robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:62d8f3d: runtime: Revert several "mark invalid contact addresses" commits (#37192)ab20681c52

master
1.7 KiB63 linesraw
1" Vim indent file
2" Language:		Device Tree
3" Maintainer:		Roland Hieber, Pengutronix <rhi@pengutronix.de>
4"
5if exists("b:did_indent")
6    finish
7endif
8let b:did_indent = 1
9
10setlocal autoindent
11setlocal nosmartindent
12setlocal indentkeys=o,O,0},0<>>,!<Ctrl-F>
13setlocal indentexpr=GetDTSIndent()
14setlocal nolisp
15
16let b:undo_indent = 'setl autoindent< smartindent< indentkeys< indentexpr< lisp<'
17
18function GetDTSIndent()
19    let sw        = shiftwidth()
20    let lnum      = v:lnum
21    let line      = getline(lnum)
22    let prevline  = getline(prevnonblank(lnum-1))
23    let prevind   = indent(prevnonblank(lnum-1))
24
25    if prevnonblank(lnum-1) < 1
26        return 0
27    endif
28
29    " Don't indent header and preprocessor directives
30    if line =~ '^\s*\(/dts-\|#\(include\|define\|undef\|warn\(ing\)\?\|error\|if\(n\?def\)\?\|else\|elif\|endif\)\)'
31        return 0
32
33    " Don't indent /node and &label blocks
34    elseif line =~ '^\s*[/&].\+{\s*$'
35        return 0
36
37    " Indent to matching bracket or remove one shiftwidth if line begins with } or >
38    elseif line =~ '^\s*[}>]'
39        " set cursor to closing bracket on current line
40        let col = matchend(line, '^\s*[>}]')
41        call cursor(lnum, col)
42        
43        " determine bracket type, {} or <>
44        let pair = strpart('{}<>', stridx('}>', line[col-1]) * 2, 2)
45
46        " find matching bracket pair
47        let pairline = searchpair(pair[0], '', pair[1], 'bW')
48
49        if pairline > 0 
50            return indent(pairline)
51        else
52            return prevind - sw
53        endif
54
55    " else, add one level of indent if line ends in { or < or = or ,
56    elseif prevline =~ '[{<=,]$'
57        return prevind + sw
58
59    else
60        return prevind
61    endif
62
63endfunction