robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" Vim indent file 2" Language: Device Tree 3" Maintainer: Roland Hieber, Pengutronix <rhi@pengutronix.de> 4" 5if exists ( "b:did_indent" ) 6finish 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 () 19let sw = shiftwidth () 20let lnum = v: lnum 21let line = getline ( lnum ) 22let prevline = getline ( prevnonblank ( lnum - 1 )) 23let prevind = indent ( prevnonblank ( lnum - 1 )) 24 25if prevnonblank ( lnum - 1 ) < 1 26return 0 27endif 28 29" Don't indent header and preprocessor directives 30if line =~ '^\s*\(/dts-\|#\(include\|define\|undef\|warn\(ing\)\?\|error\|if\(n\?def\)\?\|else\|elif\|endif\)\)' 31return 0 32 33" Don't indent /node and &label blocks 34elseif line =~ '^\s*[/&].\+{\s*$' 35return 0 36 37" Indent to matching bracket or remove one shiftwidth if line begins with } or > 38elseif line =~ '^\s*[}>]' 39" set cursor to closing bracket on current line 40let col = matchend ( line , '^\s*[>}]' ) 41call cursor ( lnum , col ) 42 43" determine bracket type, {} or <> 44let pair = strpart ( '{}<>' , stridx ( '}>' , line [ col - 1 ]) * 2 , 2 ) 45 46" find matching bracket pair 47let pairline = searchpair ( pair [ 0 ], '' , pair [ 1 ], 'bW' ) 48 49if pairline > 0 50return indent ( pairline ) 51else 52return prevind - sw 53endif 54 55" else, add one level of indent if line ends in { or < or = or , 56elseif prevline =~ '[{<=,]$' 57return prevind + sw 58 59else 60return prevind 61endif 62 63endfunction