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