annotate runtime/indent/javascript.vim @ 34625:ad1b0609b2f8 v9.1.0201

patch 9.1.0201: gM not working correctly with virt text Commit: https://github.com/vim/vim/commit/366c81a2005370ac738618d889ec0337397a9f96 Author: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Date: Sun Mar 24 09:46:56 2024 +0100 patch 9.1.0201: gM not working correctly with virt text Problem: `gM` would include outer virtual text and its padding when getting the line length used to calculate the middle of the line, putting the cursor much closer to virtual text lines. Solution: Exclude outer virtual text in getting the line length for `gM`, so that virtual text doesn't influence where the cursor is moved to (Dylan Thacker-Smith). closes: #14262 Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Mar 2024 10:00:07 +0100
parents 34c1f4cd0c18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1118
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
1 " Vim indent file
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
2 " Language: Javascript
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
3 " Maintainer: Chris Paul ( https://github.com/bounceme )
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
4 " URL: https://github.com/pangloss/vim-javascript
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
5 " Last Change: December 4, 2017
1118
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
6
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
8 if exists('b:did_indent')
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
9 finish
1118
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
10 endif
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
11 let b:did_indent = 1
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
12
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
13 " Now, set up our indentation expression and keys that trigger it.
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
14 setlocal indentexpr=GetJavascriptIndent()
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
15 setlocal autoindent nolisp nosmartindent
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
16 setlocal indentkeys+=0],0)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
17 " Testable with something like:
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
18 " vim -eNs "+filetype plugin indent on" "+syntax on" "+set ft=javascript" \
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
19 " "+norm! gg=G" '+%print' '+:q!' testfile.js \
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
20 " | diff -uBZ testfile.js -
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
21
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
22 let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<'
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
23
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
24 " Only define the function once.
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
25 if exists('*GetJavascriptIndent')
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
26 finish
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
27 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
28
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
29 let s:cpo_save = &cpo
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
30 set cpo&vim
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
31
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
32 " indent correctly if inside <script>
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
33 " vim/vim@690afe1 for the switch from cindent
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
34 " overridden with b:html_indent_script1
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
35 call extend(g:,{'html_indent_script1': 'inc'},'keep')
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
36
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
37 " Regex of syntax group names that are or delimit string or are comments.
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
38 let s:bvars = {
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
39 \ 'syng_strcom': 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!',
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
40 \ 'syng_str': 'string\|template\|special' }
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
41 " template strings may want to be excluded when editing graphql:
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
42 " au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
43 " au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
44
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
45 function s:GetVars()
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
46 call extend(b:,extend(s:bvars,{'js_cache': [0,0,0]}),'keep')
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
47 endfunction
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
48
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
49 " Get shiftwidth value
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
50 if exists('*shiftwidth')
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
51 function s:sw()
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
52 return shiftwidth()
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
53 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
54 else
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
55 function s:sw()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
56 return &l:shiftwidth ? &l:shiftwidth : &l:tabstop
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
57 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
58 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
59
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
60 " Performance for forwards search(): start search at pos rather than masking
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
61 " matches before pos.
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
62 let s:z = has('patch-7.4.984') ? 'z' : ''
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
63
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
64 " Expression used to check whether we should skip a match with searchpair().
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
65 let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom"
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
66 let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'"
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
67
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
68 let s:rel = has('reltime')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
69 " searchpair() wrapper
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
70 if s:rel
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
71 function s:GetPair(start,end,flags,skip)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
72 return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200)
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
73 endfunction
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
74 else
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
75 function s:GetPair(start,end,flags,skip)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
76 return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1)
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
77 endfunction
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
78 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
79
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
80 function s:SynAt(l,c)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
81 let byte = line2byte(a:l) + a:c - 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
82 let pos = index(s:synid_cache[0], byte)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
83 if pos == -1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
84 let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
85 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
86 return s:synid_cache[1][pos]
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
87 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
88
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
89 function s:ParseCino(f)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
90 let [divider, n, cstr] = [0] + matchlist(&cino,
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
91 \ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
92 for c in split(cstr,'\zs')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
93 if c == '.' && !divider
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
94 let divider = 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
95 elseif c ==# 's'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
96 if n !~ '\d'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
97 return n . s:sw() + 0
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
98 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
99 let n = str2nr(n) * s:sw()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
100 break
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
101 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
102 let [n, divider] .= [c, 0]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
103 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
104 endfor
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
105 return str2nr(n) / max([str2nr(divider),1])
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
106 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
107
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
108 " Optimized {skip} expr, only callable from the search loop which
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
109 " GetJavascriptIndent does to find the containing [[{(] (side-effects)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
110 function s:SkipFunc()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
111 if s:top_col == 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
112 throw 'out of bounds'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
113 elseif s:check_in
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
114 if eval(s:skip_expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
115 return 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
116 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
117 let s:check_in = 0
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
118 elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
119 if eval(s:skip_expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
120 return 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
121 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
122 elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
123 if eval(s:skip_expr)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
124 let s:check_in = 1
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
125 return 1
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
126 endif
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
127 else
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
128 let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']]
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
129 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
130 let [s:looksyn, s:top_col] = getpos('.')[1:2]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
131 endfunction
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
132
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
133 function s:AlternatePair()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
134 let [pat, l:for] = ['[][(){};]', 2]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
135 while s:SearchLoop(pat,'bW','s:SkipFunc()')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
136 if s:LookingAt() == ';'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
137 if !l:for
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
138 if s:GetPair('{','}','bW','s:SkipFunc()')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
139 return
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
140 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
141 break
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
142 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
143 let [pat, l:for] = ['[{}();]', l:for - 1]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
144 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
145 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
146 let idx = stridx('])}',s:LookingAt())
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
147 if idx == -1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
148 return
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
149 elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
150 break
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
151 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
152 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
153 endwhile
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
154 throw 'out of bounds'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
155 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
156
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
157 function s:Nat(int)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
158 return a:int * (a:int > 0)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
159 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
160
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
161 function s:LookingAt()
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
162 return getline('.')[col('.')-1]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
163 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
164
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
165 function s:Token()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
166 return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt()
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
167 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
168
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
169 function s:PreviousToken(...)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
170 let [l:pos, tok] = [getpos('.'), '']
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
171 if search('\m\k\{1,}\|\S','ebW')
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
172 if getline('.')[col('.')-2:col('.')-1] == '*/'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
173 if eval(s:in_comm) && !s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
174 call setpos('.',l:pos)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
175 else
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
176 let tok = s:Token()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
177 endif
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
178 else
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
179 let two = a:0 || line('.') != l:pos[1] ? strridx(getline('.')[:col('.')],'//') + 1 : 0
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
180 if two && eval(s:in_comm)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
181 call cursor(0,two)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
182 let tok = s:PreviousToken(1)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
183 if tok is ''
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
184 call setpos('.',l:pos)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
185 endif
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
186 else
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
187 let tok = s:Token()
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
188 endif
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
189 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
190 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
191 return tok
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
192 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
193
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
194 function s:Pure(f,...)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
195 return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]")
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
196 endfunction
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
197
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
198 function s:SearchLoop(pat,flags,expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
199 return s:GetPair(a:pat,'\_$.',a:flags,a:expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
200 endfunction
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
201
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
202 function s:ExprCol()
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
203 if getline('.')[col('.')-2] == ':'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
204 return 1
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
205 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
206 let bal = 0
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
207 while s:SearchLoop('[{}?:]','bW',s:skip_expr)
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
208 if s:LookingAt() == ':'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
209 if getline('.')[col('.')-2] == ':'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
210 call cursor(0,col('.')-1)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
211 continue
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
212 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
213 let bal -= 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
214 elseif s:LookingAt() == '?'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
215 if getline('.')[col('.'):col('.')+1] =~ '^\.\d\@!'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
216 continue
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
217 elseif !bal
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
218 return 1
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
219 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
220 let bal += 1
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
221 elseif s:LookingAt() == '{'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
222 return !s:IsBlock()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
223 elseif !s:GetPair('{','}','bW',s:skip_expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
224 break
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
225 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
226 endwhile
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
227 endfunction
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
228
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
229 " configurable regexes that define continuation lines, not including (, {, or [.
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
230 let s:opfirst = '^' . get(g:,'javascript_opfirst',
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
231 \ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
232 let s:continuation = get(g:,'javascript_continuation',
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
233 \ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
234
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
235 function s:Continues()
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
236 let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation)
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
237 if tok =~ '[a-z:]'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
238 return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
239 elseif tok !~ '[/>]'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
240 return tok isnot ''
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
241 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
242 return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex')
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
243 endfunction
1118
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
244
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
245 " Check if line 'lnum' has a balanced amount of parentheses.
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
246 function s:Balanced(lnum,line)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
247 let l:open = 0
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
248 let pos = match(a:line, '[][(){}]')
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
249 while pos != -1
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
250 if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
251 let l:open += match(' ' . a:line[pos],'[[({]')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
252 if l:open < 0
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
253 return
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
254 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
255 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
256 let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ?
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
257 \ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1)
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
258 endwhile
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
259 return !l:open
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
260 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
261
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
262 function s:OneScope()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
263 if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
264 let tok = s:PreviousToken()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
265 return (count(split('for if let while with'),tok) ||
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
266 \ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') &&
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
267 \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile())
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
268 elseif s:Token() =~# '^else$\|^do$'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
269 return s:Pure('s:PreviousToken') != '.'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
270 elseif strpart(getline('.'),col('.')-2,2) == '=>'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
271 call cursor(0,col('.')-1)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
272 if s:PreviousToken() == ')'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
273 return s:GetPair('(', ')', 'bW', s:skip_expr)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
274 endif
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
275 return 1
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
276 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
277 endfunction
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
278
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
279 function s:DoWhile()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
280 let cpos = searchpos('\m\<','cbW')
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
281 while s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
282 if s:LookingAt() =~ '\a'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
283 if s:Pure('s:IsBlock')
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
284 if s:LookingAt() ==# 'd'
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
285 return 1
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
286 endif
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
287 break
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
288 endif
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
289 elseif s:LookingAt() != '}' || !s:GetPair('{','}','bW',s:skip_expr)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
290 break
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
291 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
292 endwhile
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
293 call call('cursor',cpos)
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
294 endfunction
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
295
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
296 " returns total offset from braceless contexts. 'num' is the lineNr which
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
297 " encloses the entire context, 'cont' if whether a:firstline is a continued
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
298 " expression, which could have started in a braceless context
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
299 function s:IsContOne(cont)
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
300 let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0]
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
301 let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
302 let ind = indent('.') + !a:cont
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
303 while line('.') > l:num && ind > pind || line('.') == l:num
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
304 if indent('.') < ind && s:OneScope()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
305 let b_l += 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
306 elseif !a:cont || b_l || ind < indent(a:firstline)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
307 break
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
308 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
309 call cursor(0,1)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
310 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
311 let ind = min([ind, indent('.')])
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
312 if s:PreviousToken() is ''
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
313 break
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
314 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
315 endwhile
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
316 return b_l
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
317 endfunction
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
318
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
319 function s:IsSwitch()
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
320 call call('cursor',b:js_cache[1:])
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
321 return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
322 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
323
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
324 " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
325 function s:IsBlock()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
326 let tok = s:PreviousToken()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
327 if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
328 let s:in_jsx = 1
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
329 return tok != '{'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
330 elseif tok =~ '\k'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
331 if tok ==# 'type'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
332 return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'")
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
333 elseif tok ==# 'of'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
334 return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||"
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
335 \ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'")
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
336 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
337 return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
338 \ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
339 elseif tok == '>'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
340 return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
341 elseif tok == '*'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
342 return s:Pure('s:PreviousToken') == ':'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
343 elseif tok == ':'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
344 return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()")
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
345 elseif tok == '/'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
346 return s:SynAt(line('.'),col('.')) =~? 'regex'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
347 elseif tok !~ '[=~!<,.?^%|&([]'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
348 return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
349 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
350 endfunction
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
351
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
352 function GetJavascriptIndent()
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
353 call s:GetVars()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
354 let s:synid_cache = [[],[]]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
355 let l:line = getline(v:lnum)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
356 " use synstack as it validates syn state and works in an empty line
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
357 let s:stack = [''] + map(synstack(v:lnum,1),"synIDattr(v:val,'name')")
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
358
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
359 " start with strings,comments,etc.
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
360 if s:stack[-1] =~? 'comment\|doc'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
361 if l:line =~ '^\s*\*'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
362 return cindent(v:lnum)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
363 elseif l:line !~ '^\s*\/[/*]'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
364 return -1
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
365 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
366 elseif s:stack[-1] =~? b:syng_str
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
367 if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
368 let b:js_cache[0] = v:lnum
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
369 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
370 return -1
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
371 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
372
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
373 let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000),
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
374 \ get(get(b:,'hi_indent',{}),'blocklnr')])
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
375 call cursor(v:lnum,1)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
376 if s:PreviousToken() is ''
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
377 return
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
378 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
379 let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]]
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
380
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
381 let l:line = substitute(l:line,'^\s*','','')
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
382 let l:line_raw = l:line
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
383 if l:line[:1] == '/*'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
384 let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','')
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
385 endif
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
386 if l:line =~ '^\/[/*]'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
387 let l:line = ''
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
388 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
389
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
390 " the containing paren, bracket, or curly. Many hacks for performance
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
391 call cursor(v:lnum,1)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
392 let idx = index([']',')','}'],l:line[0])
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
393 if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum ||
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
394 \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
395 call call('cursor',b:js_cache[1:])
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
396 else
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
397 let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0,
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
398 \ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
399 try
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
400 if idx != -1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
401 call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
402 elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$'
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
403 call s:GetPair('{','}','bW','s:SkipFunc()')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
404 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
405 call s:AlternatePair()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
406 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
407 catch /^\Cout of bounds$/
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
408 call cursor(v:lnum,1)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
409 endtry
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
410 let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2]
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
411 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
412
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
413 let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]]
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
414
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
415 let [num_ind, is_op, b_l, l:switch_offset, s:in_jsx] = [s:Nat(indent(num)),0,0,0,0]
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
416 if !num || s:LookingAt() == '{' && s:IsBlock()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
417 let ilnum = line('.')
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
418 if num && !s:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr)
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
419 if ilnum == num
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
420 let [num, num_ind] = [line('.'), indent('.')]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
421 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
422 if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
423 let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
424 if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
425 return s:Nat(num_ind + l:switch_offset)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
426 elseif &cino =~ '='
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
427 let l:case_offset = s:ParseCino('=')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
428 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
429 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
430 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
431 if idx == -1 && pline[-1:] !~ '[{;]'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
432 call cursor(l:lnum, len(pline))
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
433 let sol = matchstr(l:line,s:opfirst)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
434 if sol is '' || sol == '/' && s:SynAt(v:lnum,
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
435 \ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
436 if s:Continues()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
437 let is_op = s:sw()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
438 endif
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
439 elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' &&
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
440 \ s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) &&
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
441 \ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) &&
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
442 \ (s:PreviousToken() == ']' || s:LookingAt() =~ '\k' &&
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
443 \ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function')
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
444 return num_ind + s:sw()
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
445 else
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
446 let is_op = s:sw()
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
447 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
448 call cursor(l:lnum, len(pline))
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
449 let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw()
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
450 endif
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
451 elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U'))
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
452 let pval = s:ParseCino('(')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
453 if !pval
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
454 let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')]
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
455 if search('\m\S','W',num)
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
456 return s:ParseCino('w') ? vcol : virtcol('.')-1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
457 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
458 return Wval ? s:Nat(num_ind + Wval) : vcol
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
459 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
460 return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw())
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
461 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
462
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
463 " main return
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
464 if l:line =~ '^[])}]\|^|}'
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
465 if l:line_raw[0] == ')'
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
466 if s:ParseCino('M')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
467 return indent(l:lnum)
13051
a6d3e2081544 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
468 elseif num && &cino =~# 'm' && !s:ParseCino('m')
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
469 return virtcol('.') - 1
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
470 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
471 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
472 return num_ind
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
473 elseif num
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
474 return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
475 endif
29533
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
476
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
477 let nest = get(get(b:, 'hi_indent', {}), 'blocklnr')
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
478 if nest
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
479 return indent(nextnonblank(nest + 1)) + b_l + is_op
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
480 endif
34c1f4cd0c18 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 13051
diff changeset
481
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
482 return b_l + is_op
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
483 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
484
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
485 let &cpo = s:cpo_save
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
486 unlet s:cpo_save