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