annotate runtime/indent/tcl.vim @ 31798:5948cc887603 v9.0.1231

patch 9.0.1231: completion of :runtime does not handle {where} argument Commit: https://github.com/vim/vim/commit/3770f4c9cde7b5fcd10b6fa2e665cd0b69450fb2 Author: zeertzjq <zeertzjq@outlook.com> Date: Sun Jan 22 18:38:51 2023 +0000 patch 9.0.1231: completion of :runtime does not handle {where} argument Problem: Completion of :runtime does not handle {where} argument. Solution: Parse the {where} argument. (closes https://github.com/vim/vim/issues/11863)
author Bram Moolenaar <Bram@vim.org>
date Sun, 22 Jan 2023 19:45:04 +0100
parents 9c221ad9634a
children
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18016
diff changeset
2 " Language: Tcl
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18016
diff changeset
3 " Maintainer: Chris Heithoff <chrisheithoff@gmail.com>
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18016
diff changeset
5 " Last Change: 24 Sep 2021
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18016
diff changeset
16 let b:undo_indent = "setl inde< indk< si<"
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18016
diff changeset
17
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 if exists("*GetTclIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
22 function s:prevnonblanknoncomment(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let lnum = prevnonblank(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 if line !~ '^\s*\(#\|$\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 return lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
34 function s:ends_with_backslash(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
35 let line = getline(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
36 if line =~ '\\\s*$'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
37 return 1
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
38 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
39 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
40 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
41 endfunction
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
42
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
43 function s:count_braces(lnum, count_open)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
44 let n_open = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
45 let n_close = 0
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
46 let line = getline(a:lnum)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
47 let pattern = '[{}]'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
48 let i = match(line, pattern)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
49 while i != -1
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
50 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'tcl\%(Comment\|String\)'
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
51 if line[i] == '{'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
52 let n_open += 1
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
53 elseif line[i] == '}'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
54 if n_open > 0
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
55 let n_open -= 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
56 else
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
57 let n_close += 1
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 856
diff changeset
58 endif
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
59 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
60 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
61 let i = match(line, pattern, i + 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
62 endwhile
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
63 return a:count_open ? n_open : n_close
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
64 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
66 function GetTclIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
67 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
68
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
69 " 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
70 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
71 if pnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
75 " ..and the previous line before the previous line.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
76 let pnum2 = s:prevnonblanknoncomment(pnum-1)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
77
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
78 " Default indentation is to preserve the previous indentation.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
79 let ind = indent(pnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
80
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
81 " ...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
82 if s:count_braces(pnum, 1) > 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
83 let ind += shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
84 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
85 " Look for backslash line continuation on the previous two lines.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
86 let slash1 = s:ends_with_backslash(pnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
87 let slash2 = s:ends_with_backslash(pnum2)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
88 if slash1 && !slash2
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
89 " If the previous line begins a line continuation.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
90 let ind += shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
91 elseif !slash1 && slash2
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
92 " 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
93 let ind -= shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
94 endif
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
95 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
97 " 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
98 if line =~ '^\s*}'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
99 let ind -= shiftwidth()
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
100 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
101
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
102 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 endfunction