blob: 8b7c03fce511ce8c77c01b2314f03af5208950c6 [file] [log] [blame]
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00001" Vim indent file
2" Language: ld(1) script
3" Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se>
Bram Moolenaar42eeac32005-06-29 22:40:58 +00004" Latest Revision: 2005-06-29
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005
6if exists("b:did_indent")
7 finish
8endif
9let b:did_indent = 1
10
11setlocal indentexpr=GetLDIndent()
12setlocal indentkeys=0{,0},!^F,o,O
13
14if exists("*GetLDIndent")
15 finish
16endif
17
18function s:count_braces(lnum, count_open)
19 let n_open = 0
20 let n_close = 0
21 let line = getline(a:lnum)
22 let pattern = '[{}]'
23 let i = match(line, pattern)
24 while i != -1
25 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
26 if line[i] == '{'
27 let n_open += 1
28 elseif line[i] == '}'
29 if n_open > 0
30 let n_open -= 1
31 else
32 let n_close += 1
33 endif
34 endif
35 endif
36 let i = match(line, pattern, i + 1)
37 endwhile
38 return a:count_open ? n_open : n_close
39endfunction
40
41function GetLDIndent()
42 let pnum = prevnonblank(v:lnum - 1)
43 if pnum == 0
44 return 0
45 endif
46
47 return indent(pnum) + s:count_braces(pnum, 1) * &sw
48 \ - s:count_braces(v:lnum, 0) * &sw
49endfunction