annotate runtime/indent/javascript.vim @ 11518:63b0b7b79b25

Update runtime files. commit https://github.com/vim/vim/commit/3ec574f2b549f456f664f689d6da36dc5719aeb9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 13 18:12:01 2017 +0200 Update runtime files. Includes changing &sw to shiftwidth() for all indent scripts.
author Christian Brabandt <cb@256bit.org>
date Tue, 13 Jun 2017 18:15:04 +0200
parents 146a1e213b60
children d91cf2e26ef0
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
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
5 " Last Change: March 21, 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
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
32 " Get shiftwidth value
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
33 if exists('*shiftwidth')
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
34 function s:sw()
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
35 return shiftwidth()
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
36 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
37 else
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
38 function s:sw()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
39 return &l:shiftwidth == 0 ? &l:tabstop : &l:shiftwidth
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
40 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
41 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
42
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
43 " 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
44 " matches before pos.
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
45 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
46
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
47 " searchpair() wrapper
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
48 if has('reltime')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
49 function s:GetPair(start,end,flags,skip,time,...)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
50 return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time)
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
51 endfunction
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
52 else
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
53 function s:GetPair(start,end,flags,skip,...)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
54 return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 1000,get(a:000,1)]))
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
55 endfunction
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
56 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
57
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
58 " Regex of syntax group names that are or delimit string or are comments.
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
59 let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
60 let s:syng_str = 'string\|template\|special'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
61 let s:syng_com = 'comment\|doc'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
62 " Expression used to check whether we should skip a match with searchpair().
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
63 let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
64
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
65 function s:parse_cino(f) abort
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
66 return float2nr(eval(substitute(substitute(join(split(
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
67 \ matchstr(&cino,'.*'.a:f.'\zs[^,]*'), 's',1), '*'.s:W)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
68 \ , '^-\=\zs\*','',''), '^-\=\zs\.','0.','')))
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
69 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
70
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
71 function s:skip_func()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
72 if getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
73 return eval(s:skip_expr)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
74 elseif s:checkIn || search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
75 let s:checkIn = eval(s:skip_expr)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
76 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
77 let s:looksyn = line('.')
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
78 return s:checkIn
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
79 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
80
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
81 function s:alternatePair(stop)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
82 let pos = getpos('.')[1:2]
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
83 let pat = '[][(){};]'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
84 while search('\m'.pat,'bW',a:stop)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
85 if s:skip_func() | continue | endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
86 let idx = stridx('])};',s:looking_at())
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
87 if idx is 3 | let pat = '[{}()]' | continue | endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
88 if idx + 1
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
89 if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop) <= 0
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
90 break
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
91 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
92 else
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
93 return
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
94 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
95 endwhile
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
96 call call('cursor',pos)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
97 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
98
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
99 function s:save_pos(f,...)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
100 let l:pos = getpos('.')[1:2]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
101 let ret = call(a:f,a:000)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
102 call call('cursor',l:pos)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
103 return ret
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
104 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
105
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
106 function s:syn_at(l,c)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
107 return synIDattr(synID(a:l,a:c,0),'name')
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
108 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
109
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
110 function s:looking_at()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
111 return getline('.')[col('.')-1]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
112 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
113
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
114 function s:token()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
115 return s:looking_at() =~ '\k' ? expand('<cword>') : s:looking_at()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
116 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
117
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
118 function s:previous_token()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
119 let l:pos = getpos('.')[1:2]
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
120 if search('\m\k\{1,}\zs\k\|\S','bW')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
121 if (getline('.')[col('.')-2:col('.')-1] == '*/' || line('.') != l:pos[0] &&
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
122 \ getline('.') =~ '\%<'.col('.').'c\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
123 while search('\m\S\ze\_s*\/[/*]','bW')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
124 if s:syn_at(line('.'),col('.')) !~? s:syng_com
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
125 return s:token()
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
126 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
127 endwhile
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
128 else
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
129 return s:token()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
130 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
131 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
132 call call('cursor',l:pos)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
133 return ''
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
134 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
135
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
136 function s:expr_col()
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
137 if getline('.')[col('.')-2] == ':'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
138 return 1
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
139 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
140 let bal = 0
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
141 while search('\m[{}?:;]','bW')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
142 if eval(s:skip_expr) | continue | endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
143 " switch (looking_at())
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
144 exe { '}': "if s:GetPair('{','}','bW',s:skip_expr,200) <= 0 | return | endif",
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
145 \ ';': "return",
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
146 \ '{': "return getpos('.')[1:2] != b:js_cache[1:] && !s:IsBlock()",
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
147 \ ':': "let bal -= getline('.')[max([col('.')-2,0]):col('.')] !~ '::'",
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
148 \ '?': "let bal += 1 | if bal > 0 | return 1 | endif" }[s:looking_at()]
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
149 endwhile
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
150 endfunction
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
151
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
152 " configurable regexes that define continuation lines, not including (, {, or [.
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
153 let s:opfirst = '^' . get(g:,'javascript_opfirst',
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
154 \ '\C\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
155 let s:continuation = get(g:,'javascript_continuation',
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
156 \ '\C\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
157
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
158 function s:continues(ln,con)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
159 if !cursor(a:ln, match(' '.a:con,s:continuation))
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
160 let teol = s:looking_at()
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
161 if teol == '/'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
162 return s:syn_at(line('.'),col('.')) !~? 'regex'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
163 elseif teol =~ '[-+>]'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
164 return getline('.')[col('.')-2] != tr(teol,'>','=')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
165 elseif teol =~ '\l'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
166 return s:previous_token() != '.'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
167 elseif teol == ':'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
168 return s:expr_col()
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
169 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
170 return 1
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
171 endif
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
172 endfunction
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
173
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
174 " get the line of code stripped of comments and move cursor to the last
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
175 " non-comment char.
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
176 function s:Trim(ln)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
177 let pline = substitute(getline(a:ln),'\s*$','','')
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
178 let l:max = max([strridx(pline,'//'), strridx(pline,'/*')])
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
179 while l:max != -1 && s:syn_at(a:ln, strlen(pline)) =~? s:syng_com
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
180 let pline = pline[: l:max]
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
181 let l:max = max([strridx(pline,'//'), strridx(pline,'/*')])
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
182 let pline = substitute(pline[:-2],'\s*$','','')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
183 endwhile
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
184 return pline is '' || cursor(a:ln,strlen(pline)) ? pline : pline
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
185 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
186
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
187 " Find line above 'lnum' that isn't empty or in a comment
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
188 function s:PrevCodeLine(lnum)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
189 let [l:pos, l:n] = [getpos('.')[1:2], prevnonblank(a:lnum)]
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
190 while l:n
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
191 if getline(l:n) =~ '^\s*\/[/*]'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
192 let l:n = prevnonblank(l:n-1)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
193 elseif stridx(getline(l:n), '*/') + 1 && s:syn_at(l:n,1) =~? s:syng_com
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
194 call cursor(l:n,1)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
195 keepjumps norm! [*
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
196 let l:n = search('\m\S','nbW')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
197 else
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
198 break
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
199 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
200 endwhile
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
201 call call('cursor',l:pos)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
202 return l:n
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
203 endfunction
1118
2b8ff9e3c520 updated for version 7.1a
vimboss
parents:
diff changeset
204
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
205 " Check if line 'lnum' has a balanced amount of parentheses.
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
206 function s:Balanced(lnum)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
207 let l:open = 0
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
208 let l:line = getline(a:lnum)
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
209 let pos = match(l:line, '[][(){}]', 0)
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
210 while pos != -1
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
211 if s:syn_at(a:lnum,pos + 1) !~? s:syng_strcom
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
212 let l:open += match(' ' . l:line[pos],'[[({]')
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
213 if l:open < 0
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
214 return
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
215 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
216 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
217 let pos = match(l:line, (l:open ?
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
218 \ '['.escape(tr(l:line[pos],'({[]})',')}][{(').l:line[pos],']').']' :
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
219 \ '[][(){}]'), pos + 1)
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
220 endwhile
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
221 return !l:open
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
222 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
223
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
224 function s:OneScope(lnum)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
225 let pline = s:Trim(a:lnum)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
226 let kw = 'else do'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
227 if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
228 if s:previous_token() =~# '^\%(await\|each\)$'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
229 call s:previous_token()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
230 let kw = 'for'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
231 else
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
232 let kw = 'for if let while with'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
233 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
234 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
235 return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 &&
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
236 \ s:save_pos('s:previous_token') != '.'
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
237 endfunction
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
238
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
239 " returns braceless levels started by 'i' and above lines * shiftwidth().
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
240 " 'num' is the lineNr which encloses the entire context, 'cont' if whether
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
241 " line 'i' + 1 is a continued expression, which could have started in a
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
242 " braceless context
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
243 function s:iscontOne(i,num,cont)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
244 let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
245 let pind = a:num ? indent(l:num) + s:W : 0
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
246 let ind = indent(l:i) + (a:cont ? 0 : s:W)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
247 while l:i >= l:num && (ind > pind || l:i == l:num)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
248 if indent(l:i) < ind && s:OneScope(l:i)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
249 let bL += s:W
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
250 let l:i = line('.')
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
251 elseif !a:cont || bL || ind < indent(a:i)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
252 break
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
253 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
254 let ind = min([ind, indent(l:i)])
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
255 let l:i = s:PrevCodeLine(l:i - 1)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
256 endwhile
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
257 return bL
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
258 endfunction
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
259
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
260 " 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
261 function s:IsBlock()
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
262 if s:looking_at() == '{'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
263 let l:n = line('.')
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
264 let char = s:previous_token()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
265 if match(s:stack,'\cxml\|jsx') + 1 && s:syn_at(line('.'),col('.')-1) =~? 'xml\|jsx'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
266 return char != '{'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
267 elseif char =~ '\k'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
268 if char ==# 'type'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
269 return s:previous_token() !~# '^\%(im\|ex\)port$'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
270 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
271 return index(split('return const let import export extends yield default delete var await void typeof throw case new of in instanceof')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
272 \ ,char) < (line('.') != l:n) || s:save_pos('s:previous_token') == '.'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
273 elseif char == '>'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
274 return getline('.')[col('.')-2] == '=' || s:syn_at(line('.'),col('.')) =~? '^jsflow'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
275 elseif char == ':'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
276 return !s:save_pos('s:expr_col')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
277 elseif char == '/'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
278 return s:syn_at(line('.'),col('.')) =~? 'regex'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
279 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
280 return char !~ '[=~!<*,?^%|&([]' &&
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
281 \ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
282 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
283 endfunction
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
284
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
285 function GetJavascriptIndent()
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
286 let b:js_cache = get(b:,'js_cache',[0,0,0])
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
287 " Get the current line.
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
288 call cursor(v:lnum,1)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
289 let l:line = getline('.')
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
290 " use synstack as it validates syn state and works in an empty line
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
291 let s:stack = map(synstack(v:lnum,1),"synIDattr(v:val,'name')")
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
292 let syns = get(s:stack,-1,'')
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
293
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
294 " start with strings,comments,etc.
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
295 if syns =~? s:syng_com
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
296 if l:line =~ '^\s*\*'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
297 return cindent(v:lnum)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
298 elseif l:line !~ '^\s*\/[/*]'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
299 return -1
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
300 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
301 elseif syns =~? s:syng_str
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
302 if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
303 let b:js_cache[0] = v:lnum
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
304 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
305 return -1
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
306 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
307 let l:lnum = s:PrevCodeLine(v:lnum - 1)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
308 if !l:lnum
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
309 return
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
310 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
311
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
312 let l:line = substitute(l:line,'^\s*','','')
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
313 if l:line[:1] == '/*'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
314 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
315 endif
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
316 if l:line =~ '^\/[/*]'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
317 let l:line = ''
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
318 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
319
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
320 " the containing paren, bracket, or curly. Many hacks for performance
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
321 let idx = index([']',')','}'],l:line[0])
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
322 if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum &&
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
323 \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
324 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
325 else
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
326 let [s:looksyn, s:checkIn, top] = [v:lnum - 1, 0, (!indent(l:lnum) &&
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
327 \ s:syn_at(l:lnum,1) !~? s:syng_str) * l:lnum]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
328 if idx + 1
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
329 call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:skip_func()',2000,top)
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
330 elseif getline(v:lnum) !~ '^\S' && syns =~? 'block'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
331 call s:GetPair('{','}','bW','s:skip_func()',2000,top)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
332 else
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
333 call s:alternatePair(top)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
334 endif
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
335 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
336
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
337 let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [0,0] : getpos('.')[1:2])
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
338 let num = b:js_cache[1]
9975
03fa8a51e9dc commit https://github.com/vim/vim/commit/e4a3bcf28d92d0bde9ca227ccb40d401038185e5
Christian Brabandt <cb@256bit.org>
parents: 9860
diff changeset
339
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
340 let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0]
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
341 if !num || s:IsBlock()
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
342 let ilnum = line('.')
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
343 let pline = s:save_pos('s:Trim',l:lnum)
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
344 if num && s:looking_at() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
345 let num = ilnum == num ? line('.') : num
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
346 if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
347 if &cino !~ ':'
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
348 let switch_offset = s:W
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
349 else
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
350 let switch_offset = max([-indent(num),s:parse_cino(':')])
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
351 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
352 if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
353 return indent(num) + switch_offset
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
354 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
355 endif
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
356 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
357 if idx < 0 && pline[-1:] !~ '[{;]'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
358 let isOp = (l:line =~# s:opfirst || s:continues(l:lnum,pline)) * s:W
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
359 let bL = s:iscontOne(l:lnum,b:js_cache[1],isOp)
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
360 let bL -= (bL && l:line[0] == '{') * s:W
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
361 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
362 elseif idx < 0 && getline(b:js_cache[1])[b:js_cache[2]-1] == '(' && &cino =~ '('
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
363 let pval = s:parse_cino('(')
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
364 return !pval ? (s:parse_cino('w') ? 0 : -(!!search('\m\S','W'.s:z,num))) + virtcol('.') :
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
365 \ max([indent('.') + pval + (s:GetPair('(',')','nbrmW',s:skip_expr,100,num) * s:W),0])
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
366 endif
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
367
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
368 " main return
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
369 if l:line =~ '^\%([])}]\||}\)'
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
370 return max([indent(num),0])
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
371 elseif num
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
372 return indent(num) + s:W + switch_offset + bL + isOp
10548
74effdaa369e Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9975
diff changeset
373 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents: 10548
diff changeset
374 return bL + isOp
9860
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
375 endfunction
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
376
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
377 let &cpo = s:cpo_save
9eaf8ef656e9 commit https://github.com/vim/vim/commit/0952131376a517fc12dc5ae908a97018b4ee23f0
Christian Brabandt <cb@256bit.org>
parents: 6823
diff changeset
378 unlet s:cpo_save