robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0c2a7aa5f7
master
1" Vim indent file 2" Language: ld(1) script 3" Maintainer: Doug Kearns <dougkearns@gmail.com> 4" Previous Maintainer: Nikolai Weibull <now@bitwi.se> 5" Last Change: 24 Sep 2021 6 7if exists ( "b:did_indent" ) 8finish 9endif 10let b: did_indent = 1 11 12setlocal indentexpr = GetLDIndent () 13setlocal indentkeys = 0{,0},!^F,o,O 14setlocal nosmartindent 15 16let b: undo_indent = "setl inde< indk< si<" 17 18if exists ( "*GetLDIndent" ) 19finish 20endif 21 22function s: prevnonblanknoncomment ( lnum ) 23let lnum = a: lnum 24while lnum > 1 25let lnum = prevnonblank ( lnum ) 26let line = getline ( lnum ) 27if line =~ '\*/' 28while lnum > 1 && line !~ '/\*' 29let lnum -= 1 30endwhile 31if line =~ '^\s*/\*' 32let lnum -= 1 33else 34break 35endif 36else 37break 38endif 39endwhile 40return lnum 41endfunction 42 43function s: count_braces ( lnum , count_open ) 44let n_open = 0 45let n_close = 0 46let line = getline ( a: lnum ) 47let pattern = '[{}]' 48let i = match ( line , pattern ) 49while i != -1 50if synIDattr ( synID ( a: lnum , i + 1 , 0 ), 'name' ) !~ 'ld\%(Comment\|String\)' 51if line [ i ] == '{' 52let n_open += 1 53elseif line [ i ] == '}' 54if n_open > 0 55let n_open -= 1 56else 57let n_close += 1 58endif 59endif 60endif 61let i = match ( line , pattern , i + 1 ) 62endwhile 63return a: count_open ? n_open : n_close 64endfunction 65 66function GetLDIndent () 67let line = getline ( v: lnum ) 68if line =~ '^\s*\*' 69return cindent ( v: lnum ) 70elseif line =~ '^\s*}' 71return indent ( v: lnum ) - shiftwidth () 72endif 73 74let pnum = s: prevnonblanknoncomment ( v: lnum - 1 ) 75if pnum == 0 76return 0 77endif 78 79let ind = indent ( pnum ) + s: count_braces ( pnum , 1 ) * shiftwidth () 80 81let pline = getline ( pnum ) 82if pline =~ '}\s*$' 83let ind -= ( s: count_braces ( pnum , 0 ) - ( pline =~ '^\s*}' ? 1 : 0 )) * shiftwidth () 84endif 85 86return ind 87endfunction