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