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