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