annotate runtime/indent/tcl.vim @ 15533:08604d82fc9e v8.1.0774

patch 8.1.0774: VMS build is missing the blob file commit https://github.com/vim/vim/commit/05a2907cde00ac3ccff01c59978f174c020cc375 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 18 22:59:53 2019 +0100 patch 8.1.0774: VMS build is missing the blob file Problem: VMS build is missing the blob file. Solution: Add the blob file to the build rules. (Zoltan Arpadffy)
author Bram Moolenaar <Bram@vim.org>
date Fri, 18 Jan 2019 23:00:08 +0100
parents bc1a8d21c811
children 834b7854aa3c
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
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
2 " Language: Tcl
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
3 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
4 " Latest Update: Chris Heithoff <chrisheithoff@gmail.com>
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
5 " Latest Revision: 2018-12-05
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentexpr=GetTclIndent()
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
13 setlocal indentkeys=0{,0},!^F,o,O,0]
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
14 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 if exists("*GetTclIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
20 function s:prevnonblanknoncomment(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 let lnum = prevnonblank(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 if line !~ '^\s*\(#\|$\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 return lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
32 function s:ends_with_backslash(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
33 let line = getline(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
34 if line =~ '\\\s*$'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
35 return 1
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
36 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
37 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
38 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
39 endfunction
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
40
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
41 function s:count_braces(lnum, count_open)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
42 let n_open = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
43 let n_close = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
44 let line = getline(a:lnum)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
45 let pattern = '[{}]'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
46 let i = match(line, pattern)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
47 while i != -1
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
48 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'tcl\%(Comment\|String\)'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
49 if line[i] == '{'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
50 let n_open += 1
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
51 elseif line[i] == '}'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
52 if n_open > 0
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
53 let n_open -= 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
54 else
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
55 let n_close += 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
56 endif
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
57 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
58 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
59 let i = match(line, pattern, i + 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
60 endwhile
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
61 return a:count_open ? n_open : n_close
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
62 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
64 function GetTclIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
65 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
66
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
67 " Get the line number of the previous non-blank or non-comment line.
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
68 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
69 if pnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
73 " ..and the previous line before the previous line.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
74 let pnum2 = s:prevnonblanknoncomment(pnum-1)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
75
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
76 " Default indentation is to preserve the previous indentation.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
77 let ind = indent(pnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
78
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
79 " ...but if previous line introduces an open brace, then increase current line's indentation
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
80 if s:count_braces(pnum, 1) > 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
81 let ind += shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
82 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
83 " Look for backslash line continuation on the previous two lines.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
84 let slash1 = s:ends_with_backslash(pnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
85 let slash2 = s:ends_with_backslash(pnum2)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
86 if slash1 && !slash2
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
87 " If the previous line begins a line continuation.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
88 let ind += shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
89 elseif !slash1 && slash2
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
90 " If two lines ago was the end of a line continuation group of lines.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
91 let ind -= shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
92 endif
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
93 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
95 " If the current line begins with a closed brace, then decrease the indentation by one.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
96 if line =~ '^\s*}'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
97 let ind -= shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
98 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
99
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
100 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 endfunction