Mercurial > vim
annotate runtime/plugin/matchparen.vim @ 35442:08468d7e398c default tip
runtime(java): Add a config variable for commonly used compiler options
Commit: https://github.com/vim/vim/commit/0ddab582fa13d1d653800494e45ecfba00974a18
Author: Doug Kearns <dougkearns@gmail.com>
Date: Sun Jun 16 16:58:09 2024 +0200
runtime(java): Add a config variable for commonly used compiler options
The value of g:javac_makeprg_params, if set, is added to the value of
'makeprg' as an option string.
closes: #14999
Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 16 Jun 2024 17:00:10 +0200 |
parents | 57f7c2b32500 |
children |
rev | line source |
---|---|
694 | 1 " Vim plugin for showing matching parens |
32770
4027cefc2aab
Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents:
32061
diff
changeset
|
2 " Maintainer: The Vim Project <https://github.com/vim/vim> |
35199
57f7c2b32500
runtime(matchparen): fix :NoMatchParen not working (#14797)
Christian Brabandt <cb@256bit.org>
parents:
34529
diff
changeset
|
3 " Last Change: 2024 May 18 |
32770
4027cefc2aab
Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents:
32061
diff
changeset
|
4 " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
694 | 5 |
6 " Exit quickly when: | |
7 " - this plugin was already loaded (or disabled) | |
8 " - when 'compatible' is set | |
29840 | 9 if exists("g:loaded_matchparen") || &cp |
694 | 10 finish |
11 endif | |
12 let g:loaded_matchparen = 1 | |
13 | |
4437 | 14 if !exists("g:matchparen_timeout") |
15 let g:matchparen_timeout = 300 | |
16 endif | |
17 if !exists("g:matchparen_insert_timeout") | |
18 let g:matchparen_insert_timeout = 60 | |
19 endif | |
20 | |
33631
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
21 let s:has_matchaddpos = exists('*matchaddpos') |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
22 |
694 | 23 augroup matchparen |
24 " Replace all matchparen autocommands | |
34529
2ee041017eb4
patch 9.1.0167: Changing buffer in another window causes it to show matchparen
Christian Brabandt <cb@256bit.org>
parents:
33762
diff
changeset
|
25 autocmd! CursorMoved,CursorMovedI,WinEnter,WinScrolled * call s:Highlight_Matching_Pair() |
2ee041017eb4
patch 9.1.0167: Changing buffer in another window causes it to show matchparen
Christian Brabandt <cb@256bit.org>
parents:
33762
diff
changeset
|
26 autocmd! BufWinEnter * autocmd SafeState * ++once call s:Highlight_Matching_Pair() |
31271
985a3d6e1d4b
patch 9.0.0969: matchparen highlight is not updated when switching buffers
Bram Moolenaar <Bram@vim.org>
parents:
29840
diff
changeset
|
27 autocmd! WinLeave,BufLeave * call s:Remove_Matches() |
4232 | 28 if exists('##TextChanged') |
29 autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair() | |
33762
7b26c36e9b3b
patch 9.0.2102: matchparen highlight not cleared in completion mode
Christian Brabandt <cb@256bit.org>
parents:
33631
diff
changeset
|
30 autocmd! TextChangedP * call s:Remove_Matches() |
4232 | 31 endif |
694 | 32 augroup END |
33 | |
34 " Skip the rest if it was already done. | |
35 if exists("*s:Highlight_Matching_Pair") | |
36 finish | |
37 endif | |
38 | |
2034 | 39 let s:cpo_save = &cpo |
757 | 40 set cpo-=C |
41 | |
694 | 42 " The function that is invoked (very often) to define a ":match" highlighting |
43 " for any matching paren. | |
18489 | 44 func s:Highlight_Matching_Pair() |
33631
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
45 if !exists("w:matchparen_ids") |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
46 let w:matchparen_ids = [] |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
47 endif |
694 | 48 " Remove any previous match. |
20965 | 49 call s:Remove_Matches() |
694 | 50 |
711 | 51 " Avoid that we remove the popup menu. |
1556 | 52 " Return when there are no colors (looks like the cursor jumps). |
53 if pumvisible() || (&t_Co < 8 && !has("gui_running")) | |
711 | 54 return |
55 endif | |
56 | |
694 | 57 " Get the character under the cursor and check if it's in 'matchpairs'. |
58 let c_lnum = line('.') | |
59 let c_col = col('.') | |
60 let before = 0 | |
61 | |
6051 | 62 let text = getline(c_lnum) |
7422
35af1e06696b
commit https://github.com/vim/vim/commit/c21d67e33c1b42a492e04788cbb14a23a6724e39
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
63 let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\=\)') |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
64 if empty(matches) |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
65 let [c_before, c] = ['', ''] |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
66 else |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
67 let [c_before, c] = matches[1:2] |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
68 endif |
967 | 69 let plist = split(&matchpairs, '.\zs[:,]') |
694 | 70 let i = index(plist, c) |
71 if i < 0 | |
72 " not found, in Insert mode try character before the cursor | |
73 if c_col > 1 && (mode() == 'i' || mode() == 'R') | |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
74 let before = strlen(c_before) |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
6118
diff
changeset
|
75 let c = c_before |
694 | 76 let i = index(plist, c) |
77 endif | |
78 if i < 0 | |
79 " not found, nothing to do | |
80 return | |
81 endif | |
82 endif | |
83 | |
84 " Figure out the arguments for searchpairpos(). | |
85 if i % 2 == 0 | |
86 let s_flags = 'nW' | |
87 let c2 = plist[i + 1] | |
88 else | |
89 let s_flags = 'nbW' | |
90 let c2 = c | |
91 let c = plist[i - 1] | |
92 endif | |
93 if c == '[' | |
94 let c = '\[' | |
95 let c2 = '\]' | |
96 endif | |
97 | |
98 " Find the match. When it was just before the cursor move it there for a | |
702 | 99 " moment. |
694 | 100 if before > 0 |
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
101 let has_getcurpos = exists("*getcurpos") |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
102 if has_getcurpos |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
103 " getcurpos() is more efficient but doesn't exist before 7.4.313. |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
104 let save_cursor = getcurpos() |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
105 else |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
106 let save_cursor = winsaveview() |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
107 endif |
694 | 108 call cursor(c_lnum, c_col - before) |
109 endif | |
845 | 110 |
14254
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
111 if !has("syntax") || !exists("g:syntax_on") |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
112 let s_skip = "0" |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
113 else |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
114 " Build an expression that detects whether the current cursor position is |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
115 " in certain syntax types (string, comment, etc.), for use as |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
116 " searchpairpos()'s skip argument. |
24387 | 117 " We match "escape" for special items, such as lispEscapeSpecial, and |
118 " match "symbol" for lispBarSymbol. | |
32061 | 119 let s_skip = 'synstack(".", col("."))' |
120 \ . '->indexof({_, id -> synIDattr(id, "name") =~? ' | |
121 \ . '"string\\|character\\|singlequote\\|escape\\|symbol\\|comment"}) >= 0' | |
14254
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
122 " If executing the expression determines that the cursor is currently in |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
123 " one of the syntax types, then we want searchpairpos() to find the pair |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
124 " within those syntax types (i.e., not skip). Otherwise, the cursor is |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
125 " outside of the syntax types and s_skip should keep its value so we skip |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
126 " any matching pair inside the syntax types. |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
127 " Catch if this throws E363: pattern uses more memory than 'maxmempattern'. |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
128 try |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
129 execute 'if ' . s_skip . ' | let s_skip = "0" | endif' |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
130 catch /^Vim\%((\a\+)\)\=:E363/ |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
131 " We won't find anything, so skip searching, should keep Vim responsive. |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
132 return |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
133 endtry |
1cfeee3ba4cd
patch 8.1.0143: matchit and matchparen don't handle E363
Christian Brabandt <cb@256bit.org>
parents:
14249
diff
changeset
|
134 endif |
845 | 135 |
1556 | 136 " Limit the search to lines visible in the window. |
137 let stoplinebottom = line('w$') | |
138 let stoplinetop = line('w0') | |
139 if i % 2 == 0 | |
140 let stopline = stoplinebottom | |
141 else | |
142 let stopline = stoplinetop | |
143 endif | |
144 | |
4437 | 145 " Limit the search time to 300 msec to avoid a hang on very long lines. |
146 " This fails when a timeout is not supported. | |
147 if mode() == 'i' || mode() == 'R' | |
148 let timeout = exists("b:matchparen_insert_timeout") ? b:matchparen_insert_timeout : g:matchparen_insert_timeout | |
149 else | |
150 let timeout = exists("b:matchparen_timeout") ? b:matchparen_timeout : g:matchparen_timeout | |
151 endif | |
1496 | 152 try |
4437 | 153 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, timeout) |
1496 | 154 catch /E118/ |
1556 | 155 " Can't use the timeout, restrict the stopline a bit more to avoid taking |
156 " a long time on closed folds and long lines. | |
157 " The "viewable" variables give a range in which we can scroll while | |
158 " keeping the cursor at the same position. | |
159 " adjustedScrolloff accounts for very large numbers of scrolloff. | |
160 let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2]) | |
161 let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2]) | |
162 let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2]) | |
163 " one of these stoplines will be adjusted below, but the current values are | |
164 " minimal boundaries within the current window | |
165 if i % 2 == 0 | |
166 if has("byte_offset") && has("syntax_items") && &smc > 0 | |
167 let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2]) | |
168 let stopline = min([bottom_viewable, byte2line(stopbyte)]) | |
169 else | |
170 let stopline = min([bottom_viewable, c_lnum + 100]) | |
171 endif | |
172 let stoplinebottom = stopline | |
173 else | |
174 if has("byte_offset") && has("syntax_items") && &smc > 0 | |
175 let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2]) | |
176 let stopline = max([top_viewable, byte2line(stopbyte)]) | |
177 else | |
178 let stopline = max([top_viewable, c_lnum - 100]) | |
179 endif | |
180 let stoplinetop = stopline | |
181 endif | |
1496 | 182 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline) |
183 endtry | |
845 | 184 |
694 | 185 if before > 0 |
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
186 if has_getcurpos |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
187 call setpos('.', save_cursor) |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
188 else |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
189 call winrestview(save_cursor) |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
6051
diff
changeset
|
190 endif |
694 | 191 endif |
192 | |
193 " If a match is found setup match highlighting. | |
1334 | 194 if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom |
33631
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
195 if s:has_matchaddpos |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
196 call add(w:matchparen_ids, matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10)) |
5979 | 197 else |
198 exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . | |
199 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' | |
33631
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
200 call add(w:matchparen_ids, 3) |
5979 | 201 endif |
819 | 202 let w:paren_hl_on = 1 |
694 | 203 endif |
204 endfunction | |
205 | |
20965 | 206 func s:Remove_Matches() |
207 if exists('w:paren_hl_on') && w:paren_hl_on | |
33631
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
208 while !empty(w:matchparen_ids) |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
209 silent! call remove(w:matchparen_ids, 0)->matchdelete() |
9f55ea4702b1
matchparen: do not use hard-coded match id (#13393)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
210 endwhile |
20965 | 211 let w:paren_hl_on = 0 |
212 endif | |
213 endfunc | |
214 | |
694 | 215 " Define commands that will disable and enable the plugin. |
18489 | 216 command DoMatchParen call s:DoMatchParen() |
217 command NoMatchParen call s:NoMatchParen() | |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
218 |
18489 | 219 func s:NoMatchParen() |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
220 let w = winnr() |
35199
57f7c2b32500
runtime(matchparen): fix :NoMatchParen not working (#14797)
Christian Brabandt <cb@256bit.org>
parents:
34529
diff
changeset
|
221 noau windo call s:Remove_Matches() |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
222 unlet! g:loaded_matchparen |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
223 exe "noau ". w . "wincmd w" |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
224 au! matchparen |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
225 endfunc |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
226 |
18489 | 227 func s:DoMatchParen() |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
228 runtime plugin/matchparen.vim |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
229 let w = winnr() |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
230 silent windo doau CursorMoved |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
231 exe "noau ". w . "wincmd w" |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
8148
diff
changeset
|
232 endfunc |
757 | 233 |
2034 | 234 let &cpo = s:cpo_save |
235 unlet s:cpo_save |