Mercurial > vim
annotate src/search.c @ 16570:2c2f5f0173c1 v8.1.1288
patch 8.1.1288: search stats don't show for mapped command
commit https://github.com/vim/vim/commit/9ce3fa828d238ff28d57b0092bb37575e20010ec
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 7 21:29:11 2019 +0200
patch 8.1.1288: search stats don't show for mapped command
Problem: Search stats don't show for mapped command.
Solution: Remove SEARCH_PEEK from searchit flags. Add a test. (Christian
Brabandt)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 07 May 2019 21:30:05 +0200 |
parents | 8d0ea09e2d81 |
children | f37255166ff4 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9913
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * search.c: code for normal mode searching commands | |
11 */ | |
12 | |
13 #include "vim.h" | |
14 | |
15 #ifdef FEAT_EVAL | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
16 static void set_vv_searchforward(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
17 static int first_submatch(regmmatch_T *rp); |
7 | 18 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
19 static int check_linecomment(char_u *line); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
20 static int cls(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
21 static int skip_chars(int, int); |
7 | 22 #ifdef FEAT_FIND_ID |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
23 static void show_pat_in_path(char_u *, int, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
24 int, int, FILE *, linenr_T *, long); |
7 | 25 #endif |
26 #ifdef FEAT_VIMINFO | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
27 static void wvsp_one(FILE *fp, int idx, char *s, int sc); |
7 | 28 #endif |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
29 static void search_stat(int dirc, pos_T *pos, int show_top_bot_msg, char_u *msgbuf); |
7 | 30 |
31 /* | |
32 * This file contains various searching-related routines. These fall into | |
33 * three groups: | |
34 * 1. string searches (for /, ?, n, and N) | |
35 * 2. character searches within a single line (for f, F, t, T, etc) | |
36 * 3. "other" kinds of searches like the '%' command, and 'word' searches. | |
37 */ | |
38 | |
39 /* | |
40 * String searches | |
41 * | |
42 * The string search functions are divided into two levels: | |
43 * lowest: searchit(); uses an pos_T for starting position and found match. | |
44 * Highest: do_search(); uses curwin->w_cursor; calls searchit(). | |
45 * | |
46 * The last search pattern is remembered for repeating the same search. | |
47 * This pattern is shared between the :g, :s, ? and / commands. | |
48 * This is in search_regcomp(). | |
49 * | |
50 * The actual string matching is done using a heavily modified version of | |
51 * Henry Spencer's regular expression library. See regexp.c. | |
52 */ | |
53 | |
54 /* The offset for a search command is store in a soff struct */ | |
55 /* Note: only spats[0].off is really used */ | |
56 struct soffset | |
57 { | |
1624 | 58 int dir; /* search direction, '/' or '?' */ |
7 | 59 int line; /* search has line offset */ |
60 int end; /* search set cursor at end */ | |
61 long off; /* line or char offset */ | |
62 }; | |
63 | |
64 /* A search pattern and its attributes are stored in a spat struct */ | |
65 struct spat | |
66 { | |
67 char_u *pat; /* the pattern (in allocated memory) or NULL */ | |
68 int magic; /* magicness of the pattern */ | |
4352 | 69 int no_scs; /* no smartcase for this pattern */ |
7 | 70 struct soffset off; |
71 }; | |
72 | |
73 /* | |
74 * Two search patterns are remembered: One for the :substitute command and | |
75 * one for other searches. last_idx points to the one that was used the last | |
76 * time. | |
77 */ | |
78 static struct spat spats[2] = | |
79 { | |
80 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}, /* last used search pat */ | |
81 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}} /* last used substitute pat */ | |
82 }; | |
83 | |
84 static int last_idx = 0; /* index in spats[] for RE_LAST */ | |
85 | |
6991 | 86 static char_u lastc[2] = {NUL, NUL}; /* last character searched for */ |
87 static int lastcdir = FORWARD; /* last direction of character search */ | |
88 static int last_t_cmd = TRUE; /* last search t_cmd */ | |
89 static char_u lastc_bytes[MB_MAXBYTES + 1]; | |
90 static int lastc_bytelen = 1; /* >1 for multi-byte char */ | |
91 | |
7 | 92 /* copy of spats[], for keeping the search patterns while executing autocmds */ |
93 static struct spat saved_spats[2]; | |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
94 # ifdef FEAT_SEARCH_EXTRA |
15091
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
95 static int saved_spats_last_idx = 0; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
96 static int saved_spats_no_hlsearch = 0; |
7 | 97 # endif |
98 | |
99 static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ | |
100 #ifdef FEAT_RIGHTLEFT | |
101 static int mr_pattern_alloced = FALSE; /* mr_pattern was allocated */ | |
102 #endif | |
103 | |
104 #ifdef FEAT_FIND_ID | |
105 /* | |
106 * Type used by find_pattern_in_path() to remember which included files have | |
107 * been searched already. | |
108 */ | |
109 typedef struct SearchedFile | |
110 { | |
111 FILE *fp; /* File pointer */ | |
112 char_u *name; /* Full name of file */ | |
113 linenr_T lnum; /* Line we were up to in file */ | |
114 int matched; /* Found a match in this file */ | |
115 } SearchedFile; | |
116 #endif | |
117 | |
118 /* | |
119 * translate search pattern for vim_regcomp() | |
120 * | |
121 * pat_save == RE_SEARCH: save pat in spats[RE_SEARCH].pat (normal search cmd) | |
122 * pat_save == RE_SUBST: save pat in spats[RE_SUBST].pat (:substitute command) | |
123 * pat_save == RE_BOTH: save pat in both patterns (:global command) | |
124 * pat_use == RE_SEARCH: use previous search pattern if "pat" is NULL | |
1222 | 125 * pat_use == RE_SUBST: use previous substitute pattern if "pat" is NULL |
7 | 126 * pat_use == RE_LAST: use last used pattern if "pat" is NULL |
127 * options & SEARCH_HIS: put search string in history | |
128 * options & SEARCH_KEEP: keep previous search pattern | |
129 * | |
130 * returns FAIL if failed, OK otherwise. | |
131 */ | |
132 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
133 search_regcomp( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
134 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
135 int pat_save, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
136 int pat_use, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
137 int options, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
138 regmmatch_T *regmatch) /* return: pattern and ignore-case flag */ |
7 | 139 { |
140 int magic; | |
141 int i; | |
142 | |
143 rc_did_emsg = FALSE; | |
144 magic = p_magic; | |
145 | |
146 /* | |
147 * If no pattern given, use a previously defined pattern. | |
148 */ | |
149 if (pat == NULL || *pat == NUL) | |
150 { | |
151 if (pat_use == RE_LAST) | |
152 i = last_idx; | |
153 else | |
154 i = pat_use; | |
155 if (spats[i].pat == NULL) /* pattern was never defined */ | |
156 { | |
157 if (pat_use == RE_SUBST) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
158 emsg(_(e_nopresub)); |
7 | 159 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
160 emsg(_(e_noprevre)); |
7 | 161 rc_did_emsg = TRUE; |
162 return FAIL; | |
163 } | |
164 pat = spats[i].pat; | |
165 magic = spats[i].magic; | |
166 no_smartcase = spats[i].no_scs; | |
167 } | |
168 #ifdef FEAT_CMDHIST | |
169 else if (options & SEARCH_HIS) /* put new pattern in history */ | |
170 add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
171 #endif | |
172 | |
173 #ifdef FEAT_RIGHTLEFT | |
174 if (mr_pattern_alloced) | |
175 { | |
176 vim_free(mr_pattern); | |
177 mr_pattern_alloced = FALSE; | |
178 } | |
179 | |
180 if (curwin->w_p_rl && *curwin->w_p_rlc == 's') | |
181 { | |
182 char_u *rev_pattern; | |
183 | |
184 rev_pattern = reverse_text(pat); | |
185 if (rev_pattern == NULL) | |
186 mr_pattern = pat; /* out of memory, keep normal pattern. */ | |
187 else | |
188 { | |
189 mr_pattern = rev_pattern; | |
190 mr_pattern_alloced = TRUE; | |
191 } | |
192 } | |
193 else | |
194 #endif | |
195 mr_pattern = pat; | |
196 | |
197 /* | |
198 * Save the currently used pattern in the appropriate place, | |
199 * unless the pattern should not be remembered. | |
200 */ | |
5606 | 201 if (!(options & SEARCH_KEEP) && !cmdmod.keeppatterns) |
7 | 202 { |
203 /* search or global command */ | |
204 if (pat_save == RE_SEARCH || pat_save == RE_BOTH) | |
205 save_re_pat(RE_SEARCH, pat, magic); | |
206 /* substitute or global command */ | |
207 if (pat_save == RE_SUBST || pat_save == RE_BOTH) | |
208 save_re_pat(RE_SUBST, pat, magic); | |
209 } | |
210 | |
211 regmatch->rmm_ic = ignorecase(pat); | |
410 | 212 regmatch->rmm_maxcol = 0; |
7 | 213 regmatch->regprog = vim_regcomp(pat, magic ? RE_MAGIC : 0); |
214 if (regmatch->regprog == NULL) | |
215 return FAIL; | |
216 return OK; | |
217 } | |
218 | |
219 /* | |
220 * Get search pattern used by search_regcomp(). | |
221 */ | |
222 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
223 get_search_pat(void) |
7 | 224 { |
225 return mr_pattern; | |
226 } | |
227 | |
1344 | 228 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 229 /* |
230 * Reverse text into allocated memory. | |
231 * Returns the allocated string, NULL when out of memory. | |
232 */ | |
1344 | 233 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
234 reverse_text(char_u *s) |
7 | 235 { |
236 unsigned len; | |
237 unsigned s_i, rev_i; | |
238 char_u *rev; | |
239 | |
240 /* | |
241 * Reverse the pattern. | |
242 */ | |
243 len = (unsigned)STRLEN(s); | |
244 rev = alloc(len + 1); | |
245 if (rev != NULL) | |
246 { | |
247 rev_i = len; | |
248 for (s_i = 0; s_i < len; ++s_i) | |
249 { | |
250 if (has_mbyte) | |
251 { | |
252 int mb_len; | |
253 | |
474 | 254 mb_len = (*mb_ptr2len)(s + s_i); |
7 | 255 rev_i -= mb_len; |
256 mch_memmove(rev + rev_i, s + s_i, mb_len); | |
257 s_i += mb_len - 1; | |
258 } | |
259 else | |
260 rev[--rev_i] = s[s_i]; | |
261 | |
262 } | |
263 rev[len] = NUL; | |
264 } | |
265 return rev; | |
266 } | |
267 #endif | |
268 | |
6426 | 269 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
270 save_re_pat(int idx, char_u *pat, int magic) |
7 | 271 { |
272 if (spats[idx].pat != pat) | |
273 { | |
274 vim_free(spats[idx].pat); | |
275 spats[idx].pat = vim_strsave(pat); | |
276 spats[idx].magic = magic; | |
277 spats[idx].no_scs = no_smartcase; | |
278 last_idx = idx; | |
279 #ifdef FEAT_SEARCH_EXTRA | |
280 /* If 'hlsearch' set and search pat changed: need redraw. */ | |
281 if (p_hls) | |
745 | 282 redraw_all_later(SOME_VALID); |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
283 set_no_hlsearch(FALSE); |
7 | 284 #endif |
285 } | |
286 } | |
287 | |
288 /* | |
289 * Save the search patterns, so they can be restored later. | |
290 * Used before/after executing autocommands and user functions. | |
291 */ | |
292 static int save_level = 0; | |
293 | |
294 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
295 save_search_patterns(void) |
7 | 296 { |
297 if (save_level++ == 0) | |
298 { | |
299 saved_spats[0] = spats[0]; | |
300 if (spats[0].pat != NULL) | |
301 saved_spats[0].pat = vim_strsave(spats[0].pat); | |
302 saved_spats[1] = spats[1]; | |
303 if (spats[1].pat != NULL) | |
304 saved_spats[1].pat = vim_strsave(spats[1].pat); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
305 #ifdef FEAT_SEARCH_EXTRA |
15091
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
306 saved_spats_last_idx = last_idx; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
307 saved_spats_no_hlsearch = no_hlsearch; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
308 #endif |
7 | 309 } |
310 } | |
311 | |
312 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
313 restore_search_patterns(void) |
7 | 314 { |
315 if (--save_level == 0) | |
316 { | |
317 vim_free(spats[0].pat); | |
318 spats[0] = saved_spats[0]; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
319 #if defined(FEAT_EVAL) |
1624 | 320 set_vv_searchforward(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
321 #endif |
7 | 322 vim_free(spats[1].pat); |
323 spats[1] = saved_spats[1]; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
324 #ifdef FEAT_SEARCH_EXTRA |
15091
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
325 last_idx = saved_spats_last_idx; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
326 set_no_hlsearch(saved_spats_no_hlsearch); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
327 #endif |
7 | 328 } |
329 } | |
330 | |
359 | 331 #if defined(EXITFREE) || defined(PROTO) |
332 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
333 free_search_patterns(void) |
359 | 334 { |
335 vim_free(spats[0].pat); | |
336 vim_free(spats[1].pat); | |
1862 | 337 |
338 # ifdef FEAT_RIGHTLEFT | |
339 if (mr_pattern_alloced) | |
340 { | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
341 vim_free(mr_pattern); |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
342 mr_pattern_alloced = FALSE; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
343 mr_pattern = NULL; |
1862 | 344 } |
345 # endif | |
359 | 346 } |
347 #endif | |
348 | |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
349 #ifdef FEAT_SEARCH_EXTRA |
15091
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
350 // copy of spats[RE_SEARCH], for keeping the search patterns while incremental |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
351 // searching |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
352 static struct spat saved_last_search_spat; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
353 static int did_save_last_search_spat = 0; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
354 static int saved_last_idx = 0; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
355 static int saved_no_hlsearch = 0; |
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
356 |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
357 /* |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
358 * Save and restore the search pattern for incremental highlight search |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
359 * feature. |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
360 * |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
361 * It's similar to but different from save_search_patterns() and |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
362 * restore_search_patterns(), because the search pattern must be restored when |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
363 * canceling incremental searching even if it's called inside user functions. |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
364 */ |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
365 void |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
366 save_last_search_pattern(void) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
367 { |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
368 if (did_save_last_search_spat != 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
369 iemsg("did_save_last_search_spat is not zero"); |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
370 else |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
371 ++did_save_last_search_spat; |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
372 |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
373 saved_last_search_spat = spats[RE_SEARCH]; |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
374 if (spats[RE_SEARCH].pat != NULL) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
375 saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat); |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
376 saved_last_idx = last_idx; |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
377 saved_no_hlsearch = no_hlsearch; |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
378 } |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
379 |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
380 void |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
381 restore_last_search_pattern(void) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
382 { |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
383 if (did_save_last_search_spat != 1) |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
384 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
385 iemsg("did_save_last_search_spat is not one"); |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
386 return; |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
387 } |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
388 --did_save_last_search_spat; |
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
389 |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
390 vim_free(spats[RE_SEARCH].pat); |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
391 spats[RE_SEARCH] = saved_last_search_spat; |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
392 saved_last_search_spat.pat = NULL; |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
393 # if defined(FEAT_EVAL) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
394 set_vv_searchforward(); |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
395 # endif |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
396 last_idx = saved_last_idx; |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
397 set_no_hlsearch(saved_no_hlsearch); |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
398 } |
12855
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
399 |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
400 char_u * |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
401 last_search_pattern(void) |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
402 { |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
403 return spats[RE_SEARCH].pat; |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12829
diff
changeset
|
404 } |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
405 #endif |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12539
diff
changeset
|
406 |
7 | 407 /* |
408 * Return TRUE when case should be ignored for search pattern "pat". | |
409 * Uses the 'ignorecase' and 'smartcase' options. | |
410 */ | |
411 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
412 ignorecase(char_u *pat) |
7 | 413 { |
9913
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
414 return ignorecase_opt(pat, p_ic, p_scs); |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
415 } |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
416 |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
417 /* |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
418 * As ignorecase() put pass the "ic" and "scs" flags. |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
419 */ |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
420 int |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
421 ignorecase_opt(char_u *pat, int ic_in, int scs) |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
422 { |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
423 int ic = ic_in; |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
424 |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9647
diff
changeset
|
425 if (ic && !no_smartcase && scs |
7 | 426 #ifdef FEAT_INS_EXPAND |
13210
c1534eb682a6
patch 8.0.1479: insert mode completion state is confusing
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
427 && !(ctrl_x_mode_not_default() && curbuf->b_p_inf) |
7 | 428 #endif |
429 ) | |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
430 ic = !pat_has_uppercase(pat); |
7 | 431 no_smartcase = FALSE; |
432 | |
433 return ic; | |
434 } | |
435 | |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
436 /* |
6991 | 437 * Return TRUE if pattern "pat" has an uppercase character. |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
438 */ |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
439 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
440 pat_has_uppercase(char_u *pat) |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
441 { |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
442 char_u *p = pat; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
443 |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
444 while (*p != NUL) |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
445 { |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
446 int l; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
447 |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
448 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
449 { |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
450 if (enc_utf8 && utf_isupper(utf_ptr2char(p))) |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
451 return TRUE; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
452 p += l; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
453 } |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
454 else if (*p == '\\') |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
455 { |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
456 if (p[1] == '_' && p[2] != NUL) /* skip "\_X" */ |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
457 p += 3; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
458 else if (p[1] == '%' && p[2] != NUL) /* skip "\%X" */ |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
459 p += 3; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
460 else if (p[1] != NUL) /* skip "\X" */ |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
461 p += 2; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
462 else |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
463 p += 1; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
464 } |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
465 else if (MB_ISUPPER(*p)) |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
466 return TRUE; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
467 else |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
468 ++p; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
469 } |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
470 return FALSE; |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
471 } |
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
472 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
473 #if defined(FEAT_EVAL) || defined(PROTO) |
7 | 474 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
475 last_csearch(void) |
6991 | 476 { |
477 return lastc_bytes; | |
478 } | |
479 | |
480 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
481 last_csearch_forward(void) |
6991 | 482 { |
483 return lastcdir == FORWARD; | |
484 } | |
485 | |
486 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
487 last_csearch_until(void) |
6991 | 488 { |
489 return last_t_cmd == TRUE; | |
490 } | |
491 | |
492 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
493 set_last_csearch(int c, char_u *s UNUSED, int len UNUSED) |
6991 | 494 { |
495 *lastc = c; | |
496 lastc_bytelen = len; | |
497 if (len) | |
498 memcpy(lastc_bytes, s, len); | |
499 else | |
500 vim_memset(lastc_bytes, 0, sizeof(lastc_bytes)); | |
501 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
502 #endif |
6991 | 503 |
504 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
505 set_csearch_direction(int cdir) |
6991 | 506 { |
507 lastcdir = cdir; | |
508 } | |
509 | |
510 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
511 set_csearch_until(int t_cmd) |
6991 | 512 { |
513 last_t_cmd = t_cmd; | |
514 } | |
515 | |
516 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
517 last_search_pat(void) |
7 | 518 { |
519 return spats[last_idx].pat; | |
520 } | |
521 | |
522 /* | |
523 * Reset search direction to forward. For "gd" and "gD" commands. | |
524 */ | |
525 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
526 reset_search_dir(void) |
7 | 527 { |
528 spats[0].off.dir = '/'; | |
1624 | 529 #if defined(FEAT_EVAL) |
530 set_vv_searchforward(); | |
531 #endif | |
7 | 532 } |
533 | |
534 #if defined(FEAT_EVAL) || defined(FEAT_VIMINFO) | |
535 /* | |
536 * Set the last search pattern. For ":let @/ =" and viminfo. | |
537 * Also set the saved search pattern, so that this works in an autocommand. | |
538 */ | |
539 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
540 set_last_search_pat( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
541 char_u *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
542 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
543 int magic, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
544 int setlast) |
7 | 545 { |
546 vim_free(spats[idx].pat); | |
547 /* An empty string means that nothing should be matched. */ | |
548 if (*s == NUL) | |
549 spats[idx].pat = NULL; | |
550 else | |
551 spats[idx].pat = vim_strsave(s); | |
552 spats[idx].magic = magic; | |
553 spats[idx].no_scs = FALSE; | |
554 spats[idx].off.dir = '/'; | |
1624 | 555 #if defined(FEAT_EVAL) |
556 set_vv_searchforward(); | |
557 #endif | |
7 | 558 spats[idx].off.line = FALSE; |
559 spats[idx].off.end = FALSE; | |
560 spats[idx].off.off = 0; | |
561 if (setlast) | |
562 last_idx = idx; | |
563 if (save_level) | |
564 { | |
565 vim_free(saved_spats[idx].pat); | |
566 saved_spats[idx] = spats[0]; | |
567 if (spats[idx].pat == NULL) | |
568 saved_spats[idx].pat = NULL; | |
569 else | |
570 saved_spats[idx].pat = vim_strsave(spats[idx].pat); | |
15971
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15930
diff
changeset
|
571 # ifdef FEAT_SEARCH_EXTRA |
15091
e8fdc71f3ea0
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Bram Moolenaar <Bram@vim.org>
parents:
15089
diff
changeset
|
572 saved_spats_last_idx = last_idx; |
15971
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15930
diff
changeset
|
573 # endif |
7 | 574 } |
575 # ifdef FEAT_SEARCH_EXTRA | |
576 /* If 'hlsearch' set and search pat changed: need redraw. */ | |
577 if (p_hls && idx == last_idx && !no_hlsearch) | |
745 | 578 redraw_all_later(SOME_VALID); |
7 | 579 # endif |
580 } | |
581 #endif | |
582 | |
583 #ifdef FEAT_SEARCH_EXTRA | |
584 /* | |
585 * Get a regexp program for the last used search pattern. | |
586 * This is used for highlighting all matches in a window. | |
587 * Values returned in regmatch->regprog and regmatch->rmm_ic. | |
588 */ | |
589 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
590 last_pat_prog(regmmatch_T *regmatch) |
7 | 591 { |
592 if (spats[last_idx].pat == NULL) | |
593 { | |
594 regmatch->regprog = NULL; | |
595 return; | |
596 } | |
597 ++emsg_off; /* So it doesn't beep if bad expr */ | |
598 (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch); | |
599 --emsg_off; | |
600 } | |
601 #endif | |
602 | |
603 /* | |
5735 | 604 * Lowest level search function. |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
605 * Search for 'count'th occurrence of pattern "pat" in direction "dir". |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
606 * Start at position "pos" and return the found position in "pos". |
7 | 607 * |
608 * if (options & SEARCH_MSG) == 0 don't give any messages | |
609 * if (options & SEARCH_MSG) == SEARCH_NFMSG don't give 'notfound' messages | |
610 * if (options & SEARCH_MSG) == SEARCH_MSG give all messages | |
611 * if (options & SEARCH_HIS) put search pattern in history | |
612 * if (options & SEARCH_END) return position at end of match | |
613 * if (options & SEARCH_START) accept match at pos itself | |
614 * if (options & SEARCH_KEEP) keep previous search pattern | |
615 * if (options & SEARCH_FOLD) match only once in a closed fold | |
616 * if (options & SEARCH_PEEK) check for typed char, cancel search | |
7358
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
617 * if (options & SEARCH_COL) start at pos->col instead of zero |
7 | 618 * |
619 * Return FAIL (zero) for failure, non-zero for success. | |
620 * When FEAT_EVAL is defined, returns the index of the first matching | |
621 * subpattern plus one; one if there was none. | |
622 */ | |
623 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
624 searchit( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
625 win_T *win, /* window to search in; can be NULL for a |
7 | 626 buffer without a window! */ |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
627 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
628 pos_T *pos, |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
629 pos_T *end_pos, // set to end of the match, unless NULL |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
630 int dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
631 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
632 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
633 int options, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
634 int pat_use, /* which pattern to use when "pat" is empty */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
635 linenr_T stop_lnum, /* stop after this line number when != 0 */ |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
636 proftime_T *tm UNUSED, /* timeout limit or NULL */ |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
637 int *timed_out UNUSED) /* set when timed out or NULL */ |
7 | 638 { |
639 int found; | |
640 linenr_T lnum; /* no init to shut up Apollo cc */ | |
7358
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
641 colnr_T col; |
7 | 642 regmmatch_T regmatch; |
643 char_u *ptr; | |
644 colnr_T matchcol; | |
645 lpos_T endpos; | |
140 | 646 lpos_T matchpos; |
7 | 647 int loop; |
648 pos_T start_pos; | |
649 int at_first_line; | |
650 int extra_col; | |
6903 | 651 int start_char_len; |
7 | 652 int match_ok; |
653 long nmatched; | |
654 int submatch = 0; | |
6402 | 655 int first_match = TRUE; |
648 | 656 int save_called_emsg = called_emsg; |
7 | 657 #ifdef FEAT_SEARCH_EXTRA |
658 int break_loop = FALSE; | |
659 #endif | |
660 | |
661 if (search_regcomp(pat, RE_SEARCH, pat_use, | |
662 (options & (SEARCH_HIS + SEARCH_KEEP)), ®match) == FAIL) | |
663 { | |
664 if ((options & SEARCH_MSG) && !rc_did_emsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
665 semsg(_("E383: Invalid search string: %s"), mr_pattern); |
7 | 666 return FAIL; |
667 } | |
668 | |
648 | 669 /* |
670 * find the string | |
671 */ | |
7 | 672 called_emsg = FALSE; |
673 do /* loop for count */ | |
674 { | |
6402 | 675 /* When not accepting a match at the start position set "extra_col" to |
676 * a non-zero value. Don't do that when starting at MAXCOL, since | |
677 * MAXCOL + 1 is zero. */ | |
6903 | 678 if (pos->col == MAXCOL) |
679 start_char_len = 0; | |
6402 | 680 /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */ |
6903 | 681 else if (has_mbyte |
682 && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count | |
683 && pos->col < MAXCOL - 2) | |
6402 | 684 { |
13223
e37327129859
patch 8.0.1486: accessing invalid memory with "it"
Christian Brabandt <cb@256bit.org>
parents:
13217
diff
changeset
|
685 ptr = ml_get_buf(buf, pos->lnum, FALSE); |
13225
1961162121c7
patch 8.0.1487: test 14 fails
Christian Brabandt <cb@256bit.org>
parents:
13223
diff
changeset
|
686 if ((int)STRLEN(ptr) <= pos->col) |
6903 | 687 start_char_len = 1; |
6402 | 688 else |
13223
e37327129859
patch 8.0.1486: accessing invalid memory with "it"
Christian Brabandt <cb@256bit.org>
parents:
13217
diff
changeset
|
689 start_char_len = (*mb_ptr2len)(ptr + pos->col); |
6402 | 690 } |
691 else | |
6903 | 692 start_char_len = 1; |
693 if (dir == FORWARD) | |
694 { | |
695 if (options & SEARCH_START) | |
696 extra_col = 0; | |
697 else | |
698 extra_col = start_char_len; | |
699 } | |
700 else | |
701 { | |
702 if (options & SEARCH_START) | |
703 extra_col = start_char_len; | |
704 else | |
705 extra_col = 0; | |
706 } | |
6402 | 707 |
7 | 708 start_pos = *pos; /* remember start pos for detecting no match */ |
709 found = 0; /* default: not found */ | |
710 at_first_line = TRUE; /* default: start in first line */ | |
711 if (pos->lnum == 0) /* correct lnum for when starting in line 0 */ | |
712 { | |
713 pos->lnum = 1; | |
714 pos->col = 0; | |
715 at_first_line = FALSE; /* not in first line now */ | |
716 } | |
717 | |
718 /* | |
719 * Start searching in current line, unless searching backwards and | |
720 * we're in column 0. | |
1311 | 721 * If we are searching backwards, in column 0, and not including the |
722 * current position, gain some efficiency by skipping back a line. | |
723 * Otherwise begin the search in the current line. | |
7 | 724 */ |
1311 | 725 if (dir == BACKWARD && start_pos.col == 0 |
726 && (options & SEARCH_START) == 0) | |
7 | 727 { |
728 lnum = pos->lnum - 1; | |
729 at_first_line = FALSE; | |
730 } | |
731 else | |
732 lnum = pos->lnum; | |
733 | |
734 for (loop = 0; loop <= 1; ++loop) /* loop twice if 'wrapscan' set */ | |
735 { | |
736 for ( ; lnum > 0 && lnum <= buf->b_ml.ml_line_count; | |
737 lnum += dir, at_first_line = FALSE) | |
738 { | |
692 | 739 /* Stop after checking "stop_lnum", if it's set. */ |
740 if (stop_lnum != 0 && (dir == FORWARD | |
741 ? lnum > stop_lnum : lnum < stop_lnum)) | |
742 break; | |
1496 | 743 #ifdef FEAT_RELTIME |
744 /* Stop after passing the "tm" time limit. */ | |
745 if (tm != NULL && profile_passed_limit(tm)) | |
746 break; | |
747 #endif | |
692 | 748 |
7 | 749 /* |
140 | 750 * Look for a match somewhere in line "lnum". |
7 | 751 */ |
7358
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
752 col = at_first_line && (options & SEARCH_COL) ? pos->col |
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
753 : (colnr_T)0; |
7 | 754 nmatched = vim_regexec_multi(®match, win, buf, |
7358
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
755 lnum, col, |
1521 | 756 #ifdef FEAT_RELTIME |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
757 tm, timed_out |
1521 | 758 #else |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
759 NULL, NULL |
1521 | 760 #endif |
761 ); | |
7 | 762 /* Abort searching on an error (e.g., out of stack). */ |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
763 if (called_emsg |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
764 #ifdef FEAT_RELTIME |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
765 || (timed_out != NULL && *timed_out) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
766 #endif |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
767 ) |
7 | 768 break; |
769 if (nmatched > 0) | |
770 { | |
771 /* match may actually be in another line when using \zs */ | |
140 | 772 matchpos = regmatch.startpos[0]; |
7 | 773 endpos = regmatch.endpos[0]; |
1521 | 774 #ifdef FEAT_EVAL |
7 | 775 submatch = first_submatch(®match); |
1521 | 776 #endif |
1544 | 777 /* "lnum" may be past end of buffer for "\n\zs". */ |
685 | 778 if (lnum + matchpos.lnum > buf->b_ml.ml_line_count) |
779 ptr = (char_u *)""; | |
780 else | |
781 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); | |
7 | 782 |
783 /* | |
784 * Forward search in the first line: match should be after | |
785 * the start position. If not, continue at the end of the | |
786 * match (this is vi compatible) or on the next char. | |
787 */ | |
788 if (dir == FORWARD && at_first_line) | |
789 { | |
790 match_ok = TRUE; | |
791 /* | |
140 | 792 * When the match starts in a next line it's certainly |
793 * past the start position. | |
7 | 794 * When match lands on a NUL the cursor will be put |
795 * one back afterwards, compare with that position, | |
796 * otherwise "/$" will get stuck on end of line. | |
797 */ | |
140 | 798 while (matchpos.lnum == 0 |
6402 | 799 && ((options & SEARCH_END) && first_match |
140 | 800 ? (nmatched == 1 |
801 && (int)endpos.col - 1 | |
7 | 802 < (int)start_pos.col + extra_col) |
140 | 803 : ((int)matchpos.col |
804 - (ptr[matchpos.col] == NUL) | |
805 < (int)start_pos.col + extra_col))) | |
7 | 806 { |
807 /* | |
808 * If vi-compatible searching, continue at the end | |
809 * of the match, otherwise continue one position | |
810 * forward. | |
811 */ | |
812 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) | |
813 { | |
814 if (nmatched > 1) | |
815 { | |
816 /* end is in next line, thus no match in | |
817 * this line */ | |
818 match_ok = FALSE; | |
819 break; | |
820 } | |
821 matchcol = endpos.col; | |
822 /* for empty match: advance one char */ | |
140 | 823 if (matchcol == matchpos.col |
7 | 824 && ptr[matchcol] != NUL) |
825 { | |
826 if (has_mbyte) | |
827 matchcol += | |
474 | 828 (*mb_ptr2len)(ptr + matchcol); |
7 | 829 else |
830 ++matchcol; | |
831 } | |
832 } | |
833 else | |
834 { | |
140 | 835 matchcol = matchpos.col; |
7 | 836 if (ptr[matchcol] != NUL) |
837 { | |
838 if (has_mbyte) | |
474 | 839 matchcol += (*mb_ptr2len)(ptr |
7 | 840 + matchcol); |
841 else | |
842 ++matchcol; | |
843 } | |
844 } | |
4252 | 845 if (matchcol == 0 && (options & SEARCH_START)) |
4240 | 846 break; |
7 | 847 if (ptr[matchcol] == NUL |
848 || (nmatched = vim_regexec_multi(®match, | |
140 | 849 win, buf, lnum + matchpos.lnum, |
1521 | 850 matchcol, |
851 #ifdef FEAT_RELTIME | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
852 tm, timed_out |
1521 | 853 #else |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
854 NULL, NULL |
1521 | 855 #endif |
856 )) == 0) | |
7 | 857 { |
858 match_ok = FALSE; | |
859 break; | |
860 } | |
140 | 861 matchpos = regmatch.startpos[0]; |
7 | 862 endpos = regmatch.endpos[0]; |
863 # ifdef FEAT_EVAL | |
864 submatch = first_submatch(®match); | |
865 # endif | |
866 | |
867 /* Need to get the line pointer again, a | |
868 * multi-line search may have made it invalid. */ | |
140 | 869 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); |
7 | 870 } |
871 if (!match_ok) | |
872 continue; | |
873 } | |
874 if (dir == BACKWARD) | |
875 { | |
876 /* | |
877 * Now, if there are multiple matches on this line, | |
878 * we have to get the last one. Or the last one before | |
879 * the cursor, if we're on that line. | |
880 * When putting the new cursor at the end, compare | |
881 * relative to the end of the match. | |
882 */ | |
883 match_ok = FALSE; | |
884 for (;;) | |
885 { | |
140 | 886 /* Remember a position that is before the start |
887 * position, we use it if it's the last match in | |
888 * the line. Always accept a position after | |
889 * wrapping around. */ | |
890 if (loop | |
891 || ((options & SEARCH_END) | |
892 ? (lnum + regmatch.endpos[0].lnum | |
893 < start_pos.lnum | |
894 || (lnum + regmatch.endpos[0].lnum | |
895 == start_pos.lnum | |
896 && (int)regmatch.endpos[0].col - 1 | |
6903 | 897 < (int)start_pos.col |
898 + extra_col)) | |
140 | 899 : (lnum + regmatch.startpos[0].lnum |
900 < start_pos.lnum | |
901 || (lnum + regmatch.startpos[0].lnum | |
902 == start_pos.lnum | |
903 && (int)regmatch.startpos[0].col | |
6903 | 904 < (int)start_pos.col |
905 + extra_col)))) | |
7 | 906 { |
907 match_ok = TRUE; | |
140 | 908 matchpos = regmatch.startpos[0]; |
7 | 909 endpos = regmatch.endpos[0]; |
910 # ifdef FEAT_EVAL | |
911 submatch = first_submatch(®match); | |
912 # endif | |
913 } | |
914 else | |
915 break; | |
916 | |
917 /* | |
918 * We found a valid match, now check if there is | |
919 * another one after it. | |
920 * If vi-compatible searching, continue at the end | |
921 * of the match, otherwise continue one position | |
922 * forward. | |
923 */ | |
924 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) | |
925 { | |
926 if (nmatched > 1) | |
927 break; | |
928 matchcol = endpos.col; | |
929 /* for empty match: advance one char */ | |
140 | 930 if (matchcol == matchpos.col |
7 | 931 && ptr[matchcol] != NUL) |
932 { | |
933 if (has_mbyte) | |
934 matchcol += | |
474 | 935 (*mb_ptr2len)(ptr + matchcol); |
7 | 936 else |
937 ++matchcol; | |
938 } | |
939 } | |
940 else | |
941 { | |
140 | 942 /* Stop when the match is in a next line. */ |
943 if (matchpos.lnum > 0) | |
944 break; | |
945 matchcol = matchpos.col; | |
7 | 946 if (ptr[matchcol] != NUL) |
947 { | |
948 if (has_mbyte) | |
949 matchcol += | |
474 | 950 (*mb_ptr2len)(ptr + matchcol); |
7 | 951 else |
952 ++matchcol; | |
953 } | |
954 } | |
955 if (ptr[matchcol] == NUL | |
956 || (nmatched = vim_regexec_multi(®match, | |
140 | 957 win, buf, lnum + matchpos.lnum, |
1521 | 958 matchcol, |
959 #ifdef FEAT_RELTIME | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
960 tm, timed_out |
1521 | 961 #else |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
962 NULL, NULL |
1521 | 963 #endif |
964 )) == 0) | |
13217
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
965 { |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
966 #ifdef FEAT_RELTIME |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
967 /* If the search timed out, we did find a match |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
968 * but it might be the wrong one, so that's not |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
969 * OK. */ |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
970 if (timed_out != NULL && *timed_out) |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
971 match_ok = FALSE; |
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
972 #endif |
7 | 973 break; |
13217
891b821d3602
patch 8.0.1483: searchpair() might return an invalid value on timeout
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
974 } |
7 | 975 |
976 /* Need to get the line pointer again, a | |
977 * multi-line search may have made it invalid. */ | |
140 | 978 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); |
7 | 979 } |
980 | |
981 /* | |
982 * If there is only a match after the cursor, skip | |
983 * this match. | |
984 */ | |
985 if (!match_ok) | |
986 continue; | |
987 } | |
988 | |
1544 | 989 /* With the SEARCH_END option move to the last character |
990 * of the match. Don't do it for an empty match, end | |
991 * should be same as start then. */ | |
4252 | 992 if ((options & SEARCH_END) && !(options & SEARCH_NOOF) |
1544 | 993 && !(matchpos.lnum == endpos.lnum |
994 && matchpos.col == endpos.col)) | |
7 | 995 { |
1544 | 996 /* For a match in the first column, set the position |
997 * on the NUL in the previous line. */ | |
140 | 998 pos->lnum = lnum + endpos.lnum; |
1544 | 999 pos->col = endpos.col; |
1000 if (endpos.col == 0) | |
819 | 1001 { |
1544 | 1002 if (pos->lnum > 1) /* just in case */ |
1003 { | |
1004 --pos->lnum; | |
1005 pos->col = (colnr_T)STRLEN(ml_get_buf(buf, | |
1006 pos->lnum, FALSE)); | |
1007 } | |
1008 } | |
1009 else | |
1010 { | |
1011 --pos->col; | |
1012 if (has_mbyte | |
1013 && pos->lnum <= buf->b_ml.ml_line_count) | |
1014 { | |
1060 | 1015 ptr = ml_get_buf(buf, pos->lnum, FALSE); |
1544 | 1016 pos->col -= (*mb_head_off)(ptr, ptr + pos->col); |
1017 } | |
819 | 1018 } |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1019 if (end_pos != NULL) |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1020 { |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1021 end_pos->lnum = lnum + matchpos.lnum; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1022 end_pos->col = matchpos.col; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1023 } |
7 | 1024 } |
1025 else | |
1026 { | |
140 | 1027 pos->lnum = lnum + matchpos.lnum; |
1028 pos->col = matchpos.col; | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1029 if (end_pos != NULL) |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1030 { |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1031 end_pos->lnum = lnum + endpos.lnum; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1032 end_pos->col = endpos.col; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1033 } |
7 | 1034 } |
1035 pos->coladd = 0; | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1036 if (end_pos != NULL) |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
1037 end_pos->coladd = 0; |
7 | 1038 found = 1; |
6402 | 1039 first_match = FALSE; |
7 | 1040 |
1041 /* Set variables used for 'incsearch' highlighting. */ | |
140 | 1042 search_match_lines = endpos.lnum - matchpos.lnum; |
7 | 1043 search_match_endcol = endpos.col; |
1044 break; | |
1045 } | |
1046 line_breakcheck(); /* stop if ctrl-C typed */ | |
1047 if (got_int) | |
1048 break; | |
1049 | |
1050 #ifdef FEAT_SEARCH_EXTRA | |
1051 /* Cancel searching if a character was typed. Used for | |
1052 * 'incsearch'. Don't check too often, that would slowdown | |
1053 * searching too much. */ | |
1054 if ((options & SEARCH_PEEK) | |
1055 && ((lnum - pos->lnum) & 0x3f) == 0 | |
1056 && char_avail()) | |
1057 { | |
1058 break_loop = TRUE; | |
1059 break; | |
1060 } | |
1061 #endif | |
1062 | |
1063 if (loop && lnum == start_pos.lnum) | |
1064 break; /* if second loop, stop where started */ | |
1065 } | |
1066 at_first_line = FALSE; | |
1067 | |
1068 /* | |
692 | 1069 * Stop the search if wrapscan isn't set, "stop_lnum" is |
1070 * specified, after an interrupt, after a match and after looping | |
1071 * twice. | |
7 | 1072 */ |
692 | 1073 if (!p_ws || stop_lnum != 0 || got_int || called_emsg |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1074 #ifdef FEAT_RELTIME |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1075 || (timed_out != NULL && *timed_out) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1076 #endif |
1877 | 1077 #ifdef FEAT_SEARCH_EXTRA |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1078 || break_loop |
1877 | 1079 #endif |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1080 || found || loop) |
7 | 1081 break; |
1082 | |
1083 /* | |
1084 * If 'wrapscan' is set we continue at the other end of the file. | |
1085 * If 'shortmess' does not contain 's', we give a message. | |
1086 * This message is also remembered in keep_msg for when the screen | |
1087 * is redrawn. The keep_msg is cleared whenever another message is | |
1088 * written. | |
1089 */ | |
1090 if (dir == BACKWARD) /* start second loop at the other end */ | |
1091 lnum = buf->b_ml.ml_line_count; | |
1092 else | |
1093 lnum = 1; | |
504 | 1094 if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG)) |
1095 give_warning((char_u *)_(dir == BACKWARD | |
1096 ? top_bot_msg : bot_top_msg), TRUE); | |
7 | 1097 } |
1877 | 1098 if (got_int || called_emsg |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1099 #ifdef FEAT_RELTIME |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1100 || (timed_out != NULL && *timed_out) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1101 #endif |
1877 | 1102 #ifdef FEAT_SEARCH_EXTRA |
1103 || break_loop | |
1104 #endif | |
1105 ) | |
7 | 1106 break; |
1107 } | |
1108 while (--count > 0 && found); /* stop after count matches or no match */ | |
1109 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1110 vim_regfree(regmatch.regprog); |
7 | 1111 |
648 | 1112 called_emsg |= save_called_emsg; |
1113 | |
7 | 1114 if (!found) /* did not find it */ |
1115 { | |
1116 if (got_int) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1117 emsg(_(e_interr)); |
7 | 1118 else if ((options & SEARCH_MSG) == SEARCH_MSG) |
1119 { | |
1120 if (p_ws) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1121 semsg(_(e_patnotf2), mr_pattern); |
7 | 1122 else if (lnum == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1123 semsg(_("E384: search hit TOP without match for: %s"), |
7 | 1124 mr_pattern); |
1125 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1126 semsg(_("E385: search hit BOTTOM without match for: %s"), |
7 | 1127 mr_pattern); |
1128 } | |
1129 return FAIL; | |
1130 } | |
1131 | |
685 | 1132 /* A pattern like "\n\zs" may go past the last line. */ |
1133 if (pos->lnum > buf->b_ml.ml_line_count) | |
1134 { | |
1135 pos->lnum = buf->b_ml.ml_line_count; | |
835 | 1136 pos->col = (int)STRLEN(ml_get_buf(buf, pos->lnum, FALSE)); |
685 | 1137 if (pos->col > 0) |
1138 --pos->col; | |
1139 } | |
1140 | |
7 | 1141 return submatch + 1; |
1142 } | |
1143 | |
1144 #ifdef FEAT_EVAL | |
1624 | 1145 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1146 set_search_direction(int cdir) |
1624 | 1147 { |
1148 spats[0].off.dir = cdir; | |
1149 } | |
1150 | |
1151 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1152 set_vv_searchforward(void) |
1624 | 1153 { |
1154 set_vim_var_nr(VV_SEARCHFORWARD, (long)(spats[0].off.dir == '/')); | |
1155 } | |
1156 | |
7 | 1157 /* |
1158 * Return the number of the first subpat that matched. | |
7358
6fbeef3b65e6
commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799
Christian Brabandt <cb@256bit.org>
parents:
7070
diff
changeset
|
1159 * Return zero if none of them matched. |
7 | 1160 */ |
1161 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1162 first_submatch(regmmatch_T *rp) |
7 | 1163 { |
1164 int submatch; | |
1165 | |
1166 for (submatch = 1; ; ++submatch) | |
1167 { | |
1168 if (rp->startpos[submatch].lnum >= 0) | |
1169 break; | |
1170 if (submatch == 9) | |
1171 { | |
1172 submatch = 0; | |
1173 break; | |
1174 } | |
1175 } | |
1176 return submatch; | |
1177 } | |
1178 #endif | |
1179 | |
1180 /* | |
1181 * Highest level string search function. | |
1222 | 1182 * Search for the 'count'th occurrence of pattern 'pat' in direction 'dirc' |
7 | 1183 * If 'dirc' is 0: use previous dir. |
1184 * If 'pat' is NULL or empty : use previous string. | |
1185 * If 'options & SEARCH_REV' : go in reverse of previous dir. | |
1186 * If 'options & SEARCH_ECHO': echo the search command and handle options | |
1187 * If 'options & SEARCH_MSG' : may give error message | |
1188 * If 'options & SEARCH_OPT' : interpret optional flags | |
1189 * If 'options & SEARCH_HIS' : put search pattern in history | |
1190 * If 'options & SEARCH_NOOF': don't add offset to position | |
1191 * If 'options & SEARCH_MARK': set previous context mark | |
1192 * If 'options & SEARCH_KEEP': keep previous search pattern | |
1193 * If 'options & SEARCH_START': accept match at curpos itself | |
1194 * If 'options & SEARCH_PEEK': check for typed char, cancel search | |
1195 * | |
1196 * Careful: If spats[0].off.line == TRUE and spats[0].off.off == 0 this | |
1197 * makes the movement linewise without moving the match position. | |
1198 * | |
6661 | 1199 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
7 | 1200 */ |
1201 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1202 do_search( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1203 oparg_T *oap, /* can be NULL */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1204 int dirc, /* '/' or '?' */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1205 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1206 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1207 int options, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1208 proftime_T *tm, /* timeout limit or NULL */ |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1209 int *timed_out) /* flag set on timeout or NULL */ |
7 | 1210 { |
1211 pos_T pos; /* position of the last match */ | |
1212 char_u *searchstr; | |
1213 struct soffset old_off; | |
1214 int retval; /* Return value */ | |
1215 char_u *p; | |
1216 long c; | |
1217 char_u *dircp; | |
1218 char_u *strcopy = NULL; | |
1219 char_u *ps; | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1220 char_u *msgbuf = NULL; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1221 size_t len; |
7 | 1222 |
1223 /* | |
1224 * A line offset is not remembered, this is vi compatible. | |
1225 */ | |
1226 if (spats[0].off.line && vim_strchr(p_cpo, CPO_LINEOFF) != NULL) | |
1227 { | |
1228 spats[0].off.line = FALSE; | |
1229 spats[0].off.off = 0; | |
1230 } | |
1231 | |
1232 /* | |
1233 * Save the values for when (options & SEARCH_KEEP) is used. | |
1234 * (there is no "if ()" around this because gcc wants them initialized) | |
1235 */ | |
1236 old_off = spats[0].off; | |
1237 | |
1238 pos = curwin->w_cursor; /* start searching at the cursor position */ | |
1239 | |
1240 /* | |
1241 * Find out the direction of the search. | |
1242 */ | |
1243 if (dirc == 0) | |
1244 dirc = spats[0].off.dir; | |
1245 else | |
1624 | 1246 { |
7 | 1247 spats[0].off.dir = dirc; |
1624 | 1248 #if defined(FEAT_EVAL) |
1249 set_vv_searchforward(); | |
1250 #endif | |
1251 } | |
7 | 1252 if (options & SEARCH_REV) |
1253 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1254 #ifdef MSWIN |
7 | 1255 /* There is a bug in the Visual C++ 2.2 compiler which means that |
1256 * dirc always ends up being '/' */ | |
1257 dirc = (dirc == '/') ? '?' : '/'; | |
1258 #else | |
1259 if (dirc == '/') | |
1260 dirc = '?'; | |
1261 else | |
1262 dirc = '/'; | |
1263 #endif | |
1264 } | |
1265 | |
1266 #ifdef FEAT_FOLDING | |
1267 /* If the cursor is in a closed fold, don't find another match in the same | |
1268 * fold. */ | |
1269 if (dirc == '/') | |
1270 { | |
1271 if (hasFolding(pos.lnum, NULL, &pos.lnum)) | |
1272 pos.col = MAXCOL - 2; /* avoid overflow when adding 1 */ | |
1273 } | |
1274 else | |
1275 { | |
1276 if (hasFolding(pos.lnum, &pos.lnum, NULL)) | |
1277 pos.col = 0; | |
1278 } | |
1279 #endif | |
1280 | |
1281 #ifdef FEAT_SEARCH_EXTRA | |
1282 /* | |
1283 * Turn 'hlsearch' highlighting back on. | |
1284 */ | |
1285 if (no_hlsearch && !(options & SEARCH_KEEP)) | |
1286 { | |
745 | 1287 redraw_all_later(SOME_VALID); |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1288 set_no_hlsearch(FALSE); |
7 | 1289 } |
1290 #endif | |
1291 | |
1292 /* | |
1293 * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar". | |
1294 */ | |
1295 for (;;) | |
1296 { | |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
1297 int show_top_bot_msg = FALSE; |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
1298 |
7 | 1299 searchstr = pat; |
1300 dircp = NULL; | |
1301 /* use previous pattern */ | |
1302 if (pat == NULL || *pat == NUL || *pat == dirc) | |
1303 { | |
1304 if (spats[RE_SEARCH].pat == NULL) /* no previous pattern */ | |
1305 { | |
10172
ab45de65977b
commit https://github.com/vim/vim/commit/ea683da58cf9ecf3afab9d650d3d2da76e5298d3
Christian Brabandt <cb@256bit.org>
parents:
10064
diff
changeset
|
1306 searchstr = spats[RE_SUBST].pat; |
ab45de65977b
commit https://github.com/vim/vim/commit/ea683da58cf9ecf3afab9d650d3d2da76e5298d3
Christian Brabandt <cb@256bit.org>
parents:
10064
diff
changeset
|
1307 if (searchstr == NULL) |
2719 | 1308 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1309 emsg(_(e_noprevre)); |
2719 | 1310 retval = 0; |
1311 goto end_do_search; | |
1312 } | |
7 | 1313 } |
2719 | 1314 else |
1315 { | |
1316 /* make search_regcomp() use spats[RE_SEARCH].pat */ | |
1317 searchstr = (char_u *)""; | |
1318 } | |
7 | 1319 } |
1320 | |
1321 if (pat != NULL && *pat != NUL) /* look for (new) offset */ | |
1322 { | |
1323 /* | |
1324 * Find end of regular expression. | |
1325 * If there is a matching '/' or '?', toss it. | |
1326 */ | |
1327 ps = strcopy; | |
1328 p = skip_regexp(pat, dirc, (int)p_magic, &strcopy); | |
1329 if (strcopy != ps) | |
1330 { | |
1331 /* made a copy of "pat" to change "\?" to "?" */ | |
835 | 1332 searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy)); |
7 | 1333 pat = strcopy; |
1334 searchstr = strcopy; | |
1335 } | |
1336 if (*p == dirc) | |
1337 { | |
1338 dircp = p; /* remember where we put the NUL */ | |
1339 *p++ = NUL; | |
1340 } | |
1341 spats[0].off.line = FALSE; | |
1342 spats[0].off.end = FALSE; | |
1343 spats[0].off.off = 0; | |
1344 /* | |
1345 * Check for a line offset or a character offset. | |
1346 * For get_address (echo off) we don't check for a character | |
1347 * offset, because it is meaningless and the 's' could be a | |
1348 * substitute command. | |
1349 */ | |
1350 if (*p == '+' || *p == '-' || VIM_ISDIGIT(*p)) | |
1351 spats[0].off.line = TRUE; | |
1352 else if ((options & SEARCH_OPT) && | |
1353 (*p == 'e' || *p == 's' || *p == 'b')) | |
1354 { | |
1355 if (*p == 'e') /* end */ | |
1356 spats[0].off.end = SEARCH_END; | |
1357 ++p; | |
1358 } | |
1359 if (VIM_ISDIGIT(*p) || *p == '+' || *p == '-') /* got an offset */ | |
1360 { | |
1361 /* 'nr' or '+nr' or '-nr' */ | |
1362 if (VIM_ISDIGIT(*p) || VIM_ISDIGIT(*(p + 1))) | |
1363 spats[0].off.off = atol((char *)p); | |
1364 else if (*p == '-') /* single '-' */ | |
1365 spats[0].off.off = -1; | |
1366 else /* single '+' */ | |
1367 spats[0].off.off = 1; | |
1368 ++p; | |
1369 while (VIM_ISDIGIT(*p)) /* skip number */ | |
1370 ++p; | |
1371 } | |
1372 | |
1373 /* compute length of search command for get_address() */ | |
1374 searchcmdlen += (int)(p - pat); | |
1375 | |
1376 pat = p; /* put pat after search command */ | |
1377 } | |
1378 | |
1379 if ((options & SEARCH_ECHO) && messaging() | |
1380 && !cmd_silent && msg_silent == 0) | |
1381 { | |
1382 char_u *trunc; | |
1383 | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1384 // Compute msg_row early. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1385 msg_start(); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1386 |
7 | 1387 if (*searchstr == NUL) |
15089
e428882d6ffb
patch 8.1.0555: crash when last search pat is set but not last substitute pat
Bram Moolenaar <Bram@vim.org>
parents:
15083
diff
changeset
|
1388 p = spats[0].pat; |
7 | 1389 else |
1390 p = searchstr; | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1391 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1392 if (!shortmess(SHM_SEARCHCOUNT)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1393 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1394 // Reserve enough space for the search pattern + offset + |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1395 // search stat. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1396 if (msg_scrolled != 0) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1397 // Use all the columns. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1398 len = (int)(Rows - msg_row) * Columns - 1; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1399 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1400 // Use up to 'showcmd' column. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1401 len = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1402 if (len < STRLEN(p) + 40 + 11) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1403 len = STRLEN(p) + 40 + 11; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1404 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1405 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1406 // Reserve enough space for the search pattern + offset. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1407 len = STRLEN(p) + 40; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1408 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1409 msgbuf = alloc((int)len); |
7 | 1410 if (msgbuf != NULL) |
1411 { | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1412 vim_memset(msgbuf, ' ', len); |
7 | 1413 msgbuf[0] = dirc; |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1414 msgbuf[len - 1] = NUL; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1415 |
507 | 1416 if (enc_utf8 && utf_iscomposing(utf_ptr2char(p))) |
1417 { | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1418 // Use a space to draw the composing char on. |
507 | 1419 msgbuf[1] = ' '; |
16535
be24441bf806
patch 8.1.1271: compiler warnings for use of STRNCPY()
Bram Moolenaar <Bram@vim.org>
parents:
16533
diff
changeset
|
1420 mch_memmove(msgbuf + 2, p, STRLEN(p)); |
507 | 1421 } |
1422 else | |
16535
be24441bf806
patch 8.1.1271: compiler warnings for use of STRNCPY()
Bram Moolenaar <Bram@vim.org>
parents:
16533
diff
changeset
|
1423 mch_memmove(msgbuf + 1, p, STRLEN(p)); |
7 | 1424 if (spats[0].off.line || spats[0].off.end || spats[0].off.off) |
1425 { | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1426 p = msgbuf + STRLEN(p) + 1; |
7 | 1427 *p++ = dirc; |
1428 if (spats[0].off.end) | |
1429 *p++ = 'e'; | |
1430 else if (!spats[0].off.line) | |
1431 *p++ = 's'; | |
1432 if (spats[0].off.off > 0 || spats[0].off.line) | |
1433 *p++ = '+'; | |
1434 if (spats[0].off.off != 0 || spats[0].off.line) | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1435 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1436 int l = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1437 l = sprintf((char *)p, "%ld", spats[0].off.off); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1438 p[l] = ' '; // remove NUL from sprintf |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1439 } |
7 | 1440 } |
1441 | |
516 | 1442 trunc = msg_strtrunc(msgbuf, FALSE); |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1443 if (trunc != NULL) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1444 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1445 vim_free(msgbuf); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1446 msgbuf = trunc; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1447 } |
7 | 1448 |
1449 #ifdef FEAT_RIGHTLEFT | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1450 // The search pattern could be shown on the right in rightleft |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1451 // mode, but the 'ruler' and 'showcmd' area use it too, thus |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1452 // it would be blanked out again very soon. Show it on the |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1453 // left, but do reverse the text. |
7 | 1454 if (curwin->w_p_rl && *curwin->w_p_rlc == 's') |
1455 { | |
1456 char_u *r; | |
1457 | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1458 r = reverse_text(msgbuf); |
7 | 1459 if (r != NULL) |
1460 { | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1461 vim_free(msgbuf); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1462 msgbuf = r; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1463 // move reversed text to beginning of buffer |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1464 while (*r != NUL && *r == ' ') |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1465 r++; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1466 mch_memmove(msgbuf, r, msgbuf + STRLEN(msgbuf) - r); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1467 // overwrite old text |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1468 vim_memset(r, ' ', msgbuf + STRLEN(msgbuf) - r); |
7 | 1469 } |
1470 } | |
1471 #endif | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1472 msg_outtrans(msgbuf); |
7 | 1473 msg_clr_eos(); |
1474 msg_check(); | |
1475 | |
1476 gotocmdline(FALSE); | |
1477 out_flush(); | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1478 msg_nowait = TRUE; // don't wait for this message |
7 | 1479 } |
1480 } | |
1481 | |
1482 /* | |
1483 * If there is a character offset, subtract it from the current | |
1484 * position, so we don't get stuck at "?pat?e+2" or "/pat/s-2". | |
8 | 1485 * Skip this if pos.col is near MAXCOL (closed fold). |
7 | 1486 * This is not done for a line offset, because then we would not be vi |
1487 * compatible. | |
1488 */ | |
8 | 1489 if (!spats[0].off.line && spats[0].off.off && pos.col < MAXCOL - 2) |
7 | 1490 { |
1491 if (spats[0].off.off > 0) | |
1492 { | |
1493 for (c = spats[0].off.off; c; --c) | |
1494 if (decl(&pos) == -1) | |
1495 break; | |
1496 if (c) /* at start of buffer */ | |
1497 { | |
1498 pos.lnum = 0; /* allow lnum == 0 here */ | |
1499 pos.col = MAXCOL; | |
1500 } | |
1501 } | |
1502 else | |
1503 { | |
1504 for (c = spats[0].off.off; c; ++c) | |
1505 if (incl(&pos) == -1) | |
1506 break; | |
1507 if (c) /* at end of buffer */ | |
1508 { | |
1509 pos.lnum = curbuf->b_ml.ml_line_count + 1; | |
1510 pos.col = 0; | |
1511 } | |
1512 } | |
1513 } | |
1514 | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15758
diff
changeset
|
1515 c = searchit(curwin, curbuf, &pos, NULL, |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15758
diff
changeset
|
1516 dirc == '/' ? FORWARD : BACKWARD, |
7 | 1517 searchstr, count, spats[0].off.end + (options & |
1518 (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS | |
1519 + SEARCH_MSG + SEARCH_START | |
1520 + ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))), | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
1521 RE_LAST, (linenr_T)0, tm, timed_out); |
7 | 1522 |
1523 if (dircp != NULL) | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1524 *dircp = dirc; // restore second '/' or '?' for normal_cmd() |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1525 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1526 if (!shortmess(SHM_SEARCH) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1527 && ((dirc == '/' && LT_POS(pos, curwin->w_cursor)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1528 || (dirc == '?' && LT_POS(curwin->w_cursor, pos)))) |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
1529 show_top_bot_msg = TRUE; |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1530 |
7 | 1531 if (c == FAIL) |
1532 { | |
1533 retval = 0; | |
1534 goto end_do_search; | |
1535 } | |
1536 if (spats[0].off.end && oap != NULL) | |
1537 oap->inclusive = TRUE; /* 'e' includes last character */ | |
1538 | |
1539 retval = 1; /* pattern found */ | |
1540 | |
1541 /* | |
1542 * Add character and/or line offset | |
1543 */ | |
945 | 1544 if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';')) |
7 | 1545 { |
1546 if (spats[0].off.line) /* Add the offset to the line number. */ | |
1547 { | |
1548 c = pos.lnum + spats[0].off.off; | |
1549 if (c < 1) | |
1550 pos.lnum = 1; | |
1551 else if (c > curbuf->b_ml.ml_line_count) | |
1552 pos.lnum = curbuf->b_ml.ml_line_count; | |
1553 else | |
1554 pos.lnum = c; | |
1555 pos.col = 0; | |
1556 | |
1557 retval = 2; /* pattern found, line offset added */ | |
1558 } | |
8 | 1559 else if (pos.col < MAXCOL - 2) /* just in case */ |
7 | 1560 { |
1561 /* to the right, check for end of file */ | |
1624 | 1562 c = spats[0].off.off; |
1563 if (c > 0) | |
7 | 1564 { |
1624 | 1565 while (c-- > 0) |
7 | 1566 if (incl(&pos) == -1) |
1567 break; | |
1568 } | |
1569 /* to the left, check for start of file */ | |
1570 else | |
1571 { | |
1624 | 1572 while (c++ < 0) |
1573 if (decl(&pos) == -1) | |
1574 break; | |
7 | 1575 } |
1576 } | |
1577 } | |
1578 | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1579 // Show [1/15] if 'S' is not in 'shortmess'. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1580 if ((options & SEARCH_ECHO) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1581 && messaging() |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1582 && !(cmd_silent + msg_silent) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1583 && c != FAIL |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1584 && !shortmess(SHM_SEARCHCOUNT) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1585 && msgbuf != NULL) |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
1586 search_stat(dirc, &pos, show_top_bot_msg, msgbuf); |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1587 |
7 | 1588 /* |
1589 * The search command can be followed by a ';' to do another search. | |
1590 * For example: "/pat/;/foo/+3;?bar" | |
1591 * This is like doing another search command, except: | |
1592 * - The remembered direction '/' or '?' is from the first search. | |
1593 * - When an error happens the cursor isn't moved at all. | |
1594 * Don't do this when called by get_address() (it handles ';' itself). | |
1595 */ | |
1596 if (!(options & SEARCH_OPT) || pat == NULL || *pat != ';') | |
1597 break; | |
1598 | |
1599 dirc = *++pat; | |
1600 if (dirc != '?' && dirc != '/') | |
1601 { | |
1602 retval = 0; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1603 emsg(_("E386: Expected '?' or '/' after ';'")); |
7 | 1604 goto end_do_search; |
1605 } | |
1606 ++pat; | |
1607 } | |
1608 | |
1609 if (options & SEARCH_MARK) | |
1610 setpcmark(); | |
1611 curwin->w_cursor = pos; | |
1612 curwin->w_set_curswant = TRUE; | |
1613 | |
1614 end_do_search: | |
5616 | 1615 if ((options & SEARCH_KEEP) || cmdmod.keeppatterns) |
7 | 1616 spats[0].off = old_off; |
1617 vim_free(strcopy); | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1618 vim_free(msgbuf); |
7 | 1619 |
1620 return retval; | |
1621 } | |
1622 | |
1623 #if defined(FEAT_INS_EXPAND) || defined(PROTO) | |
1624 /* | |
1625 * search_for_exact_line(buf, pos, dir, pat) | |
1626 * | |
1627 * Search for a line starting with the given pattern (ignoring leading | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
1628 * white-space), starting from pos and going in direction "dir". "pos" will |
7 | 1629 * contain the position of the match found. Blank lines match only if |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
1630 * ADDING is set. If p_ic is set then the pattern must be in lowercase. |
7 | 1631 * Return OK for success, or FAIL if no line found. |
1632 */ | |
1633 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1634 search_for_exact_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1635 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1636 pos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 int dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1638 char_u *pat) |
7 | 1639 { |
1640 linenr_T start = 0; | |
1641 char_u *ptr; | |
1642 char_u *p; | |
1643 | |
1644 if (buf->b_ml.ml_line_count == 0) | |
1645 return FAIL; | |
1646 for (;;) | |
1647 { | |
1648 pos->lnum += dir; | |
1649 if (pos->lnum < 1) | |
1650 { | |
1651 if (p_ws) | |
1652 { | |
1653 pos->lnum = buf->b_ml.ml_line_count; | |
1654 if (!shortmess(SHM_SEARCH)) | |
1655 give_warning((char_u *)_(top_bot_msg), TRUE); | |
1656 } | |
1657 else | |
1658 { | |
1659 pos->lnum = 1; | |
1660 break; | |
1661 } | |
1662 } | |
1663 else if (pos->lnum > buf->b_ml.ml_line_count) | |
1664 { | |
1665 if (p_ws) | |
1666 { | |
1667 pos->lnum = 1; | |
1668 if (!shortmess(SHM_SEARCH)) | |
1669 give_warning((char_u *)_(bot_top_msg), TRUE); | |
1670 } | |
1671 else | |
1672 { | |
1673 pos->lnum = 1; | |
1674 break; | |
1675 } | |
1676 } | |
1677 if (pos->lnum == start) | |
1678 break; | |
1679 if (start == 0) | |
1680 start = pos->lnum; | |
1681 ptr = ml_get_buf(buf, pos->lnum, FALSE); | |
1682 p = skipwhite(ptr); | |
1683 pos->col = (colnr_T) (p - ptr); | |
1684 | |
1685 /* when adding lines the matching line may be empty but it is not | |
1686 * ignored because we are interested in the next line -- Acevedo */ | |
449 | 1687 if ((compl_cont_status & CONT_ADDING) |
1688 && !(compl_cont_status & CONT_SOL)) | |
7 | 1689 { |
1690 if ((p_ic ? MB_STRICMP(p, pat) : STRCMP(p, pat)) == 0) | |
1691 return OK; | |
1692 } | |
1693 else if (*p != NUL) /* ignore empty lines */ | |
1694 { /* expanding lines or words */ | |
449 | 1695 if ((p_ic ? MB_STRNICMP(p, pat, compl_length) |
1696 : STRNCMP(p, pat, compl_length)) == 0) | |
7 | 1697 return OK; |
1698 } | |
1699 } | |
1700 return FAIL; | |
1701 } | |
1702 #endif /* FEAT_INS_EXPAND */ | |
1703 | |
1704 /* | |
1705 * Character Searches | |
1706 */ | |
1707 | |
1708 /* | |
1709 * Search for a character in a line. If "t_cmd" is FALSE, move to the | |
1710 * position of the character, otherwise move to just before the char. | |
1711 * Do this "cap->count1" times. | |
1712 * Return FAIL or OK. | |
1713 */ | |
1714 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1715 searchc(cmdarg_T *cap, int t_cmd) |
7 | 1716 { |
1717 int c = cap->nchar; /* char to search for */ | |
1718 int dir = cap->arg; /* TRUE for searching forward */ | |
1719 long count = cap->count1; /* repeat count */ | |
1720 int col; | |
1721 char_u *p; | |
1722 int len; | |
2925 | 1723 int stop = TRUE; |
7 | 1724 |
1725 if (c != NUL) /* normal search: remember args for repeat */ | |
1726 { | |
1727 if (!KeyStuffed) /* don't remember when redoing */ | |
1728 { | |
6991 | 1729 *lastc = c; |
1730 set_csearch_direction(dir); | |
1731 set_csearch_until(t_cmd); | |
1732 lastc_bytelen = (*mb_char2bytes)(c, lastc_bytes); | |
7 | 1733 if (cap->ncharC1 != 0) |
1734 { | |
6991 | 1735 lastc_bytelen += (*mb_char2bytes)(cap->ncharC1, |
1736 lastc_bytes + lastc_bytelen); | |
7 | 1737 if (cap->ncharC2 != 0) |
6991 | 1738 lastc_bytelen += (*mb_char2bytes)(cap->ncharC2, |
1739 lastc_bytes + lastc_bytelen); | |
7 | 1740 } |
1741 } | |
1742 } | |
1743 else /* repeat previous search */ | |
1744 { | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1745 if (*lastc == NUL && lastc_bytelen == 1) |
7 | 1746 return FAIL; |
1747 if (dir) /* repeat in opposite direction */ | |
1748 dir = -lastcdir; | |
1749 else | |
1750 dir = lastcdir; | |
1751 t_cmd = last_t_cmd; | |
6991 | 1752 c = *lastc; |
1753 /* For multi-byte re-use last lastc_bytes[] and lastc_bytelen. */ | |
2925 | 1754 |
1755 /* Force a move of at least one char, so ";" and "," will move the | |
1756 * cursor, even if the cursor is right in front of char we are looking | |
1757 * at. */ | |
2947 | 1758 if (vim_strchr(p_cpo, CPO_SCOLON) == NULL && count == 1 && t_cmd) |
2925 | 1759 stop = FALSE; |
7 | 1760 } |
1761 | |
530 | 1762 if (dir == BACKWARD) |
1763 cap->oap->inclusive = FALSE; | |
1764 else | |
1765 cap->oap->inclusive = TRUE; | |
1766 | |
7 | 1767 p = ml_get_curline(); |
1768 col = curwin->w_cursor.col; | |
1769 len = (int)STRLEN(p); | |
1770 | |
1771 while (count--) | |
1772 { | |
1773 if (has_mbyte) | |
1774 { | |
1775 for (;;) | |
1776 { | |
1777 if (dir > 0) | |
1778 { | |
474 | 1779 col += (*mb_ptr2len)(p + col); |
7 | 1780 if (col >= len) |
1781 return FAIL; | |
1782 } | |
1783 else | |
1784 { | |
1785 if (col == 0) | |
1786 return FAIL; | |
1787 col -= (*mb_head_off)(p, p + col - 1) + 1; | |
1788 } | |
6991 | 1789 if (lastc_bytelen == 1) |
7 | 1790 { |
2925 | 1791 if (p[col] == c && stop) |
7 | 1792 break; |
1793 } | |
11018
654fc5636b37
patch 8.0.0398: illegal memory access with "t"
Christian Brabandt <cb@256bit.org>
parents:
10900
diff
changeset
|
1794 else if (STRNCMP(p + col, lastc_bytes, lastc_bytelen) == 0 |
10430
37a441352da2
commit https://github.com/vim/vim/commit/b129a447f3b580d4c941869672b0557c52c37e4d
Christian Brabandt <cb@256bit.org>
parents:
10277
diff
changeset
|
1795 && stop) |
11018
654fc5636b37
patch 8.0.0398: illegal memory access with "t"
Christian Brabandt <cb@256bit.org>
parents:
10900
diff
changeset
|
1796 break; |
2925 | 1797 stop = TRUE; |
7 | 1798 } |
1799 } | |
1800 else | |
1801 { | |
1802 for (;;) | |
1803 { | |
1804 if ((col += dir) < 0 || col >= len) | |
1805 return FAIL; | |
2925 | 1806 if (p[col] == c && stop) |
7 | 1807 break; |
2925 | 1808 stop = TRUE; |
7 | 1809 } |
1810 } | |
1811 } | |
1812 | |
1813 if (t_cmd) | |
1814 { | |
1815 /* backup to before the character (possibly double-byte) */ | |
1816 col -= dir; | |
1817 if (has_mbyte) | |
1818 { | |
1819 if (dir < 0) | |
6991 | 1820 /* Landed on the search char which is lastc_bytelen long */ |
1821 col += lastc_bytelen - 1; | |
7 | 1822 else |
1823 /* To previous char, which may be multi-byte. */ | |
1824 col -= (*mb_head_off)(p, p + col); | |
1825 } | |
1826 } | |
1827 curwin->w_cursor.col = col; | |
1828 | |
1829 return OK; | |
1830 } | |
1831 | |
1832 /* | |
1833 * "Other" Searches | |
1834 */ | |
1835 | |
1836 /* | |
1837 * findmatch - find the matching paren or brace | |
1838 * | |
1839 * Improvement over vi: Braces inside quotes are ignored. | |
1840 */ | |
1841 pos_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1842 findmatch(oparg_T *oap, int initc) |
7 | 1843 { |
1844 return findmatchlimit(oap, initc, 0, 0); | |
1845 } | |
1846 | |
1847 /* | |
1848 * Return TRUE if the character before "linep[col]" equals "ch". | |
1849 * Return FALSE if "col" is zero. | |
1850 * Update "*prevcol" to the column of the previous character, unless "prevcol" | |
1851 * is NULL. | |
1852 * Handles multibyte string correctly. | |
1853 */ | |
1854 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1855 check_prevcol( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1856 char_u *linep, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1857 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1858 int ch, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1859 int *prevcol) |
7 | 1860 { |
1861 --col; | |
1862 if (col > 0 && has_mbyte) | |
1863 col -= (*mb_head_off)(linep, linep + col); | |
1864 if (prevcol) | |
1865 *prevcol = col; | |
1866 return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; | |
1867 } | |
1868 | |
6971 | 1869 /* |
1870 * Raw string start is found at linep[startpos.col - 1]. | |
1871 * Return TRUE if the matching end can be found between startpos and endpos. | |
1872 */ | |
1873 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1874 find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) |
6971 | 1875 { |
1876 char_u *p; | |
1877 char_u *delim_copy; | |
1878 size_t delim_len; | |
1879 linenr_T lnum; | |
1880 int found = FALSE; | |
1881 | |
1882 for (p = linep + startpos->col + 1; *p && *p != '('; ++p) | |
1883 ; | |
1884 delim_len = (p - linep) - startpos->col - 1; | |
7054
3a1a6d6fb9b3
commit https://github.com/vim/vim/commit/6ed535dbc0981d328c02e139d6505207cbef4835
Christian Brabandt <cb@256bit.org>
parents:
7019
diff
changeset
|
1885 delim_copy = vim_strnsave(linep + startpos->col + 1, (int)delim_len); |
6971 | 1886 if (delim_copy == NULL) |
1887 return FALSE; | |
1888 for (lnum = startpos->lnum; lnum <= endpos->lnum; ++lnum) | |
1889 { | |
1890 char_u *line = ml_get(lnum); | |
1891 | |
1892 for (p = line + (lnum == startpos->lnum | |
1893 ? startpos->col + 1 : 0); *p; ++p) | |
1894 { | |
1895 if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) | |
1896 break; | |
1897 if (*p == ')' && p[delim_len + 1] == '"' | |
1898 && STRNCMP(delim_copy, p + 1, delim_len) == 0) | |
1899 { | |
1900 found = TRUE; | |
1901 break; | |
1902 } | |
1903 } | |
1904 if (found) | |
1905 break; | |
1906 } | |
1907 vim_free(delim_copy); | |
1908 return found; | |
1909 } | |
1910 | |
7 | 1911 /* |
1912 * findmatchlimit -- find the matching paren or brace, if it exists within | |
6971 | 1913 * maxtravel lines of the cursor. A maxtravel of 0 means search until falling |
1914 * off the edge of the file. | |
7 | 1915 * |
1916 * "initc" is the character to find a match for. NUL means to find the | |
6971 | 1917 * character at or after the cursor. Special values: |
1918 * '*' look for C-style comment / * | |
1919 * '/' look for C-style comment / *, ignoring comment-end | |
1920 * '#' look for preprocessor directives | |
1921 * 'R' look for raw string start: R"delim(text)delim" (only backwards) | |
7 | 1922 * |
1923 * flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#') | |
1924 * FM_FORWARD search forwards (when initc is '/', '*' or '#') | |
1925 * FM_BLOCKSTOP stop at start/end of block ({ or } in column 0) | |
1926 * FM_SKIPCOMM skip comments (not implemented yet!) | |
523 | 1927 * |
6971 | 1928 * "oap" is only used to set oap->motion_type for a linewise motion, it can be |
523 | 1929 * NULL |
7 | 1930 */ |
1931 | |
1932 pos_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1933 findmatchlimit( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1934 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1935 int initc, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1936 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1937 int maxtravel) |
7 | 1938 { |
1939 static pos_T pos; /* current search position */ | |
1940 int findc = 0; /* matching brace */ | |
1941 int c; | |
1942 int count = 0; /* cumulative number of braces */ | |
1943 int backwards = FALSE; /* init for gcc */ | |
6971 | 1944 int raw_string = FALSE; /* search for raw string */ |
7 | 1945 int inquote = FALSE; /* TRUE when inside quotes */ |
1946 char_u *linep; /* pointer to current line */ | |
1947 char_u *ptr; | |
1948 int do_quotes; /* check for quotes in current line */ | |
1949 int at_start; /* do_quotes value at start position */ | |
1950 int hash_dir = 0; /* Direction searched for # things */ | |
1951 int comment_dir = 0; /* Direction searched for comments */ | |
1952 pos_T match_pos; /* Where last slash-star was found */ | |
1953 int start_in_quotes; /* start position is in quotes */ | |
1954 int traveled = 0; /* how far we've searched so far */ | |
1955 int ignore_cend = FALSE; /* ignore comment end */ | |
1956 int cpo_match; /* vi compatible matching */ | |
1957 int cpo_bsl; /* don't recognize backslashes */ | |
1958 int match_escaped = 0; /* search for escaped match */ | |
1959 int dir; /* Direction to search */ | |
1960 int comment_col = MAXCOL; /* start of / / comment */ | |
14 | 1961 #ifdef FEAT_LISP |
1962 int lispcomm = FALSE; /* inside of Lisp-style comment */ | |
1963 int lisp = curbuf->b_p_lisp; /* engage Lisp-specific hacks ;) */ | |
1964 #endif | |
7 | 1965 |
1966 pos = curwin->w_cursor; | |
5304 | 1967 pos.coladd = 0; |
7 | 1968 linep = ml_get(pos.lnum); |
1969 | |
1970 cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); | |
1971 cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL); | |
1972 | |
1973 /* Direction to search when initc is '/', '*' or '#' */ | |
1974 if (flags & FM_BACKWARD) | |
1975 dir = BACKWARD; | |
1976 else if (flags & FM_FORWARD) | |
1977 dir = FORWARD; | |
1978 else | |
1979 dir = 0; | |
1980 | |
1981 /* | |
1982 * if initc given, look in the table for the matching character | |
1983 * '/' and '*' are special cases: look for start or end of comment. | |
1984 * When '/' is used, we ignore running backwards into an star-slash, for | |
1985 * "[*" command, we just want to find any comment. | |
1986 */ | |
6971 | 1987 if (initc == '/' || initc == '*' || initc == 'R') |
7 | 1988 { |
1989 comment_dir = dir; | |
1990 if (initc == '/') | |
1991 ignore_cend = TRUE; | |
1992 backwards = (dir == FORWARD) ? FALSE : TRUE; | |
6971 | 1993 raw_string = (initc == 'R'); |
7 | 1994 initc = NUL; |
1995 } | |
1996 else if (initc != '#' && initc != NUL) | |
1997 { | |
4029 | 1998 find_mps_values(&initc, &findc, &backwards, TRUE); |
1999 if (findc == NUL) | |
7 | 2000 return NULL; |
2001 } | |
2002 else | |
2003 { | |
6971 | 2004 /* |
2005 * Either initc is '#', or no initc was given and we need to look | |
2006 * under the cursor. | |
2007 */ | |
7 | 2008 if (initc == '#') |
2009 { | |
2010 hash_dir = dir; | |
2011 } | |
2012 else | |
2013 { | |
2014 /* | |
2015 * initc was not given, must look for something to match under | |
2016 * or near the cursor. | |
2017 * Only check for special things when 'cpo' doesn't have '%'. | |
2018 */ | |
2019 if (!cpo_match) | |
2020 { | |
2021 /* Are we before or at #if, #else etc.? */ | |
2022 ptr = skipwhite(linep); | |
2023 if (*ptr == '#' && pos.col <= (colnr_T)(ptr - linep)) | |
2024 { | |
2025 ptr = skipwhite(ptr + 1); | |
2026 if ( STRNCMP(ptr, "if", 2) == 0 | |
2027 || STRNCMP(ptr, "endif", 5) == 0 | |
2028 || STRNCMP(ptr, "el", 2) == 0) | |
2029 hash_dir = 1; | |
2030 } | |
2031 | |
2032 /* Are we on a comment? */ | |
2033 else if (linep[pos.col] == '/') | |
2034 { | |
2035 if (linep[pos.col + 1] == '*') | |
2036 { | |
2037 comment_dir = FORWARD; | |
2038 backwards = FALSE; | |
2039 pos.col++; | |
2040 } | |
2041 else if (pos.col > 0 && linep[pos.col - 1] == '*') | |
2042 { | |
2043 comment_dir = BACKWARD; | |
2044 backwards = TRUE; | |
2045 pos.col--; | |
2046 } | |
2047 } | |
2048 else if (linep[pos.col] == '*') | |
2049 { | |
2050 if (linep[pos.col + 1] == '/') | |
2051 { | |
2052 comment_dir = BACKWARD; | |
2053 backwards = TRUE; | |
2054 } | |
2055 else if (pos.col > 0 && linep[pos.col - 1] == '/') | |
2056 { | |
2057 comment_dir = FORWARD; | |
2058 backwards = FALSE; | |
2059 } | |
2060 } | |
2061 } | |
2062 | |
2063 /* | |
2064 * If we are not on a comment or the # at the start of a line, then | |
2065 * look for brace anywhere on this line after the cursor. | |
2066 */ | |
2067 if (!hash_dir && !comment_dir) | |
2068 { | |
2069 /* | |
2070 * Find the brace under or after the cursor. | |
2071 * If beyond the end of the line, use the last character in | |
2072 * the line. | |
2073 */ | |
2074 if (linep[pos.col] == NUL && pos.col) | |
2075 --pos.col; | |
2076 for (;;) | |
2077 { | |
4029 | 2078 initc = PTR2CHAR(linep + pos.col); |
7 | 2079 if (initc == NUL) |
2080 break; | |
2081 | |
4029 | 2082 find_mps_values(&initc, &findc, &backwards, FALSE); |
7 | 2083 if (findc) |
2084 break; | |
4029 | 2085 pos.col += MB_PTR2LEN(linep + pos.col); |
7 | 2086 } |
2087 if (!findc) | |
2088 { | |
2089 /* no brace in the line, maybe use " #if" then */ | |
2090 if (!cpo_match && *skipwhite(linep) == '#') | |
2091 hash_dir = 1; | |
2092 else | |
2093 return NULL; | |
2094 } | |
2095 else if (!cpo_bsl) | |
2096 { | |
2097 int col, bslcnt = 0; | |
2098 | |
2099 /* Set "match_escaped" if there are an odd number of | |
2100 * backslashes. */ | |
2101 for (col = pos.col; check_prevcol(linep, col, '\\', &col);) | |
2102 bslcnt++; | |
2103 match_escaped = (bslcnt & 1); | |
2104 } | |
2105 } | |
2106 } | |
2107 if (hash_dir) | |
2108 { | |
2109 /* | |
2110 * Look for matching #if, #else, #elif, or #endif | |
2111 */ | |
2112 if (oap != NULL) | |
2113 oap->motion_type = MLINE; /* Linewise for this case only */ | |
2114 if (initc != '#') | |
2115 { | |
2116 ptr = skipwhite(skipwhite(linep) + 1); | |
2117 if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0) | |
2118 hash_dir = 1; | |
2119 else if (STRNCMP(ptr, "endif", 5) == 0) | |
2120 hash_dir = -1; | |
2121 else | |
2122 return NULL; | |
2123 } | |
2124 pos.col = 0; | |
2125 while (!got_int) | |
2126 { | |
2127 if (hash_dir > 0) | |
2128 { | |
2129 if (pos.lnum == curbuf->b_ml.ml_line_count) | |
2130 break; | |
2131 } | |
2132 else if (pos.lnum == 1) | |
2133 break; | |
2134 pos.lnum += hash_dir; | |
2135 linep = ml_get(pos.lnum); | |
2136 line_breakcheck(); /* check for CTRL-C typed */ | |
2137 ptr = skipwhite(linep); | |
2138 if (*ptr != '#') | |
2139 continue; | |
2140 pos.col = (colnr_T) (ptr - linep); | |
2141 ptr = skipwhite(ptr + 1); | |
2142 if (hash_dir > 0) | |
2143 { | |
2144 if (STRNCMP(ptr, "if", 2) == 0) | |
2145 count++; | |
2146 else if (STRNCMP(ptr, "el", 2) == 0) | |
2147 { | |
2148 if (count == 0) | |
2149 return &pos; | |
2150 } | |
2151 else if (STRNCMP(ptr, "endif", 5) == 0) | |
2152 { | |
2153 if (count == 0) | |
2154 return &pos; | |
2155 count--; | |
2156 } | |
2157 } | |
2158 else | |
2159 { | |
2160 if (STRNCMP(ptr, "if", 2) == 0) | |
2161 { | |
2162 if (count == 0) | |
2163 return &pos; | |
2164 count--; | |
2165 } | |
2166 else if (initc == '#' && STRNCMP(ptr, "el", 2) == 0) | |
2167 { | |
2168 if (count == 0) | |
2169 return &pos; | |
2170 } | |
2171 else if (STRNCMP(ptr, "endif", 5) == 0) | |
2172 count++; | |
2173 } | |
2174 } | |
2175 return NULL; | |
2176 } | |
2177 } | |
2178 | |
2179 #ifdef FEAT_RIGHTLEFT | |
1344 | 2180 /* This is just guessing: when 'rightleft' is set, search for a matching |
7 | 2181 * paren/brace in the other direction. */ |
2182 if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL) | |
2183 backwards = !backwards; | |
2184 #endif | |
2185 | |
2186 do_quotes = -1; | |
2187 start_in_quotes = MAYBE; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
2188 CLEAR_POS(&match_pos); |
699 | 2189 |
7 | 2190 /* backward search: Check if this line contains a single-line comment */ |
14 | 2191 if ((backwards && comment_dir) |
2192 #ifdef FEAT_LISP | |
2193 || lisp | |
2194 #endif | |
2195 ) | |
7 | 2196 comment_col = check_linecomment(linep); |
14 | 2197 #ifdef FEAT_LISP |
2198 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) | |
2199 lispcomm = TRUE; /* find match inside this comment */ | |
2200 #endif | |
7 | 2201 while (!got_int) |
2202 { | |
2203 /* | |
2204 * Go to the next position, forward or backward. We could use | |
2205 * inc() and dec() here, but that is much slower | |
2206 */ | |
2207 if (backwards) | |
2208 { | |
14 | 2209 #ifdef FEAT_LISP |
2210 /* char to match is inside of comment, don't search outside */ | |
2211 if (lispcomm && pos.col < (colnr_T)comment_col) | |
2212 break; | |
2213 #endif | |
7 | 2214 if (pos.col == 0) /* at start of line, go to prev. one */ |
2215 { | |
2216 if (pos.lnum == 1) /* start of file */ | |
2217 break; | |
2218 --pos.lnum; | |
2219 | |
829 | 2220 if (maxtravel > 0 && ++traveled > maxtravel) |
7 | 2221 break; |
2222 | |
2223 linep = ml_get(pos.lnum); | |
2224 pos.col = (colnr_T)STRLEN(linep); /* pos.col on trailing NUL */ | |
2225 do_quotes = -1; | |
2226 line_breakcheck(); | |
2227 | |
2228 /* Check if this line contains a single-line comment */ | |
14 | 2229 if (comment_dir |
2230 #ifdef FEAT_LISP | |
2231 || lisp | |
2232 #endif | |
2233 ) | |
7 | 2234 comment_col = check_linecomment(linep); |
14 | 2235 #ifdef FEAT_LISP |
2236 /* skip comment */ | |
2237 if (lisp && comment_col != MAXCOL) | |
2238 pos.col = comment_col; | |
2239 #endif | |
7 | 2240 } |
2241 else | |
2242 { | |
2243 --pos.col; | |
2244 if (has_mbyte) | |
2245 pos.col -= (*mb_head_off)(linep, linep + pos.col); | |
2246 } | |
2247 } | |
2248 else /* forward search */ | |
2249 { | |
14 | 2250 if (linep[pos.col] == NUL |
2251 /* at end of line, go to next one */ | |
2252 #ifdef FEAT_LISP | |
2253 /* don't search for match in comment */ | |
2254 || (lisp && comment_col != MAXCOL | |
2255 && pos.col == (colnr_T)comment_col) | |
2256 #endif | |
2257 ) | |
7 | 2258 { |
14 | 2259 if (pos.lnum == curbuf->b_ml.ml_line_count /* end of file */ |
2260 #ifdef FEAT_LISP | |
2261 /* line is exhausted and comment with it, | |
2262 * don't search for match in code */ | |
2263 || lispcomm | |
2264 #endif | |
2265 ) | |
7 | 2266 break; |
2267 ++pos.lnum; | |
2268 | |
2269 if (maxtravel && traveled++ > maxtravel) | |
2270 break; | |
2271 | |
2272 linep = ml_get(pos.lnum); | |
2273 pos.col = 0; | |
2274 do_quotes = -1; | |
2275 line_breakcheck(); | |
14 | 2276 #ifdef FEAT_LISP |
2277 if (lisp) /* find comment pos in new line */ | |
2278 comment_col = check_linecomment(linep); | |
2279 #endif | |
7 | 2280 } |
2281 else | |
2282 { | |
2283 if (has_mbyte) | |
474 | 2284 pos.col += (*mb_ptr2len)(linep + pos.col); |
7 | 2285 else |
2286 ++pos.col; | |
2287 } | |
2288 } | |
2289 | |
2290 /* | |
2291 * If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0. | |
2292 */ | |
2293 if (pos.col == 0 && (flags & FM_BLOCKSTOP) && | |
2294 (linep[0] == '{' || linep[0] == '}')) | |
2295 { | |
2296 if (linep[0] == findc && count == 0) /* match! */ | |
2297 return &pos; | |
2298 break; /* out of scope */ | |
2299 } | |
2300 | |
2301 if (comment_dir) | |
2302 { | |
2303 /* Note: comments do not nest, and we ignore quotes in them */ | |
2304 /* TODO: ignore comment brackets inside strings */ | |
2305 if (comment_dir == FORWARD) | |
2306 { | |
2307 if (linep[pos.col] == '*' && linep[pos.col + 1] == '/') | |
2308 { | |
2309 pos.col++; | |
2310 return &pos; | |
2311 } | |
2312 } | |
2313 else /* Searching backwards */ | |
2314 { | |
2315 /* | |
2316 * A comment may contain / * or / /, it may also start or end | |
12829
91222b3123ba
patch 8.0.1291: C indent wrong when * immediately follows comment
Christian Brabandt <cb@256bit.org>
parents:
12722
diff
changeset
|
2317 * with / * /. Ignore a / * after / / and after *. |
7 | 2318 */ |
2319 if (pos.col == 0) | |
2320 continue; | |
6971 | 2321 else if (raw_string) |
2322 { | |
2323 if (linep[pos.col - 1] == 'R' | |
2324 && linep[pos.col] == '"' | |
2325 && vim_strchr(linep + pos.col + 1, '(') != NULL) | |
2326 { | |
2327 /* Possible start of raw string. Now that we have the | |
2328 * delimiter we can check if it ends before where we | |
2329 * started searching, or before the previously found | |
2330 * raw string start. */ | |
2331 if (!find_rawstring_end(linep, &pos, | |
2332 count > 0 ? &match_pos : &curwin->w_cursor)) | |
2333 { | |
2334 count++; | |
2335 match_pos = pos; | |
2336 match_pos.col--; | |
2337 } | |
2338 linep = ml_get(pos.lnum); /* may have been released */ | |
2339 } | |
2340 } | |
7 | 2341 else if ( linep[pos.col - 1] == '/' |
2342 && linep[pos.col] == '*' | |
12829
91222b3123ba
patch 8.0.1291: C indent wrong when * immediately follows comment
Christian Brabandt <cb@256bit.org>
parents:
12722
diff
changeset
|
2343 && (pos.col == 1 || linep[pos.col - 2] != '*') |
7 | 2344 && (int)pos.col < comment_col) |
2345 { | |
2346 count++; | |
2347 match_pos = pos; | |
2348 match_pos.col--; | |
2349 } | |
2350 else if (linep[pos.col - 1] == '*' && linep[pos.col] == '/') | |
2351 { | |
2352 if (count > 0) | |
2353 pos = match_pos; | |
2354 else if (pos.col > 1 && linep[pos.col - 2] == '/' | |
2355 && (int)pos.col <= comment_col) | |
2356 pos.col -= 2; | |
2357 else if (ignore_cend) | |
2358 continue; | |
2359 else | |
2360 return NULL; | |
2361 return &pos; | |
2362 } | |
2363 } | |
2364 continue; | |
2365 } | |
2366 | |
2367 /* | |
2368 * If smart matching ('cpoptions' does not contain '%'), braces inside | |
2369 * of quotes are ignored, but only if there is an even number of | |
2370 * quotes in the line. | |
2371 */ | |
2372 if (cpo_match) | |
2373 do_quotes = 0; | |
2374 else if (do_quotes == -1) | |
2375 { | |
2376 /* | |
2377 * Count the number of quotes in the line, skipping \" and '"'. | |
2378 * Watch out for "\\". | |
2379 */ | |
2380 at_start = do_quotes; | |
2381 for (ptr = linep; *ptr; ++ptr) | |
2382 { | |
2383 if (ptr == linep + pos.col + backwards) | |
2384 at_start = (do_quotes & 1); | |
2385 if (*ptr == '"' | |
2386 && (ptr == linep || ptr[-1] != '\'' || ptr[1] != '\'')) | |
2387 ++do_quotes; | |
2388 if (*ptr == '\\' && ptr[1] != NUL) | |
2389 ++ptr; | |
2390 } | |
2391 do_quotes &= 1; /* result is 1 with even number of quotes */ | |
2392 | |
2393 /* | |
2394 * If we find an uneven count, check current line and previous | |
2395 * one for a '\' at the end. | |
2396 */ | |
2397 if (!do_quotes) | |
2398 { | |
2399 inquote = FALSE; | |
2400 if (ptr[-1] == '\\') | |
2401 { | |
2402 do_quotes = 1; | |
2403 if (start_in_quotes == MAYBE) | |
2404 { | |
2405 /* Do we need to use at_start here? */ | |
2406 inquote = TRUE; | |
2407 start_in_quotes = TRUE; | |
2408 } | |
2409 else if (backwards) | |
2410 inquote = TRUE; | |
2411 } | |
2412 if (pos.lnum > 1) | |
2413 { | |
2414 ptr = ml_get(pos.lnum - 1); | |
2415 if (*ptr && *(ptr + STRLEN(ptr) - 1) == '\\') | |
2416 { | |
2417 do_quotes = 1; | |
2418 if (start_in_quotes == MAYBE) | |
2419 { | |
2420 inquote = at_start; | |
2421 if (inquote) | |
2422 start_in_quotes = TRUE; | |
2423 } | |
2424 else if (!backwards) | |
2425 inquote = TRUE; | |
2426 } | |
1310 | 2427 |
2428 /* ml_get() only keeps one line, need to get linep again */ | |
2429 linep = ml_get(pos.lnum); | |
7 | 2430 } |
2431 } | |
2432 } | |
2433 if (start_in_quotes == MAYBE) | |
2434 start_in_quotes = FALSE; | |
2435 | |
2436 /* | |
2437 * If 'smartmatch' is set: | |
2438 * Things inside quotes are ignored by setting 'inquote'. If we | |
2439 * find a quote without a preceding '\' invert 'inquote'. At the | |
2440 * end of a line not ending in '\' we reset 'inquote'. | |
2441 * | |
2442 * In lines with an uneven number of quotes (without preceding '\') | |
2443 * we do not know which part to ignore. Therefore we only set | |
2444 * inquote if the number of quotes in a line is even, unless this | |
2445 * line or the previous one ends in a '\'. Complicated, isn't it? | |
2446 */ | |
4029 | 2447 c = PTR2CHAR(linep + pos.col); |
2448 switch (c) | |
7 | 2449 { |
2450 case NUL: | |
2451 /* at end of line without trailing backslash, reset inquote */ | |
2452 if (pos.col == 0 || linep[pos.col - 1] != '\\') | |
2453 { | |
2454 inquote = FALSE; | |
2455 start_in_quotes = FALSE; | |
2456 } | |
2457 break; | |
2458 | |
2459 case '"': | |
2460 /* a quote that is preceded with an odd number of backslashes is | |
2461 * ignored */ | |
2462 if (do_quotes) | |
2463 { | |
2464 int col; | |
2465 | |
2466 for (col = pos.col - 1; col >= 0; --col) | |
2467 if (linep[col] != '\\') | |
2468 break; | |
2469 if ((((int)pos.col - 1 - col) & 1) == 0) | |
2470 { | |
2471 inquote = !inquote; | |
2472 start_in_quotes = FALSE; | |
2473 } | |
2474 } | |
2475 break; | |
2476 | |
2477 /* | |
2478 * If smart matching ('cpoptions' does not contain '%'): | |
2479 * Skip things in single quotes: 'x' or '\x'. Be careful for single | |
2480 * single quotes, eg jon's. Things like '\233' or '\x3f' are not | |
2481 * skipped, there is never a brace in them. | |
2482 * Ignore this when finding matches for `'. | |
2483 */ | |
2484 case '\'': | |
2485 if (!cpo_match && initc != '\'' && findc != '\'') | |
2486 { | |
2487 if (backwards) | |
2488 { | |
2489 if (pos.col > 1) | |
2490 { | |
2491 if (linep[pos.col - 2] == '\'') | |
2492 { | |
2493 pos.col -= 2; | |
2494 break; | |
2495 } | |
2496 else if (linep[pos.col - 2] == '\\' && | |
2497 pos.col > 2 && linep[pos.col - 3] == '\'') | |
2498 { | |
2499 pos.col -= 3; | |
2500 break; | |
2501 } | |
2502 } | |
2503 } | |
2504 else if (linep[pos.col + 1]) /* forward search */ | |
2505 { | |
2506 if (linep[pos.col + 1] == '\\' && | |
2507 linep[pos.col + 2] && linep[pos.col + 3] == '\'') | |
2508 { | |
2509 pos.col += 3; | |
2510 break; | |
2511 } | |
2512 else if (linep[pos.col + 2] == '\'') | |
2513 { | |
2514 pos.col += 2; | |
2515 break; | |
2516 } | |
2517 } | |
2518 } | |
2519 /* FALLTHROUGH */ | |
2520 | |
2521 default: | |
2522 #ifdef FEAT_LISP | |
14 | 2523 /* |
2524 * For Lisp skip over backslashed (), {} and []. | |
2525 * (actually, we skip #\( et al) | |
2526 */ | |
7 | 2527 if (curbuf->b_p_lisp |
2528 && vim_strchr((char_u *)"(){}[]", c) != NULL | |
14 | 2529 && pos.col > 1 |
2530 && check_prevcol(linep, pos.col, '\\', NULL) | |
2531 && check_prevcol(linep, pos.col - 1, '#', NULL)) | |
7 | 2532 break; |
2533 #endif | |
2534 | |
2535 /* Check for match outside of quotes, and inside of | |
2536 * quotes when the start is also inside of quotes. */ | |
2537 if ((!inquote || start_in_quotes == TRUE) | |
2538 && (c == initc || c == findc)) | |
2539 { | |
2540 int col, bslcnt = 0; | |
2541 | |
2542 if (!cpo_bsl) | |
2543 { | |
2544 for (col = pos.col; check_prevcol(linep, col, '\\', &col);) | |
2545 bslcnt++; | |
2546 } | |
1859 | 2547 /* Only accept a match when 'M' is in 'cpo' or when escaping |
2548 * is what we expect. */ | |
7 | 2549 if (cpo_bsl || (bslcnt & 1) == match_escaped) |
2550 { | |
2551 if (c == initc) | |
2552 count++; | |
2553 else | |
2554 { | |
2555 if (count == 0) | |
2556 return &pos; | |
2557 count--; | |
2558 } | |
2559 } | |
2560 } | |
2561 } | |
2562 } | |
2563 | |
2564 if (comment_dir == BACKWARD && count > 0) | |
2565 { | |
2566 pos = match_pos; | |
2567 return &pos; | |
2568 } | |
2569 return (pos_T *)NULL; /* never found it */ | |
2570 } | |
2571 | |
2572 /* | |
2573 * Check if line[] contains a / / comment. | |
2574 * Return MAXCOL if not, otherwise return the column. | |
2575 * TODO: skip strings. | |
2576 */ | |
2577 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2578 check_linecomment(char_u *line) |
7 | 2579 { |
2580 char_u *p; | |
2581 | |
2582 p = line; | |
14 | 2583 #ifdef FEAT_LISP |
2584 /* skip Lispish one-line comments */ | |
2585 if (curbuf->b_p_lisp) | |
2586 { | |
2587 if (vim_strchr(p, ';') != NULL) /* there may be comments */ | |
2588 { | |
3263 | 2589 int in_str = FALSE; /* inside of string */ |
14 | 2590 |
2591 p = line; /* scan from start */ | |
333 | 2592 while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL) |
14 | 2593 { |
2594 if (*p == '"') | |
2595 { | |
3263 | 2596 if (in_str) |
14 | 2597 { |
2598 if (*(p - 1) != '\\') /* skip escaped quote */ | |
3263 | 2599 in_str = FALSE; |
14 | 2600 } |
2601 else if (p == line || ((p - line) >= 2 | |
2602 /* skip #\" form */ | |
2603 && *(p - 1) != '\\' && *(p - 2) != '#')) | |
3263 | 2604 in_str = TRUE; |
14 | 2605 } |
3263 | 2606 else if (!in_str && ((p - line) < 2 |
14 | 2607 || (*(p - 1) != '\\' && *(p - 2) != '#'))) |
2608 break; /* found! */ | |
2609 ++p; | |
2610 } | |
2611 } | |
2612 else | |
2613 p = NULL; | |
2614 } | |
2615 else | |
2616 #endif | |
7 | 2617 while ((p = vim_strchr(p, '/')) != NULL) |
2618 { | |
1463 | 2619 /* accept a double /, unless it's preceded with * and followed by *, |
2620 * because * / / * is an end and start of a C comment */ | |
2621 if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*')) | |
7 | 2622 break; |
2623 ++p; | |
2624 } | |
2625 | |
2626 if (p == NULL) | |
2627 return MAXCOL; | |
2628 return (int)(p - line); | |
2629 } | |
2630 | |
2631 /* | |
2632 * Move cursor briefly to character matching the one under the cursor. | |
2633 * Used for Insert mode and "r" command. | |
2634 * Show the match only if it is visible on the screen. | |
2635 * If there isn't a match, then beep. | |
2636 */ | |
2637 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2638 showmatch( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2639 int c) /* char to show match for */ |
7 | 2640 { |
2641 pos_T *lpos, save_cursor; | |
2642 pos_T mpos; | |
2643 colnr_T vcol; | |
2644 long save_so; | |
2645 long save_siso; | |
2646 #ifdef CURSOR_SHAPE | |
2647 int save_state; | |
2648 #endif | |
2649 colnr_T save_dollar_vcol; | |
2650 char_u *p; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2651 long *so = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2652 long *siso = curwin->w_p_siso >= 0 ? &curwin->w_p_siso : &p_siso; |
7 | 2653 |
2654 /* | |
2655 * Only show match for chars in the 'matchpairs' option. | |
2656 */ | |
2657 /* 'matchpairs' is "x:y,x:y" */ | |
4029 | 2658 for (p = curbuf->b_p_mps; *p != NUL; ++p) |
7 | 2659 { |
2660 #ifdef FEAT_RIGHTLEFT | |
4153 | 2661 if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri)) |
2662 break; | |
7 | 2663 #endif |
4029 | 2664 p += MB_PTR2LEN(p) + 1; |
2665 if (PTR2CHAR(p) == c | |
7 | 2666 #ifdef FEAT_RIGHTLEFT |
2667 && !(curwin->w_p_rl ^ p_ri) | |
2668 #endif | |
2669 ) | |
2670 break; | |
4029 | 2671 p += MB_PTR2LEN(p); |
2672 if (*p == NUL) | |
7 | 2673 return; |
2674 } | |
2675 | |
2676 if ((lpos = findmatch(NULL, NUL)) == NULL) /* no match, so beep */ | |
6949 | 2677 vim_beep(BO_MATCH); |
4153 | 2678 else if (lpos->lnum >= curwin->w_topline && lpos->lnum < curwin->w_botline) |
7 | 2679 { |
2680 if (!curwin->w_p_wrap) | |
2681 getvcol(curwin, lpos, NULL, &vcol, NULL); | |
2682 if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2683 && vcol < curwin->w_leftcol + curwin->w_width)) |
7 | 2684 { |
2685 mpos = *lpos; /* save the pos, update_screen() may change it */ | |
2686 save_cursor = curwin->w_cursor; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2687 save_so = *so; |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2688 save_siso = *siso; |
7 | 2689 /* Handle "$" in 'cpo': If the ')' is typed on top of the "$", |
2690 * stop displaying the "$". */ | |
3318 | 2691 if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol) |
2692 dollar_vcol = -1; | |
7 | 2693 ++curwin->w_virtcol; /* do display ')' just before "$" */ |
2694 update_screen(VALID); /* show the new char first */ | |
2695 | |
2696 save_dollar_vcol = dollar_vcol; | |
2697 #ifdef CURSOR_SHAPE | |
2698 save_state = State; | |
2699 State = SHOWMATCH; | |
2700 ui_cursor_shape(); /* may show different cursor shape */ | |
2701 #endif | |
2702 curwin->w_cursor = mpos; /* move to matching char */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2703 *so = 0; /* don't use 'scrolloff' here */ |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2704 *siso = 0; /* don't use 'sidescrolloff' here */ |
7 | 2705 showruler(FALSE); |
2706 setcursor(); | |
2707 cursor_on(); /* make sure that the cursor is shown */ | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2708 out_flush_cursor(TRUE, FALSE); |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2709 |
7 | 2710 /* Restore dollar_vcol(), because setcursor() may call curs_rows() |
2711 * which resets it if the matching position is in a previous line | |
2712 * and has a higher column number. */ | |
2713 dollar_vcol = save_dollar_vcol; | |
2714 | |
2715 /* | |
2716 * brief pause, unless 'm' is present in 'cpo' and a character is | |
2717 * available. | |
2718 */ | |
2719 if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) | |
2720 ui_delay(p_mat * 100L, TRUE); | |
2721 else if (!char_avail()) | |
2722 ui_delay(p_mat * 100L, FALSE); | |
2723 curwin->w_cursor = save_cursor; /* restore cursor position */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2724 *so = save_so; |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2725 *siso = save_siso; |
7 | 2726 #ifdef CURSOR_SHAPE |
2727 State = save_state; | |
2728 ui_cursor_shape(); /* may show different cursor shape */ | |
2729 #endif | |
2730 } | |
2731 } | |
2732 } | |
2733 | |
2734 /* | |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2735 * Find the start of the next sentence, searching in the direction specified |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2736 * by the "dir" argument. The cursor is positioned on the start of the next |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2737 * sentence when found. If the next sentence is found, return OK. Return FAIL |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2738 * otherwise. See ":h sentence" for the precise definition of a "sentence" |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2739 * text object. |
7 | 2740 */ |
2741 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2742 findsent(int dir, long count) |
7 | 2743 { |
2744 pos_T pos, tpos; | |
2745 int c; | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7358
diff
changeset
|
2746 int (*func)(pos_T *); |
7 | 2747 int startlnum; |
2748 int noskip = FALSE; /* do not skip blanks */ | |
2749 int cpo_J; | |
45 | 2750 int found_dot; |
7 | 2751 |
2752 pos = curwin->w_cursor; | |
2753 if (dir == FORWARD) | |
2754 func = incl; | |
2755 else | |
2756 func = decl; | |
2757 | |
2758 while (count--) | |
2759 { | |
2760 /* | |
2761 * if on an empty line, skip upto a non-empty line | |
2762 */ | |
2763 if (gchar_pos(&pos) == NUL) | |
2764 { | |
2765 do | |
2766 if ((*func)(&pos) == -1) | |
2767 break; | |
2768 while (gchar_pos(&pos) == NUL); | |
2769 if (dir == FORWARD) | |
2770 goto found; | |
2771 } | |
2772 /* | |
2773 * if on the start of a paragraph or a section and searching forward, | |
2774 * go to the next line | |
2775 */ | |
2776 else if (dir == FORWARD && pos.col == 0 && | |
2777 startPS(pos.lnum, NUL, FALSE)) | |
2778 { | |
2779 if (pos.lnum == curbuf->b_ml.ml_line_count) | |
2780 return FAIL; | |
2781 ++pos.lnum; | |
2782 goto found; | |
2783 } | |
2784 else if (dir == BACKWARD) | |
2785 decl(&pos); | |
2786 | |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2787 // go back to the previous non-white non-punctuation character |
45 | 2788 found_dot = FALSE; |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2789 while (c = gchar_pos(&pos), VIM_ISWHITE(c) |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2790 || vim_strchr((char_u *)".!?)]\"'", c) != NULL) |
7 | 2791 { |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2792 tpos = pos; |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2793 if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD)) |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2794 break; |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2795 |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2796 if (found_dot) |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2797 break; |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2798 if (vim_strchr((char_u *) ".!?", c) != NULL) |
45 | 2799 found_dot = TRUE; |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2800 |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2801 if (vim_strchr((char_u *) ")]\"'", c) != NULL |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2802 && vim_strchr((char_u *) ".!?)]\"'", gchar_pos(&tpos)) == NULL) |
7 | 2803 break; |
14131
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2804 |
ec85acd49b8e
patch 8.1.0083: "is" and "as" have trouble with quoted punctuation
Christian Brabandt <cb@256bit.org>
parents:
14000
diff
changeset
|
2805 decl(&pos); |
7 | 2806 } |
2807 | |
2808 /* remember the line where the search started */ | |
2809 startlnum = pos.lnum; | |
2810 cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL; | |
2811 | |
2812 for (;;) /* find end of sentence */ | |
2813 { | |
2814 c = gchar_pos(&pos); | |
2815 if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE))) | |
2816 { | |
2817 if (dir == BACKWARD && pos.lnum != startlnum) | |
2818 ++pos.lnum; | |
2819 break; | |
2820 } | |
2821 if (c == '.' || c == '!' || c == '?') | |
2822 { | |
2823 tpos = pos; | |
2824 do | |
2825 if ((c = inc(&tpos)) == -1) | |
2826 break; | |
2827 while (vim_strchr((char_u *)")]\"'", c = gchar_pos(&tpos)) | |
2828 != NULL); | |
2829 if (c == -1 || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL | |
2830 || (cpo_J && (c == ' ' && inc(&tpos) >= 0 | |
2831 && gchar_pos(&tpos) == ' '))) | |
2832 { | |
2833 pos = tpos; | |
2834 if (gchar_pos(&pos) == NUL) /* skip NUL at EOL */ | |
2835 inc(&pos); | |
2836 break; | |
2837 } | |
2838 } | |
2839 if ((*func)(&pos) == -1) | |
2840 { | |
2841 if (count) | |
2842 return FAIL; | |
2843 noskip = TRUE; | |
2844 break; | |
2845 } | |
2846 } | |
2847 found: | |
2848 /* skip white space */ | |
2849 while (!noskip && ((c = gchar_pos(&pos)) == ' ' || c == '\t')) | |
2850 if (incl(&pos) == -1) | |
2851 break; | |
2852 } | |
2853 | |
2854 setpcmark(); | |
2855 curwin->w_cursor = pos; | |
2856 return OK; | |
2857 } | |
2858 | |
2859 /* | |
164 | 2860 * Find the next paragraph or section in direction 'dir'. |
7 | 2861 * Paragraphs are currently supposed to be separated by empty lines. |
164 | 2862 * If 'what' is NUL we go to the next paragraph. |
7 | 2863 * If 'what' is '{' or '}' we go to the next section. |
2864 * If 'both' is TRUE also stop at '}'. | |
164 | 2865 * Return TRUE if the next paragraph or section was found. |
7 | 2866 */ |
2867 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2868 findpar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2869 int *pincl, /* Return: TRUE if last char is to be included */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2870 int dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2871 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2872 int what, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2873 int both) |
7 | 2874 { |
2875 linenr_T curr; | |
2876 int did_skip; /* TRUE after separating lines have been skipped */ | |
2877 int first; /* TRUE on first line */ | |
164 | 2878 int posix = (vim_strchr(p_cpo, CPO_PARA) != NULL); |
7 | 2879 #ifdef FEAT_FOLDING |
2880 linenr_T fold_first; /* first line of a closed fold */ | |
2881 linenr_T fold_last; /* last line of a closed fold */ | |
2882 int fold_skipped; /* TRUE if a closed fold was skipped this | |
2883 iteration */ | |
2884 #endif | |
2885 | |
2886 curr = curwin->w_cursor.lnum; | |
2887 | |
2888 while (count--) | |
2889 { | |
2890 did_skip = FALSE; | |
2891 for (first = TRUE; ; first = FALSE) | |
2892 { | |
2893 if (*ml_get(curr) != NUL) | |
2894 did_skip = TRUE; | |
2895 | |
2896 #ifdef FEAT_FOLDING | |
2897 /* skip folded lines */ | |
2898 fold_skipped = FALSE; | |
2899 if (first && hasFolding(curr, &fold_first, &fold_last)) | |
2900 { | |
2901 curr = ((dir > 0) ? fold_last : fold_first) + dir; | |
2902 fold_skipped = TRUE; | |
2903 } | |
2904 #endif | |
2905 | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2906 /* POSIX has its own ideas of what a paragraph boundary is and it |
164 | 2907 * doesn't match historical Vi: It also stops at a "{" in the |
2908 * first column and at an empty line. */ | |
2909 if (!first && did_skip && (startPS(curr, what, both) | |
2910 || (posix && what == NUL && *ml_get(curr) == '{'))) | |
7 | 2911 break; |
2912 | |
2913 #ifdef FEAT_FOLDING | |
2914 if (fold_skipped) | |
2915 curr -= dir; | |
2916 #endif | |
2917 if ((curr += dir) < 1 || curr > curbuf->b_ml.ml_line_count) | |
2918 { | |
2919 if (count) | |
2920 return FALSE; | |
2921 curr -= dir; | |
2922 break; | |
2923 } | |
2924 } | |
2925 } | |
2926 setpcmark(); | |
2927 if (both && *ml_get(curr) == '}') /* include line with '}' */ | |
2928 ++curr; | |
2929 curwin->w_cursor.lnum = curr; | |
2930 if (curr == curbuf->b_ml.ml_line_count && what != '}') | |
2931 { | |
11275
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2932 char_u *line = ml_get(curr); |
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2933 |
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2934 /* Put the cursor on the last character in the last line and make the |
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2935 * motion inclusive. */ |
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2936 if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) |
7 | 2937 { |
2938 --curwin->w_cursor.col; | |
11275
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2939 curwin->w_cursor.col -= |
5c77ca0cf6a5
patch 8.0.0523: dv} deletes part of a multi-byte character.
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2940 (*mb_head_off)(line, line + curwin->w_cursor.col); |
504 | 2941 *pincl = TRUE; |
7 | 2942 } |
2943 } | |
2944 else | |
2945 curwin->w_cursor.col = 0; | |
2946 return TRUE; | |
2947 } | |
2948 | |
2949 /* | |
2950 * check if the string 's' is a nroff macro that is in option 'opt' | |
2951 */ | |
2952 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2953 inmacro(char_u *opt, char_u *s) |
7 | 2954 { |
2955 char_u *macro; | |
2956 | |
2957 for (macro = opt; macro[0]; ++macro) | |
2958 { | |
2959 /* Accept two characters in the option being equal to two characters | |
2960 * in the line. A space in the option matches with a space in the | |
2961 * line or the line having ended. */ | |
2962 if ( (macro[0] == s[0] | |
2963 || (macro[0] == ' ' | |
2964 && (s[0] == NUL || s[0] == ' '))) | |
2965 && (macro[1] == s[1] | |
2966 || ((macro[1] == NUL || macro[1] == ' ') | |
2967 && (s[0] == NUL || s[1] == NUL || s[1] == ' ')))) | |
2968 break; | |
2969 ++macro; | |
2970 if (macro[0] == NUL) | |
2971 break; | |
2972 } | |
2973 return (macro[0] != NUL); | |
2974 } | |
2975 | |
2976 /* | |
2977 * startPS: return TRUE if line 'lnum' is the start of a section or paragraph. | |
2978 * If 'para' is '{' or '}' only check for sections. | |
2979 * If 'both' is TRUE also stop at '}' | |
2980 */ | |
2981 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2982 startPS(linenr_T lnum, int para, int both) |
7 | 2983 { |
2984 char_u *s; | |
2985 | |
2986 s = ml_get(lnum); | |
2987 if (*s == para || *s == '\f' || (both && *s == '}')) | |
2988 return TRUE; | |
2989 if (*s == '.' && (inmacro(p_sections, s + 1) || | |
2990 (!para && inmacro(p_para, s + 1)))) | |
2991 return TRUE; | |
2992 return FALSE; | |
2993 } | |
2994 | |
2995 /* | |
2996 * The following routines do the word searches performed by the 'w', 'W', | |
2997 * 'b', 'B', 'e', and 'E' commands. | |
2998 */ | |
2999 | |
3000 /* | |
3001 * To perform these searches, characters are placed into one of three | |
3002 * classes, and transitions between classes determine word boundaries. | |
3003 * | |
3004 * The classes are: | |
3005 * | |
3006 * 0 - white space | |
3007 * 1 - punctuation | |
3008 * 2 or higher - keyword characters (letters, digits and underscore) | |
3009 */ | |
3010 | |
3011 static int cls_bigword; /* TRUE for "W", "B" or "E" */ | |
3012 | |
3013 /* | |
3014 * cls() - returns the class of character at curwin->w_cursor | |
3015 * | |
3016 * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars | |
3017 * from class 2 and higher are reported as class 1 since only white space | |
3018 * boundaries are of interest. | |
3019 */ | |
3020 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3021 cls(void) |
7 | 3022 { |
3023 int c; | |
3024 | |
3025 c = gchar_cursor(); | |
3026 if (c == ' ' || c == '\t' || c == NUL) | |
3027 return 0; | |
3028 if (enc_dbcs != 0 && c > 0xFF) | |
3029 { | |
3030 /* If cls_bigword, report multi-byte chars as class 1. */ | |
3031 if (enc_dbcs == DBCS_KOR && cls_bigword) | |
3032 return 1; | |
3033 | |
3034 /* process code leading/trailing bytes */ | |
3035 return dbcs_class(((unsigned)c >> 8), (c & 0xFF)); | |
3036 } | |
3037 if (enc_utf8) | |
3038 { | |
3039 c = utf_class(c); | |
3040 if (c != 0 && cls_bigword) | |
3041 return 1; | |
3042 return c; | |
3043 } | |
3044 | |
3045 /* If cls_bigword is TRUE, report all non-blanks as class 1. */ | |
3046 if (cls_bigword) | |
3047 return 1; | |
3048 | |
3049 if (vim_iswordc(c)) | |
3050 return 2; | |
3051 return 1; | |
3052 } | |
3053 | |
3054 | |
3055 /* | |
3056 * fwd_word(count, type, eol) - move forward one word | |
3057 * | |
3058 * Returns FAIL if the cursor was already at the end of the file. | |
3059 * If eol is TRUE, last word stops at end of line (for operators). | |
3060 */ | |
3061 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3062 fwd_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3063 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3064 int bigword, /* "W", "E" or "B" */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3065 int eol) |
7 | 3066 { |
3067 int sclass; /* starting class */ | |
3068 int i; | |
3069 int last_line; | |
3070 | |
3071 curwin->w_cursor.coladd = 0; | |
3072 cls_bigword = bigword; | |
3073 while (--count >= 0) | |
3074 { | |
3075 #ifdef FEAT_FOLDING | |
3076 /* When inside a range of folded lines, move to the last char of the | |
3077 * last line. */ | |
3078 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) | |
3079 coladvance((colnr_T)MAXCOL); | |
3080 #endif | |
3081 sclass = cls(); | |
3082 | |
3083 /* | |
3084 * We always move at least one character, unless on the last | |
3085 * character in the buffer. | |
3086 */ | |
3087 last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); | |
3088 i = inc_cursor(); | |
3089 if (i == -1 || (i >= 1 && last_line)) /* started at last char in file */ | |
3090 return FAIL; | |
1309 | 3091 if (i >= 1 && eol && count == 0) /* started at last char in line */ |
7 | 3092 return OK; |
3093 | |
3094 /* | |
3095 * Go one char past end of current word (if any) | |
3096 */ | |
3097 if (sclass != 0) | |
3098 while (cls() == sclass) | |
3099 { | |
3100 i = inc_cursor(); | |
3101 if (i == -1 || (i >= 1 && eol && count == 0)) | |
3102 return OK; | |
3103 } | |
3104 | |
3105 /* | |
3106 * go to next non-white | |
3107 */ | |
3108 while (cls() == 0) | |
3109 { | |
3110 /* | |
3111 * We'll stop if we land on a blank line | |
3112 */ | |
3113 if (curwin->w_cursor.col == 0 && *ml_get_curline() == NUL) | |
3114 break; | |
3115 | |
3116 i = inc_cursor(); | |
3117 if (i == -1 || (i >= 1 && eol && count == 0)) | |
3118 return OK; | |
3119 } | |
3120 } | |
3121 return OK; | |
3122 } | |
3123 | |
3124 /* | |
3125 * bck_word() - move backward 'count' words | |
3126 * | |
3127 * If stop is TRUE and we are already on the start of a word, move one less. | |
3128 * | |
3129 * Returns FAIL if top of the file was reached. | |
3130 */ | |
3131 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3132 bck_word(long count, int bigword, int stop) |
7 | 3133 { |
3134 int sclass; /* starting class */ | |
3135 | |
3136 curwin->w_cursor.coladd = 0; | |
3137 cls_bigword = bigword; | |
3138 while (--count >= 0) | |
3139 { | |
3140 #ifdef FEAT_FOLDING | |
3141 /* When inside a range of folded lines, move to the first char of the | |
3142 * first line. */ | |
3143 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL)) | |
3144 curwin->w_cursor.col = 0; | |
3145 #endif | |
3146 sclass = cls(); | |
3147 if (dec_cursor() == -1) /* started at start of file */ | |
3148 return FAIL; | |
3149 | |
3150 if (!stop || sclass == cls() || sclass == 0) | |
3151 { | |
3152 /* | |
3153 * Skip white space before the word. | |
3154 * Stop on an empty line. | |
3155 */ | |
3156 while (cls() == 0) | |
3157 { | |
3158 if (curwin->w_cursor.col == 0 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3159 && LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 3160 goto finished; |
3161 if (dec_cursor() == -1) /* hit start of file, stop here */ | |
3162 return OK; | |
3163 } | |
3164 | |
3165 /* | |
3166 * Move backward to start of this word. | |
3167 */ | |
3168 if (skip_chars(cls(), BACKWARD)) | |
3169 return OK; | |
3170 } | |
3171 | |
3172 inc_cursor(); /* overshot - forward one */ | |
3173 finished: | |
3174 stop = FALSE; | |
3175 } | |
3176 return OK; | |
3177 } | |
3178 | |
3179 /* | |
3180 * end_word() - move to the end of the word | |
3181 * | |
3182 * There is an apparent bug in the 'e' motion of the real vi. At least on the | |
3183 * System V Release 3 version for the 80386. Unlike 'b' and 'w', the 'e' | |
3184 * motion crosses blank lines. When the real vi crosses a blank line in an | |
3185 * 'e' motion, the cursor is placed on the FIRST character of the next | |
3186 * non-blank line. The 'E' command, however, works correctly. Since this | |
3187 * appears to be a bug, I have not duplicated it here. | |
3188 * | |
3189 * Returns FAIL if end of the file was reached. | |
3190 * | |
3191 * If stop is TRUE and we are already on the end of a word, move one less. | |
3192 * If empty is TRUE stop on an empty line. | |
3193 */ | |
3194 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3195 end_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3196 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3197 int bigword, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3198 int stop, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3199 int empty) |
7 | 3200 { |
3201 int sclass; /* starting class */ | |
3202 | |
3203 curwin->w_cursor.coladd = 0; | |
3204 cls_bigword = bigword; | |
3205 while (--count >= 0) | |
3206 { | |
3207 #ifdef FEAT_FOLDING | |
3208 /* When inside a range of folded lines, move to the last char of the | |
3209 * last line. */ | |
3210 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) | |
3211 coladvance((colnr_T)MAXCOL); | |
3212 #endif | |
3213 sclass = cls(); | |
3214 if (inc_cursor() == -1) | |
3215 return FAIL; | |
3216 | |
3217 /* | |
3218 * If we're in the middle of a word, we just have to move to the end | |
3219 * of it. | |
3220 */ | |
3221 if (cls() == sclass && sclass != 0) | |
3222 { | |
3223 /* | |
3224 * Move forward to end of the current word | |
3225 */ | |
3226 if (skip_chars(sclass, FORWARD)) | |
3227 return FAIL; | |
3228 } | |
3229 else if (!stop || sclass == 0) | |
3230 { | |
3231 /* | |
3232 * We were at the end of a word. Go to the end of the next word. | |
3233 * First skip white space, if 'empty' is TRUE, stop at empty line. | |
3234 */ | |
3235 while (cls() == 0) | |
3236 { | |
3237 if (empty && curwin->w_cursor.col == 0 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3238 && LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 3239 goto finished; |
3240 if (inc_cursor() == -1) /* hit end of file, stop here */ | |
3241 return FAIL; | |
3242 } | |
3243 | |
3244 /* | |
3245 * Move forward to the end of this word. | |
3246 */ | |
3247 if (skip_chars(cls(), FORWARD)) | |
3248 return FAIL; | |
3249 } | |
3250 dec_cursor(); /* overshot - one char backward */ | |
3251 finished: | |
3252 stop = FALSE; /* we move only one word less */ | |
3253 } | |
3254 return OK; | |
3255 } | |
3256 | |
3257 /* | |
3258 * Move back to the end of the word. | |
3259 * | |
3260 * Returns FAIL if start of the file was reached. | |
3261 */ | |
3262 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3263 bckend_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3264 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3265 int bigword, /* TRUE for "B" */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3266 int eol) /* TRUE: stop at end of line. */ |
7 | 3267 { |
3268 int sclass; /* starting class */ | |
3269 int i; | |
3270 | |
3271 curwin->w_cursor.coladd = 0; | |
3272 cls_bigword = bigword; | |
3273 while (--count >= 0) | |
3274 { | |
3275 sclass = cls(); | |
3276 if ((i = dec_cursor()) == -1) | |
3277 return FAIL; | |
3278 if (eol && i == 1) | |
3279 return OK; | |
3280 | |
3281 /* | |
3282 * Move backward to before the start of this word. | |
3283 */ | |
3284 if (sclass != 0) | |
3285 { | |
3286 while (cls() == sclass) | |
3287 if ((i = dec_cursor()) == -1 || (eol && i == 1)) | |
3288 return OK; | |
3289 } | |
3290 | |
3291 /* | |
3292 * Move backward to end of the previous word | |
3293 */ | |
3294 while (cls() == 0) | |
3295 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3296 if (curwin->w_cursor.col == 0 && LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 3297 break; |
3298 if ((i = dec_cursor()) == -1 || (eol && i == 1)) | |
3299 return OK; | |
3300 } | |
3301 } | |
3302 return OK; | |
3303 } | |
3304 | |
3305 /* | |
3306 * Skip a row of characters of the same class. | |
3307 * Return TRUE when end-of-file reached, FALSE otherwise. | |
3308 */ | |
3309 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3310 skip_chars(int cclass, int dir) |
7 | 3311 { |
3312 while (cls() == cclass) | |
3313 if ((dir == FORWARD ? inc_cursor() : dec_cursor()) == -1) | |
3314 return TRUE; | |
3315 return FALSE; | |
3316 } | |
3317 | |
3318 #ifdef FEAT_TEXTOBJ | |
3319 /* | |
3320 * Go back to the start of the word or the start of white space | |
3321 */ | |
3322 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3323 back_in_line(void) |
7 | 3324 { |
3325 int sclass; /* starting class */ | |
3326 | |
3327 sclass = cls(); | |
3328 for (;;) | |
3329 { | |
3330 if (curwin->w_cursor.col == 0) /* stop at start of line */ | |
3331 break; | |
3332 dec_cursor(); | |
3333 if (cls() != sclass) /* stop at start of word */ | |
3334 { | |
3335 inc_cursor(); | |
3336 break; | |
3337 } | |
3338 } | |
3339 } | |
3340 | |
3341 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3342 find_first_blank(pos_T *posp) |
7 | 3343 { |
3344 int c; | |
3345 | |
3346 while (decl(posp) != -1) | |
3347 { | |
3348 c = gchar_pos(posp); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3349 if (!VIM_ISWHITE(c)) |
7 | 3350 { |
3351 incl(posp); | |
3352 break; | |
3353 } | |
3354 } | |
3355 } | |
3356 | |
3357 /* | |
3358 * Skip count/2 sentences and count/2 separating white spaces. | |
3359 */ | |
3360 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3361 findsent_forward( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3362 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3363 int at_start_sent) /* cursor is at start of sentence */ |
7 | 3364 { |
3365 while (count--) | |
3366 { | |
3367 findsent(FORWARD, 1L); | |
3368 if (at_start_sent) | |
3369 find_first_blank(&curwin->w_cursor); | |
3370 if (count == 0 || at_start_sent) | |
3371 decl(&curwin->w_cursor); | |
3372 at_start_sent = !at_start_sent; | |
3373 } | |
3374 } | |
3375 | |
3376 /* | |
3377 * Find word under cursor, cursor at end. | |
3378 * Used while an operator is pending, and in Visual mode. | |
3379 */ | |
3380 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3381 current_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3382 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3383 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3384 int include, /* TRUE: include word and white space */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3385 int bigword) /* FALSE == word, TRUE == WORD */ |
7 | 3386 { |
3387 pos_T start_pos; | |
3388 pos_T pos; | |
3389 int inclusive = TRUE; | |
3390 int include_white = FALSE; | |
3391 | |
3392 cls_bigword = bigword; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3393 CLEAR_POS(&start_pos); |
7 | 3394 |
3395 /* Correct cursor when 'selection' is exclusive */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3396 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) |
7 | 3397 dec_cursor(); |
3398 | |
3399 /* | |
3400 * When Visual mode is not active, or when the VIsual area is only one | |
3401 * character, select the word and/or white space under the cursor. | |
3402 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3403 if (!VIsual_active || EQUAL_POS(curwin->w_cursor, VIsual)) |
7 | 3404 { |
3405 /* | |
3406 * Go to start of current word or white space. | |
3407 */ | |
3408 back_in_line(); | |
3409 start_pos = curwin->w_cursor; | |
3410 | |
3411 /* | |
3412 * If the start is on white space, and white space should be included | |
3413 * (" word"), or start is not on white space, and white space should | |
3414 * not be included ("word"), find end of word. | |
3415 */ | |
3416 if ((cls() == 0) == include) | |
3417 { | |
3418 if (end_word(1L, bigword, TRUE, TRUE) == FAIL) | |
3419 return FAIL; | |
3420 } | |
3421 else | |
3422 { | |
3423 /* | |
3424 * If the start is not on white space, and white space should be | |
3425 * included ("word "), or start is on white space and white | |
3426 * space should not be included (" "), find start of word. | |
3427 * If we end up in the first column of the next line (single char | |
3428 * word) back up to end of the line. | |
3429 */ | |
3430 fwd_word(1L, bigword, TRUE); | |
3431 if (curwin->w_cursor.col == 0) | |
3432 decl(&curwin->w_cursor); | |
3433 else | |
3434 oneleft(); | |
3435 | |
3436 if (include) | |
3437 include_white = TRUE; | |
3438 } | |
3439 | |
3440 if (VIsual_active) | |
3441 { | |
3442 /* should do something when inclusive == FALSE ! */ | |
3443 VIsual = start_pos; | |
3444 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3445 } | |
3446 else | |
3447 { | |
3448 oap->start = start_pos; | |
3449 oap->motion_type = MCHAR; | |
3450 } | |
3451 --count; | |
3452 } | |
3453 | |
3454 /* | |
3455 * When count is still > 0, extend with more objects. | |
3456 */ | |
3457 while (count > 0) | |
3458 { | |
3459 inclusive = TRUE; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3460 if (VIsual_active && LT_POS(curwin->w_cursor, VIsual)) |
7 | 3461 { |
3462 /* | |
3463 * In Visual mode, with cursor at start: move cursor back. | |
3464 */ | |
3465 if (decl(&curwin->w_cursor) == -1) | |
3466 return FAIL; | |
3467 if (include != (cls() != 0)) | |
3468 { | |
3469 if (bck_word(1L, bigword, TRUE) == FAIL) | |
3470 return FAIL; | |
3471 } | |
3472 else | |
3473 { | |
3474 if (bckend_word(1L, bigword, TRUE) == FAIL) | |
3475 return FAIL; | |
3476 (void)incl(&curwin->w_cursor); | |
3477 } | |
3478 } | |
3479 else | |
3480 { | |
3481 /* | |
3482 * Move cursor forward one word and/or white area. | |
3483 */ | |
3484 if (incl(&curwin->w_cursor) == -1) | |
3485 return FAIL; | |
3486 if (include != (cls() == 0)) | |
3487 { | |
96 | 3488 if (fwd_word(1L, bigword, TRUE) == FAIL && count > 1) |
7 | 3489 return FAIL; |
3490 /* | |
3491 * If end is just past a new-line, we don't want to include | |
96 | 3492 * the first character on the line. |
3493 * Put cursor on last char of white. | |
7 | 3494 */ |
96 | 3495 if (oneleft() == FAIL) |
7 | 3496 inclusive = FALSE; |
3497 } | |
3498 else | |
3499 { | |
3500 if (end_word(1L, bigword, TRUE, TRUE) == FAIL) | |
3501 return FAIL; | |
3502 } | |
3503 } | |
3504 --count; | |
3505 } | |
3506 | |
9 | 3507 if (include_white && (cls() != 0 |
3508 || (curwin->w_cursor.col == 0 && !inclusive))) | |
7 | 3509 { |
3510 /* | |
3511 * If we don't include white space at the end, move the start | |
3512 * to include some white space there. This makes "daw" work | |
3513 * better on the last word in a sentence (and "2daw" on last-but-one | |
9 | 3514 * word). Also when "2daw" deletes "word." at the end of the line |
3515 * (cursor is at start of next line). | |
3516 * But don't delete white space at start of line (indent). | |
7 | 3517 */ |
3518 pos = curwin->w_cursor; /* save cursor position */ | |
3519 curwin->w_cursor = start_pos; | |
3520 if (oneleft() == OK) | |
3521 { | |
3522 back_in_line(); | |
3523 if (cls() == 0 && curwin->w_cursor.col > 0) | |
3524 { | |
3525 if (VIsual_active) | |
3526 VIsual = curwin->w_cursor; | |
3527 else | |
3528 oap->start = curwin->w_cursor; | |
3529 } | |
3530 } | |
3531 curwin->w_cursor = pos; /* put cursor back at end */ | |
3532 } | |
3533 | |
3534 if (VIsual_active) | |
3535 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3536 if (*p_sel == 'e' && inclusive && LTOREQ_POS(VIsual, curwin->w_cursor)) |
7 | 3537 inc_cursor(); |
3538 if (VIsual_mode == 'V') | |
3539 { | |
3540 VIsual_mode = 'v'; | |
3541 redraw_cmdline = TRUE; /* show mode later */ | |
3542 } | |
3543 } | |
3544 else | |
3545 oap->inclusive = inclusive; | |
3546 | |
3547 return OK; | |
3548 } | |
3549 | |
3550 /* | |
3551 * Find sentence(s) under the cursor, cursor at end. | |
3552 * When Visual active, extend it by one or more sentences. | |
3553 */ | |
3554 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3555 current_sent(oparg_T *oap, long count, int include) |
7 | 3556 { |
3557 pos_T start_pos; | |
3558 pos_T pos; | |
3559 int start_blank; | |
3560 int c; | |
3561 int at_start_sent; | |
3562 long ncount; | |
3563 | |
3564 start_pos = curwin->w_cursor; | |
3565 pos = start_pos; | |
3566 findsent(FORWARD, 1L); /* Find start of next sentence. */ | |
3567 | |
3568 /* | |
3701 | 3569 * When the Visual area is bigger than one character: Extend it. |
7 | 3570 */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3571 if (VIsual_active && !EQUAL_POS(start_pos, VIsual)) |
7 | 3572 { |
3573 extend: | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3574 if (LT_POS(start_pos, VIsual)) |
7 | 3575 { |
3576 /* | |
3577 * Cursor at start of Visual area. | |
3578 * Find out where we are: | |
3579 * - in the white space before a sentence | |
3580 * - in a sentence or just after it | |
3581 * - at the start of a sentence | |
3582 */ | |
3583 at_start_sent = TRUE; | |
3584 decl(&pos); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3585 while (LT_POS(pos, curwin->w_cursor)) |
7 | 3586 { |
3587 c = gchar_pos(&pos); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3588 if (!VIM_ISWHITE(c)) |
7 | 3589 { |
3590 at_start_sent = FALSE; | |
3591 break; | |
3592 } | |
3593 incl(&pos); | |
3594 } | |
3595 if (!at_start_sent) | |
3596 { | |
3597 findsent(BACKWARD, 1L); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3598 if (EQUAL_POS(curwin->w_cursor, start_pos)) |
7 | 3599 at_start_sent = TRUE; /* exactly at start of sentence */ |
3600 else | |
3601 /* inside a sentence, go to its end (start of next) */ | |
3602 findsent(FORWARD, 1L); | |
3603 } | |
3604 if (include) /* "as" gets twice as much as "is" */ | |
3605 count *= 2; | |
3606 while (count--) | |
3607 { | |
3608 if (at_start_sent) | |
3609 find_first_blank(&curwin->w_cursor); | |
3610 c = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3611 if (!at_start_sent || (!include && !VIM_ISWHITE(c))) |
7 | 3612 findsent(BACKWARD, 1L); |
3613 at_start_sent = !at_start_sent; | |
3614 } | |
3615 } | |
3616 else | |
3617 { | |
3618 /* | |
3619 * Cursor at end of Visual area. | |
3620 * Find out where we are: | |
3621 * - just before a sentence | |
3622 * - just before or in the white space before a sentence | |
3623 * - in a sentence | |
3624 */ | |
3625 incl(&pos); | |
3626 at_start_sent = TRUE; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3627 /* not just before a sentence */ |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3628 if (!EQUAL_POS(pos, curwin->w_cursor)) |
7 | 3629 { |
3630 at_start_sent = FALSE; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3631 while (LT_POS(pos, curwin->w_cursor)) |
7 | 3632 { |
3633 c = gchar_pos(&pos); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3634 if (!VIM_ISWHITE(c)) |
7 | 3635 { |
3636 at_start_sent = TRUE; | |
3637 break; | |
3638 } | |
3639 incl(&pos); | |
3640 } | |
3641 if (at_start_sent) /* in the sentence */ | |
3642 findsent(BACKWARD, 1L); | |
3643 else /* in/before white before a sentence */ | |
3644 curwin->w_cursor = start_pos; | |
3645 } | |
3646 | |
3647 if (include) /* "as" gets twice as much as "is" */ | |
3648 count *= 2; | |
3649 findsent_forward(count, at_start_sent); | |
3650 if (*p_sel == 'e') | |
3651 ++curwin->w_cursor.col; | |
3652 } | |
3653 return OK; | |
3654 } | |
3655 | |
3656 /* | |
3701 | 3657 * If the cursor started on a blank, check if it is just before the start |
3658 * of the next sentence. | |
7 | 3659 */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3660 while (c = gchar_pos(&pos), VIM_ISWHITE(c)) /* VIM_ISWHITE() is a macro */ |
7 | 3661 incl(&pos); |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3662 if (EQUAL_POS(pos, curwin->w_cursor)) |
7 | 3663 { |
3664 start_blank = TRUE; | |
3665 find_first_blank(&start_pos); /* go back to first blank */ | |
3666 } | |
3667 else | |
3668 { | |
3669 start_blank = FALSE; | |
3670 findsent(BACKWARD, 1L); | |
3671 start_pos = curwin->w_cursor; | |
3672 } | |
3673 if (include) | |
3674 ncount = count * 2; | |
3675 else | |
3676 { | |
3677 ncount = count; | |
3678 if (start_blank) | |
3679 --ncount; | |
3680 } | |
45 | 3681 if (ncount > 0) |
7 | 3682 findsent_forward(ncount, TRUE); |
3683 else | |
3684 decl(&curwin->w_cursor); | |
3685 | |
3686 if (include) | |
3687 { | |
3688 /* | |
3689 * If the blank in front of the sentence is included, exclude the | |
3690 * blanks at the end of the sentence, go back to the first blank. | |
3691 * If there are no trailing blanks, try to include leading blanks. | |
3692 */ | |
3693 if (start_blank) | |
3694 { | |
3695 find_first_blank(&curwin->w_cursor); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3696 c = gchar_pos(&curwin->w_cursor); /* VIM_ISWHITE() is a macro */ |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3697 if (VIM_ISWHITE(c)) |
7 | 3698 decl(&curwin->w_cursor); |
3699 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3700 else if (c = gchar_cursor(), !VIM_ISWHITE(c)) |
7 | 3701 find_first_blank(&start_pos); |
3702 } | |
3703 | |
3704 if (VIsual_active) | |
3705 { | |
3701 | 3706 /* Avoid getting stuck with "is" on a single space before a sentence. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3707 if (EQUAL_POS(start_pos, curwin->w_cursor)) |
7 | 3708 goto extend; |
3709 if (*p_sel == 'e') | |
3710 ++curwin->w_cursor.col; | |
3711 VIsual = start_pos; | |
3712 VIsual_mode = 'v'; | |
10064
793471c09a4b
commit https://github.com/vim/vim/commit/779f2fc3a7468e273897d2fd0672315812a2e3da
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3713 redraw_cmdline = TRUE; /* show mode later */ |
7 | 3714 redraw_curbuf_later(INVERTED); /* update the inversion */ |
3715 } | |
3716 else | |
3717 { | |
3718 /* include a newline after the sentence, if there is one */ | |
3719 if (incl(&curwin->w_cursor) == -1) | |
3720 oap->inclusive = TRUE; | |
3721 else | |
3722 oap->inclusive = FALSE; | |
3723 oap->start = start_pos; | |
3724 oap->motion_type = MCHAR; | |
3725 } | |
3726 return OK; | |
3727 } | |
3728 | |
423 | 3729 /* |
3730 * Find block under the cursor, cursor at end. | |
4352 | 3731 * "what" and "other" are two matching parenthesis/brace/etc. |
423 | 3732 */ |
7 | 3733 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3734 current_block( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3735 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3736 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3737 int include, /* TRUE == include white space */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3738 int what, /* '(', '{', etc. */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3739 int other) /* ')', '}', etc. */ |
7 | 3740 { |
3741 pos_T old_pos; | |
3742 pos_T *pos = NULL; | |
3743 pos_T start_pos; | |
3744 pos_T *end_pos; | |
3745 pos_T old_start, old_end; | |
3746 char_u *save_cpo; | |
423 | 3747 int sol = FALSE; /* '{' at start of line */ |
7 | 3748 |
3749 old_pos = curwin->w_cursor; | |
423 | 3750 old_end = curwin->w_cursor; /* remember where we started */ |
7 | 3751 old_start = old_end; |
3752 | |
3753 /* | |
3754 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive. | |
3755 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3756 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor)) |
7 | 3757 { |
3758 setpcmark(); | |
423 | 3759 if (what == '{') /* ignore indent */ |
7 | 3760 while (inindent(1)) |
3761 if (inc_cursor() != 0) | |
3762 break; | |
423 | 3763 if (gchar_cursor() == what) |
3764 /* cursor on '(' or '{', move cursor just after it */ | |
7 | 3765 ++curwin->w_cursor.col; |
3766 } | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3767 else if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 3768 { |
3769 old_start = VIsual; | |
3770 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ | |
3771 } | |
3772 else | |
3773 old_end = VIsual; | |
3774 | |
3775 /* | |
3776 * Search backwards for unclosed '(', '{', etc.. | |
3777 * Put this position in start_pos. | |
6675 | 3778 * Ignore quotes here. Keep the "M" flag in 'cpo', as that is what the |
3779 * user wants. | |
7 | 3780 */ |
3781 save_cpo = p_cpo; | |
6675 | 3782 p_cpo = (char_u *)(vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%"); |
7 | 3783 while (count-- > 0) |
3784 { | |
3785 if ((pos = findmatch(NULL, what)) == NULL) | |
3786 break; | |
3787 curwin->w_cursor = *pos; | |
3788 start_pos = *pos; /* the findmatch for end_pos will overwrite *pos */ | |
3789 } | |
3790 p_cpo = save_cpo; | |
3791 | |
3792 /* | |
3793 * Search for matching ')', '}', etc. | |
3794 * Put this position in curwin->w_cursor. | |
3795 */ | |
3796 if (pos == NULL || (end_pos = findmatch(NULL, other)) == NULL) | |
3797 { | |
3798 curwin->w_cursor = old_pos; | |
3799 return FAIL; | |
3800 } | |
3801 curwin->w_cursor = *end_pos; | |
3802 | |
3803 /* | |
3804 * Try to exclude the '(', '{', ')', '}', etc. when "include" is FALSE. | |
5975 | 3805 * If the ending '}', ')' or ']' is only preceded by indent, skip that |
3806 * indent. But only if the resulting area is not smaller than what we | |
3807 * started with. | |
7 | 3808 */ |
3809 while (!include) | |
3810 { | |
3811 incl(&start_pos); | |
3812 sol = (curwin->w_cursor.col == 0); | |
3813 decl(&curwin->w_cursor); | |
5975 | 3814 while (inindent(1)) |
3815 { | |
3816 sol = TRUE; | |
3817 if (decl(&curwin->w_cursor) != 0) | |
3818 break; | |
3819 } | |
3820 | |
7 | 3821 /* |
3822 * In Visual mode, when the resulting area is not bigger than what we | |
3823 * started with, extend it to the next block, and then exclude again. | |
3824 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3825 if (!LT_POS(start_pos, old_start) && !LT_POS(old_end, curwin->w_cursor) |
7 | 3826 && VIsual_active) |
3827 { | |
3828 curwin->w_cursor = old_start; | |
3829 decl(&curwin->w_cursor); | |
3830 if ((pos = findmatch(NULL, what)) == NULL) | |
3831 { | |
3832 curwin->w_cursor = old_pos; | |
3833 return FAIL; | |
3834 } | |
3835 start_pos = *pos; | |
3836 curwin->w_cursor = *pos; | |
3837 if ((end_pos = findmatch(NULL, other)) == NULL) | |
3838 { | |
3839 curwin->w_cursor = old_pos; | |
3840 return FAIL; | |
3841 } | |
3842 curwin->w_cursor = *end_pos; | |
3843 } | |
3844 else | |
3845 break; | |
3846 } | |
3847 | |
3848 if (VIsual_active) | |
3849 { | |
3850 if (*p_sel == 'e') | |
7070
d92910c0c415
commit https://github.com/vim/vim/commit/8667d66ca923d361e00e6369cbff37283db5a432
Christian Brabandt <cb@256bit.org>
parents:
7054
diff
changeset
|
3851 inc(&curwin->w_cursor); |
557 | 3852 if (sol && gchar_cursor() != NUL) |
7 | 3853 inc(&curwin->w_cursor); /* include the line break */ |
3854 VIsual = start_pos; | |
3855 VIsual_mode = 'v'; | |
3856 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3857 showmode(); | |
3858 } | |
3859 else | |
3860 { | |
3861 oap->start = start_pos; | |
3862 oap->motion_type = MCHAR; | |
1290 | 3863 oap->inclusive = FALSE; |
7 | 3864 if (sol) |
3865 incl(&curwin->w_cursor); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3866 else if (LTOREQ_POS(start_pos, curwin->w_cursor)) |
1290 | 3867 /* Include the character under the cursor. */ |
3868 oap->inclusive = TRUE; | |
7 | 3869 else |
1290 | 3870 /* End is before the start (no text in between <>, [], etc.): don't |
3871 * operate on any text. */ | |
3872 curwin->w_cursor = start_pos; | |
7 | 3873 } |
3874 | |
3875 return OK; | |
3876 } | |
3877 | |
423 | 3878 /* |
3879 * Return TRUE if the cursor is on a "<aaa>" tag. Ignore "<aaa/>". | |
3880 * When "end_tag" is TRUE return TRUE if the cursor is on "</aaa>". | |
3881 */ | |
3882 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3883 in_html_tag( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3884 int end_tag) |
423 | 3885 { |
3886 char_u *line = ml_get_curline(); | |
3887 char_u *p; | |
3888 int c; | |
3889 int lc = NUL; | |
3890 pos_T pos; | |
3891 | |
3892 if (enc_dbcs) | |
3893 { | |
3894 char_u *lp = NULL; | |
3895 | |
3896 /* We search forward until the cursor, because searching backwards is | |
3897 * very slow for DBCS encodings. */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3898 for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p)) |
423 | 3899 if (*p == '>' || *p == '<') |
3900 { | |
3901 lc = *p; | |
3902 lp = p; | |
3903 } | |
3904 if (*p != '<') /* check for '<' under cursor */ | |
3905 { | |
3906 if (lc != '<') | |
3907 return FALSE; | |
3908 p = lp; | |
3909 } | |
3910 } | |
3911 else | |
3912 { | |
3913 for (p = line + curwin->w_cursor.col; p > line; ) | |
3914 { | |
3915 if (*p == '<') /* find '<' under/before cursor */ | |
3916 break; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3917 MB_PTR_BACK(line, p); |
423 | 3918 if (*p == '>') /* find '>' before cursor */ |
3919 break; | |
3920 } | |
3921 if (*p != '<') | |
3922 return FALSE; | |
3923 } | |
3924 | |
3925 pos.lnum = curwin->w_cursor.lnum; | |
835 | 3926 pos.col = (colnr_T)(p - line); |
423 | 3927 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3928 MB_PTR_ADV(p); |
423 | 3929 if (end_tag) |
3930 /* check that there is a '/' after the '<' */ | |
3931 return *p == '/'; | |
3932 | |
3933 /* check that there is no '/' after the '<' */ | |
3934 if (*p == '/') | |
3935 return FALSE; | |
3936 | |
3937 /* check that the matching '>' is not preceded by '/' */ | |
3938 for (;;) | |
3939 { | |
3940 if (inc(&pos) < 0) | |
3941 return FALSE; | |
3942 c = *ml_get_pos(&pos); | |
3943 if (c == '>') | |
3944 break; | |
3945 lc = c; | |
3946 } | |
3947 return lc != '/'; | |
3948 } | |
3949 | |
3950 /* | |
3951 * Find tag block under the cursor, cursor at end. | |
3952 */ | |
3953 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3954 current_tagblock( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3955 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3956 long count_arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3957 int include) /* TRUE == include white space */ |
423 | 3958 { |
3959 long count = count_arg; | |
3960 long n; | |
3961 pos_T old_pos; | |
3962 pos_T start_pos; | |
3963 pos_T end_pos; | |
3964 pos_T old_start, old_end; | |
3965 char_u *spat, *epat; | |
3966 char_u *p; | |
3967 char_u *cp; | |
3968 int len; | |
3969 int r; | |
3970 int do_include = include; | |
3971 int save_p_ws = p_ws; | |
3972 int retval = FAIL; | |
6661 | 3973 int is_inclusive = TRUE; |
423 | 3974 |
3975 p_ws = FALSE; | |
3976 | |
3977 old_pos = curwin->w_cursor; | |
3978 old_end = curwin->w_cursor; /* remember where we started */ | |
3979 old_start = old_end; | |
1527 | 3980 if (!VIsual_active || *p_sel == 'e') |
3981 decl(&old_end); /* old_end is inclusive */ | |
423 | 3982 |
3983 /* | |
435 | 3984 * If we start on "<aaa>" select that block. |
423 | 3985 */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
3986 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor)) |
423 | 3987 { |
3988 setpcmark(); | |
3989 | |
3990 /* ignore indent */ | |
3991 while (inindent(1)) | |
3992 if (inc_cursor() != 0) | |
3993 break; | |
3994 | |
3995 if (in_html_tag(FALSE)) | |
3996 { | |
1290 | 3997 /* cursor on start tag, move to its '>' */ |
423 | 3998 while (*ml_get_cursor() != '>') |
3999 if (inc_cursor() < 0) | |
4000 break; | |
4001 } | |
4002 else if (in_html_tag(TRUE)) | |
4003 { | |
4004 /* cursor on end tag, move to just before it */ | |
4005 while (*ml_get_cursor() != '<') | |
4006 if (dec_cursor() < 0) | |
4007 break; | |
4008 dec_cursor(); | |
4009 old_end = curwin->w_cursor; | |
4010 } | |
4011 } | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4012 else if (LT_POS(VIsual, curwin->w_cursor)) |
423 | 4013 { |
4014 old_start = VIsual; | |
4015 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ | |
4016 } | |
4017 else | |
4018 old_end = VIsual; | |
4019 | |
4020 again: | |
4021 /* | |
4022 * Search backwards for unclosed "<aaa>". | |
4023 * Put this position in start_pos. | |
4024 */ | |
4025 for (n = 0; n < count; ++n) | |
4026 { | |
435 | 4027 if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)", |
423 | 4028 (char_u *)"", |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
4029 (char_u *)"</[^>]*>", BACKWARD, NULL, 0, |
1496 | 4030 NULL, (linenr_T)0, 0L) <= 0) |
423 | 4031 { |
4032 curwin->w_cursor = old_pos; | |
4033 goto theend; | |
4034 } | |
4035 } | |
4036 start_pos = curwin->w_cursor; | |
4037 | |
4038 /* | |
4039 * Search for matching "</aaa>". First isolate the "aaa". | |
4040 */ | |
4041 inc_cursor(); | |
4042 p = ml_get_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4043 for (cp = p; *cp != NUL && *cp != '>' && !VIM_ISWHITE(*cp); MB_PTR_ADV(cp)) |
423 | 4044 ; |
835 | 4045 len = (int)(cp - p); |
423 | 4046 if (len == 0) |
4047 { | |
4048 curwin->w_cursor = old_pos; | |
4049 goto theend; | |
4050 } | |
3306 | 4051 spat = alloc(len + 31); |
423 | 4052 epat = alloc(len + 9); |
4053 if (spat == NULL || epat == NULL) | |
4054 { | |
4055 vim_free(spat); | |
4056 vim_free(epat); | |
4057 curwin->w_cursor = old_pos; | |
4058 goto theend; | |
4059 } | |
3306 | 4060 sprintf((char *)spat, "<%.*s\\>\\%%(\\s\\_[^>]\\{-}[^/]>\\|>\\)\\c", len, p); |
423 | 4061 sprintf((char *)epat, "</%.*s>\\c", len, p); |
4062 | |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
4063 r = do_searchpair(spat, (char_u *)"", epat, FORWARD, NULL, |
1496 | 4064 0, NULL, (linenr_T)0, 0L); |
423 | 4065 |
4066 vim_free(spat); | |
4067 vim_free(epat); | |
4068 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4069 if (r < 1 || LT_POS(curwin->w_cursor, old_end)) |
423 | 4070 { |
4071 /* Can't find other end or it's before the previous end. Could be a | |
4072 * HTML tag that doesn't have a matching end. Search backwards for | |
4073 * another starting tag. */ | |
4074 count = 1; | |
4075 curwin->w_cursor = start_pos; | |
4076 goto again; | |
4077 } | |
4078 | |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
4079 if (do_include) |
423 | 4080 { |
4081 /* Include up to the '>'. */ | |
4082 while (*ml_get_cursor() != '>') | |
4083 if (inc_cursor() < 0) | |
4084 break; | |
4085 } | |
4086 else | |
4087 { | |
6661 | 4088 char_u *c = ml_get_cursor(); |
4089 | |
4090 /* Exclude the '<' of the end tag. | |
4091 * If the closing tag is on new line, do not decrement cursor, but | |
4092 * make operation exclusive, so that the linefeed will be selected */ | |
4093 if (*c == '<' && !VIsual_active && curwin->w_cursor.col == 0) | |
4094 /* do not decrement cursor */ | |
4095 is_inclusive = FALSE; | |
4096 else if (*c == '<') | |
423 | 4097 dec_cursor(); |
4098 } | |
4099 end_pos = curwin->w_cursor; | |
4100 | |
4101 if (!do_include) | |
4102 { | |
4103 /* Exclude the start tag. */ | |
4104 curwin->w_cursor = start_pos; | |
4105 while (inc_cursor() >= 0) | |
1290 | 4106 if (*ml_get_cursor() == '>') |
423 | 4107 { |
4108 inc_cursor(); | |
4109 start_pos = curwin->w_cursor; | |
4110 break; | |
4111 } | |
4112 curwin->w_cursor = end_pos; | |
4113 | |
14554
e7f92d1a3fcd
patch 8.1.0290: "cit" on an empty HTML tag changes the whole tag
Christian Brabandt <cb@256bit.org>
parents:
14131
diff
changeset
|
4114 // If we are in Visual mode and now have the same text as before set |
e7f92d1a3fcd
patch 8.1.0290: "cit" on an empty HTML tag changes the whole tag
Christian Brabandt <cb@256bit.org>
parents:
14131
diff
changeset
|
4115 // "do_include" and try again. |
e7f92d1a3fcd
patch 8.1.0290: "cit" on an empty HTML tag changes the whole tag
Christian Brabandt <cb@256bit.org>
parents:
14131
diff
changeset
|
4116 if (VIsual_active && EQUAL_POS(start_pos, old_start) |
e7f92d1a3fcd
patch 8.1.0290: "cit" on an empty HTML tag changes the whole tag
Christian Brabandt <cb@256bit.org>
parents:
14131
diff
changeset
|
4117 && EQUAL_POS(end_pos, old_end)) |
423 | 4118 { |
4119 do_include = TRUE; | |
4120 curwin->w_cursor = old_start; | |
4121 count = count_arg; | |
4122 goto again; | |
4123 } | |
4124 } | |
4125 | |
4126 if (VIsual_active) | |
4127 { | |
1290 | 4128 /* If the end is before the start there is no text between tags, select |
4129 * the char under the cursor. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4130 if (LT_POS(end_pos, start_pos)) |
1290 | 4131 curwin->w_cursor = start_pos; |
4132 else if (*p_sel == 'e') | |
6434 | 4133 inc_cursor(); |
423 | 4134 VIsual = start_pos; |
4135 VIsual_mode = 'v'; | |
4136 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
4137 showmode(); | |
4138 } | |
4139 else | |
4140 { | |
4141 oap->start = start_pos; | |
4142 oap->motion_type = MCHAR; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4143 if (LT_POS(end_pos, start_pos)) |
1290 | 4144 { |
4145 /* End is before the start: there is no text between tags; operate | |
4146 * on an empty area. */ | |
4147 curwin->w_cursor = start_pos; | |
4148 oap->inclusive = FALSE; | |
4149 } | |
4150 else | |
6661 | 4151 oap->inclusive = is_inclusive; |
423 | 4152 } |
4153 retval = OK; | |
4154 | |
4155 theend: | |
4156 p_ws = save_p_ws; | |
4157 return retval; | |
4158 } | |
4159 | |
7 | 4160 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4161 current_par( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4162 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4163 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4164 int include, /* TRUE == include white space */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4165 int type) /* 'p' for paragraph, 'S' for section */ |
7 | 4166 { |
4167 linenr_T start_lnum; | |
4168 linenr_T end_lnum; | |
4169 int white_in_front; | |
4170 int dir; | |
4171 int start_is_white; | |
4172 int prev_start_is_white; | |
4173 int retval = OK; | |
4174 int do_white = FALSE; | |
4175 int t; | |
4176 int i; | |
4177 | |
4178 if (type == 'S') /* not implemented yet */ | |
4179 return FAIL; | |
4180 | |
4181 start_lnum = curwin->w_cursor.lnum; | |
4182 | |
4183 /* | |
4184 * When visual area is more than one line: extend it. | |
4185 */ | |
4186 if (VIsual_active && start_lnum != VIsual.lnum) | |
4187 { | |
4188 extend: | |
4189 if (start_lnum < VIsual.lnum) | |
4190 dir = BACKWARD; | |
4191 else | |
4192 dir = FORWARD; | |
4193 for (i = count; --i >= 0; ) | |
4194 { | |
4195 if (start_lnum == | |
4196 (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) | |
4197 { | |
4198 retval = FAIL; | |
4199 break; | |
4200 } | |
4201 | |
4202 prev_start_is_white = -1; | |
4203 for (t = 0; t < 2; ++t) | |
4204 { | |
4205 start_lnum += dir; | |
4206 start_is_white = linewhite(start_lnum); | |
4207 if (prev_start_is_white == start_is_white) | |
4208 { | |
4209 start_lnum -= dir; | |
4210 break; | |
4211 } | |
4212 for (;;) | |
4213 { | |
4214 if (start_lnum == (dir == BACKWARD | |
4215 ? 1 : curbuf->b_ml.ml_line_count)) | |
4216 break; | |
4217 if (start_is_white != linewhite(start_lnum + dir) | |
4218 || (!start_is_white | |
4219 && startPS(start_lnum + (dir > 0 | |
4220 ? 1 : 0), 0, 0))) | |
4221 break; | |
4222 start_lnum += dir; | |
4223 } | |
4224 if (!include) | |
4225 break; | |
4226 if (start_lnum == (dir == BACKWARD | |
4227 ? 1 : curbuf->b_ml.ml_line_count)) | |
4228 break; | |
4229 prev_start_is_white = start_is_white; | |
4230 } | |
4231 } | |
4232 curwin->w_cursor.lnum = start_lnum; | |
4233 curwin->w_cursor.col = 0; | |
4234 return retval; | |
4235 } | |
4236 | |
4237 /* | |
4238 * First move back to the start_lnum of the paragraph or white lines | |
4239 */ | |
4240 white_in_front = linewhite(start_lnum); | |
4241 while (start_lnum > 1) | |
4242 { | |
4243 if (white_in_front) /* stop at first white line */ | |
4244 { | |
4245 if (!linewhite(start_lnum - 1)) | |
4246 break; | |
4247 } | |
4248 else /* stop at first non-white line of start of paragraph */ | |
4249 { | |
4250 if (linewhite(start_lnum - 1) || startPS(start_lnum, 0, 0)) | |
4251 break; | |
4252 } | |
4253 --start_lnum; | |
4254 } | |
4255 | |
4256 /* | |
4257 * Move past the end of any white lines. | |
4258 */ | |
4259 end_lnum = start_lnum; | |
692 | 4260 while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum)) |
4261 ++end_lnum; | |
7 | 4262 |
4263 --end_lnum; | |
4264 i = count; | |
4265 if (!include && white_in_front) | |
4266 --i; | |
4267 while (i--) | |
4268 { | |
4269 if (end_lnum == curbuf->b_ml.ml_line_count) | |
4270 return FAIL; | |
4271 | |
4272 if (!include) | |
4273 do_white = linewhite(end_lnum + 1); | |
4274 | |
4275 if (include || !do_white) | |
4276 { | |
4277 ++end_lnum; | |
4278 /* | |
4279 * skip to end of paragraph | |
4280 */ | |
4281 while (end_lnum < curbuf->b_ml.ml_line_count | |
4282 && !linewhite(end_lnum + 1) | |
4283 && !startPS(end_lnum + 1, 0, 0)) | |
4284 ++end_lnum; | |
4285 } | |
4286 | |
4287 if (i == 0 && white_in_front && include) | |
4288 break; | |
4289 | |
4290 /* | |
4291 * skip to end of white lines after paragraph | |
4292 */ | |
4293 if (include || do_white) | |
4294 while (end_lnum < curbuf->b_ml.ml_line_count | |
4295 && linewhite(end_lnum + 1)) | |
4296 ++end_lnum; | |
4297 } | |
4298 | |
4299 /* | |
4300 * If there are no empty lines at the end, try to find some empty lines at | |
4301 * the start (unless that has been done already). | |
4302 */ | |
4303 if (!white_in_front && !linewhite(end_lnum) && include) | |
4304 while (start_lnum > 1 && linewhite(start_lnum - 1)) | |
4305 --start_lnum; | |
4306 | |
4307 if (VIsual_active) | |
4308 { | |
4309 /* Problem: when doing "Vipipip" nothing happens in a single white | |
4310 * line, we get stuck there. Trap this here. */ | |
4311 if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum) | |
4312 goto extend; | |
10881
8f6df2f6d2fc
patch 8.0.0330: illegal memory access after "vapo"
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
4313 if (VIsual.lnum != start_lnum) |
8f6df2f6d2fc
patch 8.0.0330: illegal memory access after "vapo"
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
4314 { |
8f6df2f6d2fc
patch 8.0.0330: illegal memory access after "vapo"
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
4315 VIsual.lnum = start_lnum; |
8f6df2f6d2fc
patch 8.0.0330: illegal memory access after "vapo"
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
4316 VIsual.col = 0; |
8f6df2f6d2fc
patch 8.0.0330: illegal memory access after "vapo"
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
4317 } |
7 | 4318 VIsual_mode = 'V'; |
4319 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
4320 showmode(); | |
4321 } | |
4322 else | |
4323 { | |
4324 oap->start.lnum = start_lnum; | |
4325 oap->start.col = 0; | |
4326 oap->motion_type = MLINE; | |
4327 } | |
4328 curwin->w_cursor.lnum = end_lnum; | |
4329 curwin->w_cursor.col = 0; | |
4330 | |
4331 return OK; | |
4332 } | |
12 | 4333 |
4334 /* | |
4335 * Search quote char from string line[col]. | |
4336 * Quote character escaped by one of the characters in "escape" is not counted | |
4337 * as a quote. | |
4338 * Returns column number of "quotechar" or -1 when not found. | |
4339 */ | |
4340 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4341 find_next_quote( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4342 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4343 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4344 int quotechar, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4345 char_u *escape) /* escape characters, can be NULL */ |
12 | 4346 { |
4347 int c; | |
4348 | |
408 | 4349 for (;;) |
12 | 4350 { |
4351 c = line[col]; | |
4352 if (c == NUL) | |
4353 return -1; | |
4354 else if (escape != NULL && vim_strchr(escape, c)) | |
4355 ++col; | |
4356 else if (c == quotechar) | |
4357 break; | |
4358 if (has_mbyte) | |
474 | 4359 col += (*mb_ptr2len)(line + col); |
12 | 4360 else |
4361 ++col; | |
4362 } | |
4363 return col; | |
4364 } | |
4365 | |
4366 /* | |
4367 * Search backwards in "line" from column "col_start" to find "quotechar". | |
4368 * Quote character escaped by one of the characters in "escape" is not counted | |
4369 * as a quote. | |
4370 * Return the found column or zero. | |
4371 */ | |
4372 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4373 find_prev_quote( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4374 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4375 int col_start, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4376 int quotechar, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4377 char_u *escape) /* escape characters, can be NULL */ |
12 | 4378 { |
4379 int n; | |
4380 | |
4381 while (col_start > 0) | |
4382 { | |
4383 --col_start; | |
4384 col_start -= (*mb_head_off)(line, line + col_start); | |
4385 n = 0; | |
4386 if (escape != NULL) | |
4387 while (col_start - n > 0 && vim_strchr(escape, | |
4388 line[col_start - n - 1]) != NULL) | |
4389 ++n; | |
4390 if (n & 1) | |
4391 col_start -= n; /* uneven number of escape chars, skip it */ | |
4392 else if (line[col_start] == quotechar) | |
4393 break; | |
4394 } | |
4395 return col_start; | |
4396 } | |
4397 | |
4398 /* | |
4399 * Find quote under the cursor, cursor at end. | |
4400 * Returns TRUE if found, else FALSE. | |
4401 */ | |
4402 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4403 current_quote( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4404 oparg_T *oap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4405 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4406 int include, /* TRUE == include quote char */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4407 int quotechar) /* Quote character */ |
12 | 4408 { |
4409 char_u *line = ml_get_curline(); | |
4410 int col_end; | |
4411 int col_start = curwin->w_cursor.col; | |
4412 int inclusive = FALSE; | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4413 int vis_empty = TRUE; // Visual selection <= 1 char |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4414 int vis_bef_curs = FALSE; // Visual starts before cursor |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4415 int inside_quotes = FALSE; // Looks like "i'" done before |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4416 int selected_quote = FALSE; // Has quote inside selection |
527 | 4417 int i; |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4418 int restore_vis_bef = FALSE; // restore VIsual on abort |
12 | 4419 |
11478
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4420 /* Correct cursor when 'selection' is "exclusive". */ |
12 | 4421 if (VIsual_active) |
4422 { | |
10900
9b4574d95571
patch 8.0.0339: illegal memory access with vi'
Christian Brabandt <cb@256bit.org>
parents:
10881
diff
changeset
|
4423 /* this only works within one line */ |
9b4574d95571
patch 8.0.0339: illegal memory access with vi'
Christian Brabandt <cb@256bit.org>
parents:
10881
diff
changeset
|
4424 if (VIsual.lnum != curwin->w_cursor.lnum) |
9b4574d95571
patch 8.0.0339: illegal memory access with vi'
Christian Brabandt <cb@256bit.org>
parents:
10881
diff
changeset
|
4425 return FALSE; |
9b4574d95571
patch 8.0.0339: illegal memory access with vi'
Christian Brabandt <cb@256bit.org>
parents:
10881
diff
changeset
|
4426 |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4427 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); |
11478
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4428 if (*p_sel == 'e') |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4429 { |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4430 if (!vis_bef_curs) |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4431 { |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4432 // VIsual needs to be the start of Visual selection. |
11478
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4433 pos_T t = curwin->w_cursor; |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4434 |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4435 curwin->w_cursor = VIsual; |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4436 VIsual = t; |
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4437 vis_bef_curs = TRUE; |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4438 restore_vis_bef = TRUE; |
11478
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4439 } |
12 | 4440 dec_cursor(); |
11478
29a781fd3f27
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
4441 } |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4442 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); |
12 | 4443 } |
527 | 4444 |
4445 if (!vis_empty) | |
4446 { | |
4447 /* Check if the existing selection exactly spans the text inside | |
4448 * quotes. */ | |
4449 if (vis_bef_curs) | |
4450 { | |
4451 inside_quotes = VIsual.col > 0 | |
4452 && line[VIsual.col - 1] == quotechar | |
4453 && line[curwin->w_cursor.col] != NUL | |
4454 && line[curwin->w_cursor.col + 1] == quotechar; | |
4455 i = VIsual.col; | |
4456 col_end = curwin->w_cursor.col; | |
4457 } | |
4458 else | |
4459 { | |
4460 inside_quotes = curwin->w_cursor.col > 0 | |
4461 && line[curwin->w_cursor.col - 1] == quotechar | |
4462 && line[VIsual.col] != NUL | |
4463 && line[VIsual.col + 1] == quotechar; | |
4464 i = curwin->w_cursor.col; | |
4465 col_end = VIsual.col; | |
4466 } | |
4467 | |
4468 /* Find out if we have a quote in the selection. */ | |
4469 while (i <= col_end) | |
4470 if (line[i++] == quotechar) | |
4471 { | |
4472 selected_quote = TRUE; | |
4473 break; | |
4474 } | |
4475 } | |
4476 | |
12 | 4477 if (!vis_empty && line[col_start] == quotechar) |
4478 { | |
4479 /* Already selecting something and on a quote character. Find the | |
4480 * next quoted string. */ | |
4481 if (vis_bef_curs) | |
4482 { | |
4483 /* Assume we are on a closing quote: move to after the next | |
4484 * opening quote. */ | |
4485 col_start = find_next_quote(line, col_start + 1, quotechar, NULL); | |
4486 if (col_start < 0) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4487 goto abort_search; |
12 | 4488 col_end = find_next_quote(line, col_start + 1, quotechar, |
4489 curbuf->b_p_qe); | |
4490 if (col_end < 0) | |
4491 { | |
4492 /* We were on a starting quote perhaps? */ | |
4493 col_end = col_start; | |
4494 col_start = curwin->w_cursor.col; | |
4495 } | |
4496 } | |
4497 else | |
4498 { | |
4499 col_end = find_prev_quote(line, col_start, quotechar, NULL); | |
4500 if (line[col_end] != quotechar) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4501 goto abort_search; |
12 | 4502 col_start = find_prev_quote(line, col_end, quotechar, |
4503 curbuf->b_p_qe); | |
4504 if (line[col_start] != quotechar) | |
4505 { | |
4506 /* We were on an ending quote perhaps? */ | |
4507 col_start = col_end; | |
4508 col_end = curwin->w_cursor.col; | |
4509 } | |
4510 } | |
4511 } | |
4512 else | |
5735 | 4513 |
4514 if (line[col_start] == quotechar || !vis_empty) | |
12 | 4515 { |
4516 int first_col = col_start; | |
4517 | |
4518 if (!vis_empty) | |
4519 { | |
4520 if (vis_bef_curs) | |
4521 first_col = find_next_quote(line, col_start, quotechar, NULL); | |
4522 else | |
4523 first_col = find_prev_quote(line, col_start, quotechar, NULL); | |
4524 } | |
5735 | 4525 |
12 | 4526 /* The cursor is on a quote, we don't know if it's the opening or |
4527 * closing quote. Search from the start of the line to find out. | |
4528 * Also do this when there is a Visual area, a' may leave the cursor | |
4529 * in between two strings. */ | |
4530 col_start = 0; | |
408 | 4531 for (;;) |
12 | 4532 { |
4533 /* Find open quote character. */ | |
4534 col_start = find_next_quote(line, col_start, quotechar, NULL); | |
4535 if (col_start < 0 || col_start > first_col) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4536 goto abort_search; |
12 | 4537 /* Find close quote character. */ |
4538 col_end = find_next_quote(line, col_start + 1, quotechar, | |
4539 curbuf->b_p_qe); | |
4540 if (col_end < 0) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4541 goto abort_search; |
12 | 4542 /* If is cursor between start and end quote character, it is |
4543 * target text object. */ | |
4544 if (col_start <= first_col && first_col <= col_end) | |
4545 break; | |
4546 col_start = col_end + 1; | |
4547 } | |
4548 } | |
4549 else | |
4550 { | |
4551 /* Search backward for a starting quote. */ | |
4552 col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe); | |
4553 if (line[col_start] != quotechar) | |
4554 { | |
4555 /* No quote before the cursor, look after the cursor. */ | |
4556 col_start = find_next_quote(line, col_start, quotechar, NULL); | |
4557 if (col_start < 0) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4558 goto abort_search; |
12 | 4559 } |
4560 | |
4561 /* Find close quote character. */ | |
4562 col_end = find_next_quote(line, col_start + 1, quotechar, | |
4563 curbuf->b_p_qe); | |
4564 if (col_end < 0) | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4565 goto abort_search; |
12 | 4566 } |
4567 | |
4568 /* When "include" is TRUE, include spaces after closing quote or before | |
4569 * the starting quote. */ | |
4570 if (include) | |
4571 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4572 if (VIM_ISWHITE(line[col_end + 1])) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4573 while (VIM_ISWHITE(line[col_end + 1])) |
12 | 4574 ++col_end; |
4575 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4576 while (col_start > 0 && VIM_ISWHITE(line[col_start - 1])) |
12 | 4577 --col_start; |
4578 } | |
4579 | |
527 | 4580 /* Set start position. After vi" another i" must include the ". |
4581 * For v2i" include the quotes. */ | |
5735 | 4582 if (!include && count < 2 && (vis_empty || !inside_quotes)) |
12 | 4583 ++col_start; |
4584 curwin->w_cursor.col = col_start; | |
4585 if (VIsual_active) | |
4586 { | |
527 | 4587 /* Set the start of the Visual area when the Visual area was empty, we |
4588 * were just inside quotes or the Visual area didn't start at a quote | |
4589 * and didn't include a quote. | |
4590 */ | |
4591 if (vis_empty | |
4592 || (vis_bef_curs | |
4593 && !selected_quote | |
4594 && (inside_quotes | |
4595 || (line[VIsual.col] != quotechar | |
4596 && (VIsual.col == 0 | |
4597 || line[VIsual.col - 1] != quotechar))))) | |
12 | 4598 { |
4599 VIsual = curwin->w_cursor; | |
4600 redraw_curbuf_later(INVERTED); | |
4601 } | |
4602 } | |
4603 else | |
4604 { | |
4605 oap->start = curwin->w_cursor; | |
4606 oap->motion_type = MCHAR; | |
4607 } | |
4608 | |
4609 /* Set end position. */ | |
4610 curwin->w_cursor.col = col_end; | |
5735 | 4611 if ((include || count > 1 /* After vi" another i" must include the ". */ |
527 | 4612 || (!vis_empty && inside_quotes) |
4613 ) && inc_cursor() == 2) | |
12 | 4614 inclusive = TRUE; |
4615 if (VIsual_active) | |
4616 { | |
4617 if (vis_empty || vis_bef_curs) | |
4618 { | |
4619 /* decrement cursor when 'selection' is not exclusive */ | |
4620 if (*p_sel != 'e') | |
4621 dec_cursor(); | |
4622 } | |
4623 else | |
4624 { | |
527 | 4625 /* Cursor is at start of Visual area. Set the end of the Visual |
4626 * area when it was just inside quotes or it didn't end at a | |
4627 * quote. */ | |
4628 if (inside_quotes | |
4629 || (!selected_quote | |
4630 && line[VIsual.col] != quotechar | |
4631 && (line[VIsual.col] == NUL | |
4632 || line[VIsual.col + 1] != quotechar))) | |
4633 { | |
4634 dec_cursor(); | |
4635 VIsual = curwin->w_cursor; | |
4636 } | |
12 | 4637 curwin->w_cursor.col = col_start; |
4638 } | |
4639 if (VIsual_mode == 'V') | |
4640 { | |
4641 VIsual_mode = 'v'; | |
4642 redraw_cmdline = TRUE; /* show mode later */ | |
4643 } | |
4644 } | |
4645 else | |
4646 { | |
4647 /* Set inclusive and other oap's flags. */ | |
4648 oap->inclusive = inclusive; | |
4649 } | |
4650 | |
4651 return OK; | |
15930
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4652 |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4653 abort_search: |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4654 if (VIsual_active && *p_sel == 'e') |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4655 { |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4656 inc_cursor(); |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4657 if (restore_vis_bef) |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4658 { |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4659 pos_T t = curwin->w_cursor; |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4660 |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4661 curwin->w_cursor = VIsual; |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4662 VIsual = t; |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4663 } |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4664 } |
e580c9d75443
patch 8.1.0971: failure for selecting quoted text object moves cursor
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
4665 return FALSE; |
12 | 4666 } |
4667 | |
4668 #endif /* FEAT_TEXTOBJ */ | |
7 | 4669 |
12539
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4670 static int is_one_char(char_u *pattern, int move, pos_T *cur, int direction); |
3755 | 4671 |
3718 | 4672 /* |
4673 * Find next search match under cursor, cursor at end. | |
4674 * Used while an operator is pending, and in Visual mode. | |
4675 */ | |
4676 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4677 current_search( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4678 long count, |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4679 int forward) // TRUE for forward, FALSE for backward |
3718 | 4680 { |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4681 pos_T start_pos; // start position of the pattern match |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4682 pos_T end_pos; // end position of the pattern match |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4683 pos_T orig_pos; // position of the cursor at beginning |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4684 pos_T pos; // position after the pattern |
3718 | 4685 int i; |
4686 int dir; | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4687 int result; // result of various function calls |
3718 | 4688 char_u old_p_ws = p_ws; |
4689 int flags = 0; | |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5118
diff
changeset
|
4690 pos_T save_VIsual = VIsual; |
5064
8875401008da
updated for version 7.3.1275
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4691 int one_char; |
3718 | 4692 |
4693 /* wrapping should not occur */ | |
4694 p_ws = FALSE; | |
4695 | |
4696 /* Correct cursor when 'selection' is exclusive */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4697 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) |
3718 | 4698 dec_cursor(); |
4699 | |
4700 if (VIsual_active) | |
4701 { | |
4702 orig_pos = curwin->w_cursor; | |
4703 | |
4704 pos = curwin->w_cursor; | |
4705 | |
4706 /* make sure, searching further will extend the match */ | |
4707 if (VIsual_active) | |
4708 { | |
4709 if (forward) | |
4710 incl(&pos); | |
4711 else | |
4712 decl(&pos); | |
4713 } | |
4714 } | |
4715 else | |
8954
ab4fe611d205
commit https://github.com/vim/vim/commit/268a06ce901d2c780304e0395028e3c2f60ec755
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
4716 orig_pos = pos = curwin->w_cursor; |
3718 | 4717 |
12539
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4718 /* Is the pattern is zero-width?, this time, don't care about the direction |
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4719 */ |
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4720 one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor, |
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4721 FORWARD); |
5064
8875401008da
updated for version 7.3.1275
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4722 if (one_char == -1) |
5523 | 4723 { |
4724 p_ws = old_p_ws; | |
4725 return FAIL; /* pattern not found */ | |
4726 } | |
3732 | 4727 |
4728 /* | |
3718 | 4729 * The trick is to first search backwards and then search forward again, |
4730 * so that a match at the current cursor position will be correctly | |
4731 * captured. | |
4732 */ | |
4733 for (i = 0; i < 2; i++) | |
4734 { | |
4735 if (forward) | |
4736 dir = i; | |
4737 else | |
4738 dir = !i; | |
3732 | 4739 |
4740 flags = 0; | |
5064
8875401008da
updated for version 7.3.1275
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4741 if (!dir && !one_char) |
3732 | 4742 flags = SEARCH_END; |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4743 end_pos = pos; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4744 |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4745 result = searchit(curwin, curbuf, &pos, &end_pos, |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4746 (dir ? FORWARD : BACKWARD), |
3718 | 4747 spats[last_idx].pat, (long) (i ? count : 1), |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
4748 SEARCH_KEEP | flags, RE_SEARCH, 0, NULL, NULL); |
3718 | 4749 |
4750 /* First search may fail, but then start searching from the | |
4751 * beginning of the file (cursor might be on the search match) | |
4752 * except when Visual mode is active, so that extending the visual | |
4753 * selection works. */ | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4754 if (i == 1 && !result) /* not found, abort */ |
3718 | 4755 { |
4756 curwin->w_cursor = orig_pos; | |
4757 if (VIsual_active) | |
4758 VIsual = save_VIsual; | |
4759 p_ws = old_p_ws; | |
4760 return FAIL; | |
4761 } | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4762 else if (i == 0 && !result) |
3718 | 4763 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4764 if (forward) |
3718 | 4765 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4766 /* try again from start of buffer */ |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4767 CLEAR_POS(&pos); |
3718 | 4768 } |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4769 else |
3718 | 4770 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4771 /* try again from end of buffer */ |
3718 | 4772 /* searching backwards, so set pos to last line and col */ |
4773 pos.lnum = curwin->w_buffer->b_ml.ml_line_count; | |
3724 | 4774 pos.col = (colnr_T)STRLEN( |
4775 ml_get(curwin->w_buffer->b_ml.ml_line_count)); | |
3718 | 4776 } |
4777 } | |
5452 | 4778 p_ws = old_p_ws; |
3718 | 4779 } |
4780 | |
4781 start_pos = pos; | |
14000
96933f0ecbd1
patch 8.1.0018: using "gn" may select wrong text when wrapping
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
4782 p_ws = old_p_ws; |
3718 | 4783 |
4784 if (!VIsual_active) | |
4785 VIsual = start_pos; | |
4786 | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4787 // put cursor on last character of match |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4788 curwin->w_cursor = end_pos; |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4789 if (LT_POS(VIsual, end_pos)) |
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4790 dec_cursor(); |
3718 | 4791 VIsual_active = TRUE; |
4792 VIsual_mode = 'v'; | |
4793 | |
15758
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4794 redraw_curbuf_later(INVERTED); /* update the inversion */ |
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4795 if (*p_sel == 'e') |
3718 | 4796 { |
15758
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4797 /* Correction for exclusive selection depends on the direction. */ |
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4798 if (forward && LTOREQ_POS(VIsual, curwin->w_cursor)) |
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4799 inc_cursor(); |
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4800 else if (!forward && LTOREQ_POS(curwin->w_cursor, VIsual)) |
675dd5d7afb3
patch 8.1.0886: compiler warning for NULL pointer and condition always true
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4801 inc(&VIsual); |
3718 | 4802 } |
4803 | |
4804 #ifdef FEAT_FOLDING | |
4805 if (fdo_flags & FDO_SEARCH && KeyTyped) | |
4806 foldOpenCursor(); | |
4807 #endif | |
4808 | |
4809 may_start_select('c'); | |
4810 #ifdef FEAT_MOUSE | |
4811 setmouse(); | |
4812 #endif | |
4813 #ifdef FEAT_CLIPBOARD | |
4814 /* Make sure the clipboard gets updated. Needed because start and | |
4815 * end are still the same, and the selection needs to be owned */ | |
4816 clip_star.vmode = NUL; | |
4817 #endif | |
4818 redraw_curbuf_later(INVERTED); | |
4819 showmode(); | |
4820 | |
4821 return OK; | |
4822 } | |
3755 | 4823 |
4824 /* | |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4825 * Check if the pattern is one character long or zero-width. |
11488
9473793c7bb5
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'
Christian Brabandt <cb@256bit.org>
parents:
11478
diff
changeset
|
4826 * If move is TRUE, check from the beginning of the buffer, else from position |
9473793c7bb5
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'
Christian Brabandt <cb@256bit.org>
parents:
11478
diff
changeset
|
4827 * "cur". |
12539
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4828 * "direction" is FORWARD or BACKWARD. |
3755 | 4829 * Returns TRUE, FALSE or -1 for failure. |
4830 */ | |
4831 static int | |
12539
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4832 is_one_char(char_u *pattern, int move, pos_T *cur, int direction) |
3755 | 4833 { |
4834 regmmatch_T regmatch; | |
4835 int nmatched = 0; | |
4836 int result = -1; | |
3778 | 4837 pos_T pos; |
4838 int save_called_emsg = called_emsg; | |
6443 | 4839 int flag = 0; |
3755 | 4840 |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4841 if (pattern == NULL) |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4842 pattern = spats[last_idx].pat; |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4843 |
3755 | 4844 if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH, |
4845 SEARCH_KEEP, ®match) == FAIL) | |
4846 return -1; | |
4847 | |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4848 /* init startcol correctly */ |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4849 regmatch.startpos[0].col = -1; |
3755 | 4850 /* move to match */ |
6443 | 4851 if (move) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4852 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4853 CLEAR_POS(&pos); |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11117
diff
changeset
|
4854 } |
6443 | 4855 else |
4856 { | |
11488
9473793c7bb5
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'
Christian Brabandt <cb@256bit.org>
parents:
11478
diff
changeset
|
4857 pos = *cur; |
6443 | 4858 /* accept a match at the cursor position */ |
4859 flag = SEARCH_START; | |
4860 } | |
4861 | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15091
diff
changeset
|
4862 if (searchit(curwin, curbuf, &pos, NULL, direction, pattern, 1, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
4863 SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL) |
3755 | 4864 { |
4865 /* Zero-width pattern should match somewhere, then we can check if | |
4866 * start and end are in the same position. */ | |
3778 | 4867 called_emsg = FALSE; |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4868 do |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4869 { |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4870 regmatch.startpos[0].col++; |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4871 nmatched = vim_regexec_multi(®match, curwin, curbuf, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11488
diff
changeset
|
4872 pos.lnum, regmatch.startpos[0].col, NULL, NULL); |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4873 if (!nmatched) |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4874 break; |
12539
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4875 } while (direction == FORWARD ? regmatch.startpos[0].col < pos.col |
6d3584b60170
patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4876 : regmatch.startpos[0].col > pos.col); |
3755 | 4877 |
4878 if (!called_emsg) | |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4879 { |
3755 | 4880 result = (nmatched != 0 |
3778 | 4881 && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum |
4882 && regmatch.startpos[0].col == regmatch.endpos[0].col); | |
9647
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4883 /* one char width */ |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4884 if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col) |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4885 result = TRUE; |
847518911c0b
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
8954
diff
changeset
|
4886 } |
3755 | 4887 } |
4888 | |
3778 | 4889 called_emsg |= save_called_emsg; |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
4890 vim_regfree(regmatch.regprog); |
3755 | 4891 return result; |
4892 } | |
3718 | 4893 |
7 | 4894 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(FEAT_TEXTOBJ) \ |
4895 || defined(PROTO) | |
4896 /* | |
4897 * return TRUE if line 'lnum' is empty or has white chars only. | |
4898 */ | |
4899 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4900 linewhite(linenr_T lnum) |
7 | 4901 { |
4902 char_u *p; | |
4903 | |
4904 p = skipwhite(ml_get(lnum)); | |
4905 return (*p == NUL); | |
4906 } | |
4907 #endif | |
4908 | |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4909 /* |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4910 * Add the search count "[3/19]" to "msgbuf". |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4911 */ |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4912 static void |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4913 search_stat( |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4914 int dirc, |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4915 pos_T *pos, |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
4916 int show_top_bot_msg, |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4917 char_u *msgbuf) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4918 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4919 int save_ws = p_ws; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4920 int wraparound = FALSE; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4921 pos_T p = (*pos); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4922 static pos_T lastpos = {0, 0, 0}; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4923 static int cur = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4924 static int cnt = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4925 static int chgtick = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4926 static char_u *lastpat = NULL; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4927 static buf_T *lbuf = NULL; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4928 #ifdef FEAT_RELTIME |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4929 proftime_T start; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4930 #endif |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4931 #define OUT_OF_TIME 999 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4932 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4933 wraparound = ((dirc == '?' && LT_POS(lastpos, p)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4934 || (dirc == '/' && LT_POS(p, lastpos))); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4935 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4936 // If anything relevant changed the count has to be recomputed. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4937 // MB_STRNICMP ignores case, but we should not ignore case. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4938 // Unfortunately, there is no MB_STRNICMP function. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4939 if (!(chgtick == CHANGEDTICK(curbuf) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4940 && MB_STRNICMP(lastpat, spats[last_idx].pat, STRLEN(lastpat)) == 0 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4941 && STRLEN(lastpat) == STRLEN(spats[last_idx].pat) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4942 && EQUAL_POS(lastpos, curwin->w_cursor) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4943 && lbuf == curbuf) || wraparound || cur < 0 || cur > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4944 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4945 cur = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4946 cnt = 0; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4947 CLEAR_POS(&lastpos); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4948 lbuf = curbuf; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4949 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4950 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4951 if (EQUAL_POS(lastpos, curwin->w_cursor) && !wraparound |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4952 && (dirc == '/' ? cur < cnt : cur > 0)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4953 cur += dirc == '/' ? 1 : -1; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4954 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4955 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4956 p_ws = FALSE; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4957 #ifdef FEAT_RELTIME |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4958 profile_setlimit(20L, &start); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4959 #endif |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4960 while (!got_int && searchit(curwin, curbuf, &lastpos, NULL, |
16570
2c2f5f0173c1
patch 8.1.1288: search stats don't show for mapped command
Bram Moolenaar <Bram@vim.org>
parents:
16560
diff
changeset
|
4961 FORWARD, NULL, 1, SEARCH_KEEP, RE_LAST, |
2c2f5f0173c1
patch 8.1.1288: search stats don't show for mapped command
Bram Moolenaar <Bram@vim.org>
parents:
16560
diff
changeset
|
4962 (linenr_T)0, NULL, NULL) != FAIL) |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4963 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4964 #ifdef FEAT_RELTIME |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4965 // Stop after passing the time limit. |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4966 if (profile_passed_limit(&start)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4967 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4968 cnt = OUT_OF_TIME; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4969 cur = OUT_OF_TIME; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4970 break; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4971 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4972 #endif |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4973 cnt++; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4974 if (LTOREQ_POS(lastpos, p)) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4975 cur++; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4976 fast_breakcheck(); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4977 if (cnt > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4978 break; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4979 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4980 if (got_int) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4981 cur = -1; // abort |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4982 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4983 if (cur > 0) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4984 { |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
4985 #define STAT_BUF_LEN 12 |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4986 char t[STAT_BUF_LEN] = ""; |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
4987 int len; |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4988 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4989 #ifdef FEAT_RIGHTLEFT |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4990 if (curwin->w_p_rl && *curwin->w_p_rlc == 's') |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4991 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4992 if (cur == OUT_OF_TIME) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4993 vim_snprintf(t, STAT_BUF_LEN, "[?/??]"); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4994 else if (cnt > 99 && cur > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4995 vim_snprintf(t, STAT_BUF_LEN, "[>99/>99]"); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4996 else if (cnt > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4997 vim_snprintf(t, STAT_BUF_LEN, "[>99/%d]", cur); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4998 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
4999 vim_snprintf(t, STAT_BUF_LEN, "[%d/%d]", cnt, cur); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5000 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5001 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5002 #endif |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5003 { |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5004 if (cur == OUT_OF_TIME) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5005 vim_snprintf(t, STAT_BUF_LEN, "[?/??]"); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5006 else if (cnt > 99 && cur > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5007 vim_snprintf(t, STAT_BUF_LEN, "[>99/>99]"); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5008 else if (cnt > 99) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5009 vim_snprintf(t, STAT_BUF_LEN, "[%d/>99]", cur); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5010 else |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5011 vim_snprintf(t, STAT_BUF_LEN, "[%d/%d]", cur, cnt); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5012 } |
16560
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5013 |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5014 len = STRLEN(t); |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5015 if (show_top_bot_msg && len + 3 < STAT_BUF_LEN) |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5016 { |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5017 STRCPY(t + len, " W"); |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5018 len += 2; |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5019 } |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5020 |
8d0ea09e2d81
patch 8.1.1283: delaying half a second after the top-bot message
Bram Moolenaar <Bram@vim.org>
parents:
16535
diff
changeset
|
5021 mch_memmove(msgbuf + STRLEN(msgbuf) - len, t, len); |
16533
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5022 if (dirc == '?' && cur == 100) |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5023 cur = -1; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5024 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5025 vim_free(lastpat); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5026 lastpat = vim_strsave(spats[last_idx].pat); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5027 chgtick = CHANGEDTICK(curbuf); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5028 lbuf = curbuf; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5029 lastpos = p; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5030 |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5031 // keep the message even after redraw |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5032 give_warning(msgbuf, FALSE); |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5033 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5034 p_ws = save_ws; |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5035 } |
5e25171e0e75
patch 8.1.1270: cannot see current match position
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
5036 |
7 | 5037 #if defined(FEAT_FIND_ID) || defined(PROTO) |
5038 /* | |
5039 * Find identifiers or defines in included files. | |
2719 | 5040 * If p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase. |
7 | 5041 */ |
5042 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5043 find_pattern_in_path( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5044 char_u *ptr, /* pointer to search pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5045 int dir UNUSED, /* direction of expansion */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5046 int len, /* length of search pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5047 int whole, /* match whole words only */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5048 int skip_comments, /* don't match inside comments */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5049 int type, /* Type of search; are we looking for a type? |
7 | 5050 a macro? */ |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5051 long count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5052 int action, /* What to do when we find it */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5053 linenr_T start_lnum, /* first line to start searching */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5054 linenr_T end_lnum) /* last line for searching */ |
7 | 5055 { |
5056 SearchedFile *files; /* Stack of included files */ | |
5057 SearchedFile *bigger; /* When we need more space */ | |
5058 int max_path_depth = 50; | |
5059 long match_count = 1; | |
5060 | |
5061 char_u *pat; | |
5062 char_u *new_fname; | |
5063 char_u *curr_fname = curbuf->b_fname; | |
5064 char_u *prev_fname = NULL; | |
5065 linenr_T lnum; | |
5066 int depth; | |
5067 int depth_displayed; /* For type==CHECK_PATH */ | |
5068 int old_files; | |
5069 int already_searched; | |
5070 char_u *file_line; | |
5071 char_u *line; | |
5072 char_u *p; | |
5073 char_u save_char; | |
5074 int define_matched; | |
5075 regmatch_T regmatch; | |
5076 regmatch_T incl_regmatch; | |
5077 regmatch_T def_regmatch; | |
5078 int matched = FALSE; | |
5079 int did_show = FALSE; | |
5080 int found = FALSE; | |
5081 int i; | |
5082 char_u *already = NULL; | |
5083 char_u *startp = NULL; | |
534 | 5084 char_u *inc_opt = NULL; |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11759
diff
changeset
|
5085 #if defined(FEAT_QUICKFIX) |
7 | 5086 win_T *curwin_save = NULL; |
5087 #endif | |
5088 | |
5089 regmatch.regprog = NULL; | |
5090 incl_regmatch.regprog = NULL; | |
5091 def_regmatch.regprog = NULL; | |
5092 | |
5093 file_line = alloc(LSIZE); | |
5094 if (file_line == NULL) | |
5095 return; | |
5096 | |
5097 if (type != CHECK_PATH && type != FIND_DEFINE | |
5098 #ifdef FEAT_INS_EXPAND | |
5099 /* when CONT_SOL is set compare "ptr" with the beginning of the line | |
5100 * is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo */ | |
449 | 5101 && !(compl_cont_status & CONT_SOL) |
7 | 5102 #endif |
5103 ) | |
5104 { | |
5105 pat = alloc(len + 5); | |
5106 if (pat == NULL) | |
5107 goto fpip_end; | |
5108 sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr); | |
5109 /* ignore case according to p_ic, p_scs and pat */ | |
5110 regmatch.rm_ic = ignorecase(pat); | |
5111 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5112 vim_free(pat); | |
5113 if (regmatch.regprog == NULL) | |
5114 goto fpip_end; | |
5115 } | |
534 | 5116 inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc; |
5117 if (*inc_opt != NUL) | |
7 | 5118 { |
534 | 5119 incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0); |
7 | 5120 if (incl_regmatch.regprog == NULL) |
5121 goto fpip_end; | |
5122 incl_regmatch.rm_ic = FALSE; /* don't ignore case in incl. pat. */ | |
5123 } | |
5124 if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL)) | |
5125 { | |
5126 def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL | |
5127 ? p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0); | |
5128 if (def_regmatch.regprog == NULL) | |
5129 goto fpip_end; | |
5130 def_regmatch.rm_ic = FALSE; /* don't ignore case in define pat. */ | |
5131 } | |
5132 files = (SearchedFile *)lalloc_clear((long_u) | |
5133 (max_path_depth * sizeof(SearchedFile)), TRUE); | |
5134 if (files == NULL) | |
5135 goto fpip_end; | |
5136 old_files = max_path_depth; | |
5137 depth = depth_displayed = -1; | |
5138 | |
5139 lnum = start_lnum; | |
5140 if (end_lnum > curbuf->b_ml.ml_line_count) | |
5141 end_lnum = curbuf->b_ml.ml_line_count; | |
5142 if (lnum > end_lnum) /* do at least one line */ | |
5143 lnum = end_lnum; | |
5144 line = ml_get(lnum); | |
5145 | |
5146 for (;;) | |
5147 { | |
5148 if (incl_regmatch.regprog != NULL | |
5149 && vim_regexec(&incl_regmatch, line, (colnr_T)0)) | |
5150 { | |
534 | 5151 char_u *p_fname = (curr_fname == curbuf->b_fname) |
5152 ? curbuf->b_ffname : curr_fname; | |
5153 | |
5154 if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL) | |
5155 /* Use text from '\zs' to '\ze' (or end) of 'include'. */ | |
5156 new_fname = find_file_name_in_path(incl_regmatch.startp[0], | |
5118
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5157 (int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]), |
534 | 5158 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname); |
5159 else | |
5160 /* Use text after match with 'include'. */ | |
5161 new_fname = file_name_in_line(incl_regmatch.endp[0], 0, | |
681 | 5162 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); |
7 | 5163 already_searched = FALSE; |
5164 if (new_fname != NULL) | |
5165 { | |
5166 /* Check whether we have already searched in this file */ | |
5167 for (i = 0;; i++) | |
5168 { | |
5169 if (i == depth + 1) | |
5170 i = old_files; | |
5171 if (i == max_path_depth) | |
5172 break; | |
5173 if (fullpathcmp(new_fname, files[i].name, TRUE) & FPC_SAME) | |
5174 { | |
5175 if (type != CHECK_PATH && | |
5176 action == ACTION_SHOW_ALL && files[i].matched) | |
5177 { | |
5178 msg_putchar('\n'); /* cursor below last one */ | |
5179 if (!got_int) /* don't display if 'q' | |
5180 typed at "--more--" | |
1859 | 5181 message */ |
7 | 5182 { |
5183 msg_home_replace_hl(new_fname); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5184 msg_puts(_(" (includes previously listed match)")); |
7 | 5185 prev_fname = NULL; |
5186 } | |
5187 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13225
diff
changeset
|
5188 VIM_CLEAR(new_fname); |
7 | 5189 already_searched = TRUE; |
5190 break; | |
5191 } | |
5192 } | |
5193 } | |
5194 | |
5195 if (type == CHECK_PATH && (action == ACTION_SHOW_ALL | |
5196 || (new_fname == NULL && !already_searched))) | |
5197 { | |
5198 if (did_show) | |
5199 msg_putchar('\n'); /* cursor below last one */ | |
5200 else | |
5201 { | |
5202 gotocmdline(TRUE); /* cursor at status line */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5203 msg_puts_title(_("--- Included files ")); |
7 | 5204 if (action != ACTION_SHOW_ALL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5205 msg_puts_title(_("not found ")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5206 msg_puts_title(_("in path ---\n")); |
7 | 5207 } |
5208 did_show = TRUE; | |
5209 while (depth_displayed < depth && !got_int) | |
5210 { | |
5211 ++depth_displayed; | |
5212 for (i = 0; i < depth_displayed; i++) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5213 msg_puts(" "); |
7 | 5214 msg_home_replace(files[depth_displayed].name); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5215 msg_puts(" -->\n"); |
7 | 5216 } |
5217 if (!got_int) /* don't display if 'q' typed | |
5218 for "--more--" message */ | |
5219 { | |
5220 for (i = 0; i <= depth_displayed; i++) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5221 msg_puts(" "); |
7 | 5222 if (new_fname != NULL) |
5223 { | |
5224 /* using "new_fname" is more reliable, e.g., when | |
5225 * 'includeexpr' is set. */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5226 msg_outtrans_attr(new_fname, HL_ATTR(HLF_D)); |
7 | 5227 } |
5228 else | |
5229 { | |
5230 /* | |
5231 * Isolate the file name. | |
5232 * Include the surrounding "" or <> if present. | |
5233 */ | |
3699 | 5234 if (inc_opt != NULL |
5235 && strstr((char *)inc_opt, "\\zs") != NULL) | |
5236 { | |
5237 /* pattern contains \zs, use the match */ | |
5238 p = incl_regmatch.startp[0]; | |
5239 i = (int)(incl_regmatch.endp[0] | |
5240 - incl_regmatch.startp[0]); | |
5241 } | |
5242 else | |
5243 { | |
5244 /* find the file name after the end of the match */ | |
5245 for (p = incl_regmatch.endp[0]; | |
5246 *p && !vim_isfilec(*p); p++) | |
5247 ; | |
5248 for (i = 0; vim_isfilec(p[i]); i++) | |
5249 ; | |
5250 } | |
5251 | |
7 | 5252 if (i == 0) |
5253 { | |
5254 /* Nothing found, use the rest of the line. */ | |
5255 p = incl_regmatch.endp[0]; | |
835 | 5256 i = (int)STRLEN(p); |
7 | 5257 } |
3699 | 5258 /* Avoid checking before the start of the line, can |
5259 * happen if \zs appears in the regexp. */ | |
5260 else if (p > line) | |
7 | 5261 { |
5262 if (p[-1] == '"' || p[-1] == '<') | |
5263 { | |
5264 --p; | |
5265 ++i; | |
5266 } | |
5267 if (p[i] == '"' || p[i] == '>') | |
5268 ++i; | |
5269 } | |
5270 save_char = p[i]; | |
5271 p[i] = NUL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5272 msg_outtrans_attr(p, HL_ATTR(HLF_D)); |
7 | 5273 p[i] = save_char; |
5274 } | |
5275 | |
5276 if (new_fname == NULL && action == ACTION_SHOW_ALL) | |
5277 { | |
5278 if (already_searched) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5279 msg_puts(_(" (Already listed)")); |
7 | 5280 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5281 msg_puts(_(" NOT FOUND")); |
7 | 5282 } |
5283 } | |
5284 out_flush(); /* output each line directly */ | |
5285 } | |
5286 | |
5287 if (new_fname != NULL) | |
5288 { | |
5289 /* Push the new file onto the file stack */ | |
5290 if (depth + 1 == old_files) | |
5291 { | |
5292 bigger = (SearchedFile *)lalloc((long_u)( | |
5293 max_path_depth * 2 * sizeof(SearchedFile)), TRUE); | |
5294 if (bigger != NULL) | |
5295 { | |
5296 for (i = 0; i <= depth; i++) | |
5297 bigger[i] = files[i]; | |
5298 for (i = depth + 1; i < old_files + max_path_depth; i++) | |
5299 { | |
5300 bigger[i].fp = NULL; | |
5301 bigger[i].name = NULL; | |
5302 bigger[i].lnum = 0; | |
5303 bigger[i].matched = FALSE; | |
5304 } | |
5305 for (i = old_files; i < max_path_depth; i++) | |
5306 bigger[i + max_path_depth] = files[i]; | |
5307 old_files += max_path_depth; | |
5308 max_path_depth *= 2; | |
5309 vim_free(files); | |
5310 files = bigger; | |
5311 } | |
5312 } | |
5313 if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r")) | |
5314 == NULL) | |
5315 vim_free(new_fname); | |
5316 else | |
5317 { | |
5318 if (++depth == old_files) | |
5319 { | |
5320 /* | |
5321 * lalloc() for 'bigger' must have failed above. We | |
5322 * will forget one of our already visited files now. | |
5323 */ | |
5324 vim_free(files[old_files].name); | |
5325 ++old_files; | |
5326 } | |
5327 files[depth].name = curr_fname = new_fname; | |
5328 files[depth].lnum = 0; | |
5329 files[depth].matched = FALSE; | |
5330 #ifdef FEAT_INS_EXPAND | |
5331 if (action == ACTION_EXPAND) | |
5332 { | |
1007 | 5333 msg_hist_off = TRUE; /* reset in msg_trunc_attr() */ |
274 | 5334 vim_snprintf((char*)IObuff, IOSIZE, |
5335 _("Scanning included file: %s"), | |
5336 (char *)new_fname); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5337 msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R)); |
7 | 5338 } |
712 | 5339 else |
7 | 5340 #endif |
712 | 5341 if (p_verbose >= 5) |
5342 { | |
5343 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5344 smsg(_("Searching included file %s"), |
712 | 5345 (char *)new_fname); |
5346 verbose_leave(); | |
5347 } | |
5348 | |
7 | 5349 } |
5350 } | |
5351 } | |
5352 else | |
5353 { | |
5354 /* | |
5355 * Check if the line is a define (type == FIND_DEFINE) | |
5356 */ | |
5357 p = line; | |
5358 search_line: | |
5359 define_matched = FALSE; | |
5360 if (def_regmatch.regprog != NULL | |
5361 && vim_regexec(&def_regmatch, line, (colnr_T)0)) | |
5362 { | |
5363 /* | |
5364 * Pattern must be first identifier after 'define', so skip | |
5365 * to that position before checking for match of pattern. Also | |
5366 * don't let it match beyond the end of this identifier. | |
5367 */ | |
5368 p = def_regmatch.endp[0]; | |
5369 while (*p && !vim_iswordc(*p)) | |
5370 p++; | |
5371 define_matched = TRUE; | |
5372 } | |
5373 | |
5374 /* | |
5375 * Look for a match. Don't do this if we are looking for a | |
5376 * define and this line didn't match define_prog above. | |
5377 */ | |
5378 if (def_regmatch.regprog == NULL || define_matched) | |
5379 { | |
5380 if (define_matched | |
5381 #ifdef FEAT_INS_EXPAND | |
449 | 5382 || (compl_cont_status & CONT_SOL) |
7 | 5383 #endif |
5384 ) | |
5385 { | |
5386 /* compare the first "len" chars from "ptr" */ | |
5387 startp = skipwhite(p); | |
5388 if (p_ic) | |
5389 matched = !MB_STRNICMP(startp, ptr, len); | |
5390 else | |
5391 matched = !STRNCMP(startp, ptr, len); | |
5392 if (matched && define_matched && whole | |
5393 && vim_iswordc(startp[len])) | |
5394 matched = FALSE; | |
5395 } | |
5396 else if (regmatch.regprog != NULL | |
5397 && vim_regexec(®match, line, (colnr_T)(p - line))) | |
5398 { | |
5399 matched = TRUE; | |
5400 startp = regmatch.startp[0]; | |
5401 /* | |
5402 * Check if the line is not a comment line (unless we are | |
5403 * looking for a define). A line starting with "# define" | |
5404 * is not considered to be a comment line. | |
5405 */ | |
5406 if (!define_matched && skip_comments) | |
5407 { | |
5408 #ifdef FEAT_COMMENTS | |
5409 if ((*line != '#' || | |
5410 STRNCMP(skipwhite(line + 1), "define", 6) != 0) | |
3562 | 5411 && get_leader_len(line, NULL, FALSE, TRUE)) |
7 | 5412 matched = FALSE; |
5413 | |
5414 /* | |
5415 * Also check for a "/ *" or "/ /" before the match. | |
5416 * Skips lines like "int backwards; / * normal index | |
5417 * * /" when looking for "normal". | |
5418 * Note: Doesn't skip "/ *" in comments. | |
5419 */ | |
5420 p = skipwhite(line); | |
5421 if (matched | |
5422 || (p[0] == '/' && p[1] == '*') || p[0] == '*') | |
5423 #endif | |
5424 for (p = line; *p && p < startp; ++p) | |
5425 { | |
5426 if (matched | |
5427 && p[0] == '/' | |
5428 && (p[1] == '*' || p[1] == '/')) | |
5429 { | |
5430 matched = FALSE; | |
5431 /* After "//" all text is comment */ | |
5432 if (p[1] == '/') | |
5433 break; | |
5434 ++p; | |
5435 } | |
5436 else if (!matched && p[0] == '*' && p[1] == '/') | |
5437 { | |
5438 /* Can find match after "* /". */ | |
5439 matched = TRUE; | |
5440 ++p; | |
5441 } | |
5442 } | |
5443 } | |
5444 } | |
5445 } | |
5446 } | |
5447 if (matched) | |
5448 { | |
5449 #ifdef FEAT_INS_EXPAND | |
5450 if (action == ACTION_EXPAND) | |
5451 { | |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
5452 int cont_s_ipos = FALSE; |
7 | 5453 int add_r; |
5454 char_u *aux; | |
5455 | |
5456 if (depth == -1 && lnum == curwin->w_cursor.lnum) | |
5457 break; | |
5458 found = TRUE; | |
5459 aux = p = startp; | |
449 | 5460 if (compl_cont_status & CONT_ADDING) |
7 | 5461 { |
449 | 5462 p += compl_length; |
7 | 5463 if (vim_iswordp(p)) |
5464 goto exit_matched; | |
5465 p = find_word_start(p); | |
5466 } | |
5467 p = find_word_end(p); | |
5468 i = (int)(p - aux); | |
5469 | |
449 | 5470 if ((compl_cont_status & CONT_ADDING) && i == compl_length) |
7 | 5471 { |
449 | 5472 /* IOSIZE > compl_length, so the STRNCPY works */ |
7 | 5473 STRNCPY(IObuff, aux, i); |
944 | 5474 |
5475 /* Get the next line: when "depth" < 0 from the current | |
5476 * buffer, otherwise from the included file. Jump to | |
5477 * exit_matched when past the last line. */ | |
5478 if (depth < 0) | |
5479 { | |
5480 if (lnum >= end_lnum) | |
5481 goto exit_matched; | |
5482 line = ml_get(++lnum); | |
5483 } | |
5484 else if (vim_fgets(line = file_line, | |
5485 LSIZE, files[depth].fp)) | |
7 | 5486 goto exit_matched; |
5487 | |
5488 /* we read a line, set "already" to check this "line" later | |
5489 * if depth >= 0 we'll increase files[depth].lnum far | |
5490 * bellow -- Acevedo */ | |
5491 already = aux = p = skipwhite(line); | |
5492 p = find_word_start(p); | |
5493 p = find_word_end(p); | |
5494 if (p > aux) | |
5495 { | |
5496 if (*aux != ')' && IObuff[i-1] != TAB) | |
5497 { | |
5498 if (IObuff[i-1] != ' ') | |
5499 IObuff[i++] = ' '; | |
5500 /* IObuf =~ "\(\k\|\i\).* ", thus i >= 2*/ | |
5501 if (p_js | |
5502 && (IObuff[i-2] == '.' | |
5503 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL | |
5504 && (IObuff[i-2] == '?' | |
5505 || IObuff[i-2] == '!')))) | |
5506 IObuff[i++] = ' '; | |
5507 } | |
1859 | 5508 /* copy as much as possible of the new word */ |
7 | 5509 if (p - aux >= IOSIZE - i) |
5510 p = aux + IOSIZE - i - 1; | |
5511 STRNCPY(IObuff + i, aux, p - aux); | |
5512 i += (int)(p - aux); | |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
5513 cont_s_ipos = TRUE; |
7 | 5514 } |
5515 IObuff[i] = NUL; | |
5516 aux = IObuff; | |
5517 | |
449 | 5518 if (i == compl_length) |
7 | 5519 goto exit_matched; |
5520 } | |
5521 | |
942 | 5522 add_r = ins_compl_add_infercase(aux, i, p_ic, |
7 | 5523 curr_fname == curbuf->b_fname ? NULL : curr_fname, |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
5524 dir, cont_s_ipos); |
7 | 5525 if (add_r == OK) |
5526 /* if dir was BACKWARD then honor it just once */ | |
5527 dir = FORWARD; | |
464 | 5528 else if (add_r == FAIL) |
7 | 5529 break; |
5530 } | |
5531 else | |
5532 #endif | |
5533 if (action == ACTION_SHOW_ALL) | |
5534 { | |
5535 found = TRUE; | |
5536 if (!did_show) | |
5537 gotocmdline(TRUE); /* cursor at status line */ | |
5538 if (curr_fname != prev_fname) | |
5539 { | |
5540 if (did_show) | |
5541 msg_putchar('\n'); /* cursor below last one */ | |
5542 if (!got_int) /* don't display if 'q' typed | |
1859 | 5543 at "--more--" message */ |
7 | 5544 msg_home_replace_hl(curr_fname); |
5545 prev_fname = curr_fname; | |
5546 } | |
5547 did_show = TRUE; | |
5548 if (!got_int) | |
5549 show_pat_in_path(line, type, TRUE, action, | |
5550 (depth == -1) ? NULL : files[depth].fp, | |
5551 (depth == -1) ? &lnum : &files[depth].lnum, | |
5552 match_count++); | |
5553 | |
5554 /* Set matched flag for this file and all the ones that | |
5555 * include it */ | |
5556 for (i = 0; i <= depth; ++i) | |
5557 files[i].matched = TRUE; | |
5558 } | |
5559 else if (--count <= 0) | |
5560 { | |
5561 found = TRUE; | |
5562 if (depth == -1 && lnum == curwin->w_cursor.lnum | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11759
diff
changeset
|
5563 #if defined(FEAT_QUICKFIX) |
7 | 5564 && g_do_tagpreview == 0 |
5565 #endif | |
5566 ) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5567 emsg(_("E387: Match is on current line")); |
7 | 5568 else if (action == ACTION_SHOW) |
5569 { | |
5570 show_pat_in_path(line, type, did_show, action, | |
5571 (depth == -1) ? NULL : files[depth].fp, | |
5572 (depth == -1) ? &lnum : &files[depth].lnum, 1L); | |
5573 did_show = TRUE; | |
5574 } | |
5575 else | |
5576 { | |
5577 #ifdef FEAT_GUI | |
5578 need_mouse_correct = TRUE; | |
5579 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11759
diff
changeset
|
5580 #if defined(FEAT_QUICKFIX) |
7 | 5581 /* ":psearch" uses the preview window */ |
5582 if (g_do_tagpreview != 0) | |
5583 { | |
5584 curwin_save = curwin; | |
816 | 5585 prepare_tagpreview(TRUE); |
7 | 5586 } |
5587 #endif | |
5588 if (action == ACTION_SPLIT) | |
5589 { | |
5590 if (win_split(0, 0) == FAIL) | |
5591 break; | |
2583 | 5592 RESET_BINDING(curwin); |
7 | 5593 } |
5594 if (depth == -1) | |
5595 { | |
5596 /* match in current file */ | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11759
diff
changeset
|
5597 #if defined(FEAT_QUICKFIX) |
7 | 5598 if (g_do_tagpreview != 0) |
5599 { | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
5600 if (!GETFILE_SUCCESS(getfile( |
11759
5e36b2f825cb
patch 8.0.0762: ml_get error with :psearch in buffer without a name
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5601 curwin_save->w_buffer->b_fnum, NULL, |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
5602 NULL, TRUE, lnum, FALSE))) |
7 | 5603 break; /* failed to jump to file */ |
5604 } | |
5605 else | |
5606 #endif | |
5607 setpcmark(); | |
5608 curwin->w_cursor.lnum = lnum; | |
11759
5e36b2f825cb
patch 8.0.0762: ml_get error with :psearch in buffer without a name
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5609 check_cursor(); |
7 | 5610 } |
5611 else | |
5612 { | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
5613 if (!GETFILE_SUCCESS(getfile( |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
5614 0, files[depth].name, NULL, TRUE, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11275
diff
changeset
|
5615 files[depth].lnum, FALSE))) |
7 | 5616 break; /* failed to jump to file */ |
5617 /* autocommands may have changed the lnum, we don't | |
5618 * want that here */ | |
5619 curwin->w_cursor.lnum = files[depth].lnum; | |
5620 } | |
5621 } | |
5622 if (action != ACTION_SHOW) | |
5623 { | |
1859 | 5624 curwin->w_cursor.col = (colnr_T)(startp - line); |
7 | 5625 curwin->w_set_curswant = TRUE; |
5626 } | |
5627 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11759
diff
changeset
|
5628 #if defined(FEAT_QUICKFIX) |
7 | 5629 if (g_do_tagpreview != 0 |
673 | 5630 && curwin != curwin_save && win_valid(curwin_save)) |
7 | 5631 { |
5632 /* Return cursor to where we were */ | |
5633 validate_cursor(); | |
5634 redraw_later(VALID); | |
5635 win_enter(curwin_save, TRUE); | |
5636 } | |
5637 #endif | |
5638 break; | |
5639 } | |
5640 #ifdef FEAT_INS_EXPAND | |
5641 exit_matched: | |
5642 #endif | |
5643 matched = FALSE; | |
5644 /* look for other matches in the rest of the line if we | |
5645 * are not at the end of it already */ | |
5646 if (def_regmatch.regprog == NULL | |
5647 #ifdef FEAT_INS_EXPAND | |
5648 && action == ACTION_EXPAND | |
449 | 5649 && !(compl_cont_status & CONT_SOL) |
7 | 5650 #endif |
1859 | 5651 && *startp != NUL |
3693 | 5652 && *(p = startp + MB_PTR2LEN(startp)) != NUL) |
7 | 5653 goto search_line; |
5654 } | |
5655 line_breakcheck(); | |
5656 #ifdef FEAT_INS_EXPAND | |
5657 if (action == ACTION_EXPAND) | |
10277
154d5a2e7395
commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents:
10172
diff
changeset
|
5658 ins_compl_check_keys(30, FALSE); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
15971
diff
changeset
|
5659 if (got_int || ins_compl_interrupted()) |
7 | 5660 #else |
5661 if (got_int) | |
5662 #endif | |
5663 break; | |
5664 | |
5665 /* | |
5666 * Read the next line. When reading an included file and encountering | |
5667 * end-of-file, close the file and continue in the file that included | |
5668 * it. | |
5669 */ | |
5670 while (depth >= 0 && !already | |
5671 && vim_fgets(line = file_line, LSIZE, files[depth].fp)) | |
5672 { | |
5673 fclose(files[depth].fp); | |
5674 --old_files; | |
5675 files[old_files].name = files[depth].name; | |
5676 files[old_files].matched = files[depth].matched; | |
5677 --depth; | |
5678 curr_fname = (depth == -1) ? curbuf->b_fname | |
5679 : files[depth].name; | |
5680 if (depth < depth_displayed) | |
5681 depth_displayed = depth; | |
5682 } | |
5683 if (depth >= 0) /* we could read the line */ | |
5118
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5684 { |
7 | 5685 files[depth].lnum++; |
5118
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5686 /* Remove any CR and LF from the line. */ |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5687 i = (int)STRLEN(line); |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5688 if (i > 0 && line[i - 1] == '\n') |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5689 line[--i] = NUL; |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5690 if (i > 0 && line[i - 1] == '\r') |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5691 line[--i] = NUL; |
5569d11ef585
updated for version 7.3.1302
Bram Moolenaar <bram@vim.org>
parents:
5064
diff
changeset
|
5692 } |
7 | 5693 else if (!already) |
5694 { | |
5695 if (++lnum > end_lnum) | |
5696 break; | |
5697 line = ml_get(lnum); | |
5698 } | |
5699 already = NULL; | |
5700 } | |
5701 /* End of big for (;;) loop. */ | |
5702 | |
5703 /* Close any files that are still open. */ | |
5704 for (i = 0; i <= depth; i++) | |
5705 { | |
5706 fclose(files[i].fp); | |
5707 vim_free(files[i].name); | |
5708 } | |
5709 for (i = old_files; i < max_path_depth; i++) | |
5710 vim_free(files[i].name); | |
5711 vim_free(files); | |
5712 | |
5713 if (type == CHECK_PATH) | |
5714 { | |
5715 if (!did_show) | |
5716 { | |
5717 if (action != ACTION_SHOW_ALL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5718 msg(_("All included files were found")); |
7 | 5719 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5720 msg(_("No included files")); |
7 | 5721 } |
5722 } | |
5723 else if (!found | |
5724 #ifdef FEAT_INS_EXPAND | |
5725 && action != ACTION_EXPAND | |
5726 #endif | |
5727 ) | |
5728 { | |
5729 #ifdef FEAT_INS_EXPAND | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
15971
diff
changeset
|
5730 if (got_int || ins_compl_interrupted()) |
7 | 5731 #else |
5732 if (got_int) | |
5733 #endif | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5734 emsg(_(e_interr)); |
7 | 5735 else if (type == FIND_DEFINE) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5736 emsg(_("E388: Couldn't find definition")); |
7 | 5737 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5738 emsg(_("E389: Couldn't find pattern")); |
7 | 5739 } |
5740 if (action == ACTION_SHOW || action == ACTION_SHOW_ALL) | |
5741 msg_end(); | |
5742 | |
5743 fpip_end: | |
5744 vim_free(file_line); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5745 vim_regfree(regmatch.regprog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5746 vim_regfree(incl_regmatch.regprog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5747 vim_regfree(def_regmatch.regprog); |
7 | 5748 } |
5749 | |
5750 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5751 show_pat_in_path( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5752 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5753 int type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5754 int did_show, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5755 int action, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5756 FILE *fp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5757 linenr_T *lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5758 long count) |
7 | 5759 { |
5760 char_u *p; | |
5761 | |
5762 if (did_show) | |
5763 msg_putchar('\n'); /* cursor below last one */ | |
867 | 5764 else if (!msg_silent) |
7 | 5765 gotocmdline(TRUE); /* cursor at status line */ |
5766 if (got_int) /* 'q' typed at "--more--" message */ | |
5767 return; | |
5768 for (;;) | |
5769 { | |
5770 p = line + STRLEN(line) - 1; | |
5771 if (fp != NULL) | |
5772 { | |
5773 /* We used fgets(), so get rid of newline at end */ | |
5774 if (p >= line && *p == '\n') | |
5775 --p; | |
5776 if (p >= line && *p == '\r') | |
5777 --p; | |
5778 *(p + 1) = NUL; | |
5779 } | |
5780 if (action == ACTION_SHOW_ALL) | |
5781 { | |
5782 sprintf((char *)IObuff, "%3ld: ", count); /* show match nr */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5783 msg_puts((char *)IObuff); |
7 | 5784 sprintf((char *)IObuff, "%4ld", *lnum); /* show line nr */ |
5785 /* Highlight line numbers */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5786 msg_puts_attr((char *)IObuff, HL_ATTR(HLF_N)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5787 msg_puts(" "); |
7 | 5788 } |
168 | 5789 msg_prt_line(line, FALSE); |
7 | 5790 out_flush(); /* show one line at a time */ |
5791 | |
5792 /* Definition continues until line that doesn't end with '\' */ | |
5793 if (got_int || type != FIND_DEFINE || p < line || *p != '\\') | |
5794 break; | |
5795 | |
5796 if (fp != NULL) | |
5797 { | |
5798 if (vim_fgets(line, LSIZE, fp)) /* end of file */ | |
5799 break; | |
5800 ++*lnum; | |
5801 } | |
5802 else | |
5803 { | |
5804 if (++*lnum > curbuf->b_ml.ml_line_count) | |
5805 break; | |
5806 line = ml_get(*lnum); | |
5807 } | |
5808 msg_putchar('\n'); | |
5809 } | |
5810 } | |
5811 #endif | |
5812 | |
5813 #ifdef FEAT_VIMINFO | |
5814 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5815 read_viminfo_search_pattern(vir_T *virp, int force) |
7 | 5816 { |
5817 char_u *lp; | |
5818 int idx = -1; | |
5819 int magic = FALSE; | |
5820 int no_scs = FALSE; | |
5821 int off_line = FALSE; | |
572 | 5822 int off_end = 0; |
7 | 5823 long off = 0; |
5824 int setlast = FALSE; | |
5825 #ifdef FEAT_SEARCH_EXTRA | |
5826 static int hlsearch_on = FALSE; | |
5827 #endif | |
5828 char_u *val; | |
5829 | |
5830 /* | |
5831 * Old line types: | |
5832 * "/pat", "&pat": search/subst. pat | |
5833 * "~/pat", "~&pat": last used search/subst. pat | |
5834 * New line types: | |
5835 * "~h", "~H": hlsearch highlighting off/on | |
5836 * "~<magic><smartcase><line><end><off><last><which>pat" | |
5837 * <magic>: 'm' off, 'M' on | |
5838 * <smartcase>: 's' off, 'S' on | |
5839 * <line>: 'L' line offset, 'l' char offset | |
5840 * <end>: 'E' from end, 'e' from start | |
5841 * <off>: decimal, offset | |
5842 * <last>: '~' last used pattern | |
5843 * <which>: '/' search pat, '&' subst. pat | |
5844 */ | |
5845 lp = virp->vir_line; | |
5846 if (lp[0] == '~' && (lp[1] == 'm' || lp[1] == 'M')) /* new line type */ | |
5847 { | |
5848 if (lp[1] == 'M') /* magic on */ | |
5849 magic = TRUE; | |
5850 if (lp[2] == 's') | |
5851 no_scs = TRUE; | |
5852 if (lp[3] == 'L') | |
5853 off_line = TRUE; | |
5854 if (lp[4] == 'E') | |
8 | 5855 off_end = SEARCH_END; |
7 | 5856 lp += 5; |
5857 off = getdigits(&lp); | |
5858 } | |
5859 if (lp[0] == '~') /* use this pattern for last-used pattern */ | |
5860 { | |
5861 setlast = TRUE; | |
5862 lp++; | |
5863 } | |
5864 if (lp[0] == '/') | |
5865 idx = RE_SEARCH; | |
5866 else if (lp[0] == '&') | |
5867 idx = RE_SUBST; | |
5868 #ifdef FEAT_SEARCH_EXTRA | |
5869 else if (lp[0] == 'h') /* ~h: 'hlsearch' highlighting off */ | |
5870 hlsearch_on = FALSE; | |
5871 else if (lp[0] == 'H') /* ~H: 'hlsearch' highlighting on */ | |
5872 hlsearch_on = TRUE; | |
5873 #endif | |
5874 if (idx >= 0) | |
5875 { | |
5876 if (force || spats[idx].pat == NULL) | |
5877 { | |
5878 val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), | |
5879 TRUE); | |
5880 if (val != NULL) | |
5881 { | |
5882 set_last_search_pat(val, idx, magic, setlast); | |
5883 vim_free(val); | |
5884 spats[idx].no_scs = no_scs; | |
5885 spats[idx].off.line = off_line; | |
5886 spats[idx].off.end = off_end; | |
5887 spats[idx].off.off = off; | |
5888 #ifdef FEAT_SEARCH_EXTRA | |
5889 if (setlast) | |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5890 set_no_hlsearch(!hlsearch_on); |
7 | 5891 #endif |
5892 } | |
5893 } | |
5894 } | |
5895 return viminfo_readline(virp); | |
5896 } | |
5897 | |
5898 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5899 write_viminfo_search_pattern(FILE *fp) |
7 | 5900 { |
5901 if (get_viminfo_parameter('/') != 0) | |
5902 { | |
5903 #ifdef FEAT_SEARCH_EXTRA | |
5904 fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c", | |
5905 (no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H'); | |
5906 #endif | |
5907 wvsp_one(fp, RE_SEARCH, "", '/'); | |
1675 | 5908 wvsp_one(fp, RE_SUBST, _("Substitute "), '&'); |
7 | 5909 } |
5910 } | |
5911 | |
5912 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5913 wvsp_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5914 FILE *fp, /* file to write to */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5915 int idx, /* spats[] index */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5916 char *s, /* search pat */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5917 int sc) /* dir char */ |
7 | 5918 { |
5919 if (spats[idx].pat != NULL) | |
5920 { | |
835 | 5921 fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s); |
7 | 5922 /* off.dir is not stored, it's reset to forward */ |
5923 fprintf(fp, "%c%c%c%c%ld%s%c", | |
5924 spats[idx].magic ? 'M' : 'm', /* magic */ | |
5925 spats[idx].no_scs ? 's' : 'S', /* smartcase */ | |
5926 spats[idx].off.line ? 'L' : 'l', /* line offset */ | |
5927 spats[idx].off.end ? 'E' : 'e', /* offset from end */ | |
5928 spats[idx].off.off, /* offset */ | |
5929 last_idx == idx ? "~" : "", /* last used pat */ | |
5930 sc); | |
5931 viminfo_writestring(fp, spats[idx].pat); | |
5932 } | |
5933 } | |
5934 #endif /* FEAT_VIMINFO */ |