annotate runtime/indent/tcl.vim @ 4476:3cc2dca142a0 v7.3.986

updated for version 7.3.986 Problem: Test 95 doesn't pass when 'encoding' isn't utf-8. (Yasuhiro Matsumoto) Solution: Force 'encoding' to be utf-8.
author Bram Moolenaar <bram@vim.org>
date Tue, 21 May 2013 13:05:15 +0200
parents 8906c10ecbb0
children d0a20101ecb2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
2 " Language: Tcl
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 389
diff changeset
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
4 " Latest Revision: 2006-12-20
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal indentexpr=GetTclIndent()
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
12 setlocal indentkeys=0{,0},!^F,o,O,0]
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
13 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if exists("*GetTclIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
19 function s:prevnonblanknoncomment(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 let lnum = prevnonblank(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if line !~ '^\s*\(#\|$\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 return lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
31 function s:count_braces(lnum, count_open)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
32 let n_open = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
33 let n_close = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
34 let line = getline(a:lnum)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
35 let pattern = '[{}]'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
36 let i = match(line, pattern)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
37 while i != -1
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
38 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'tcl\%(Comment\|String\)'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
39 if line[i] == '{'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
40 let n_open += 1
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
41 elseif line[i] == '}'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
42 if n_open > 0
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
43 let n_open -= 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
44 else
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
45 let n_close += 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
46 endif
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
47 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
48 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
49 let i = match(line, pattern, i + 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
50 endwhile
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
51 return a:count_open ? n_open : n_close
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
52 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
54 function GetTclIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
55 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
56 if line =~ '^\s*\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
57 return cindent(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
58 elseif line =~ '^\s*}'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
59 return indent(v:lnum) - &sw
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
60 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
61
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
62 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
63 if pnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
67 let ind = indent(pnum) + s:count_braces(pnum, 1) * &sw
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
68
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
69 let pline = getline(pnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
70 if pline =~ '}\s*$'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
71 let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * &sw
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
72 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
74 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 endfunction