7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
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 /*
|
|
11 * ex_getln.c: Functions for entering and editing an Ex command line.
|
|
12 */
|
|
13
|
|
14 #include "vim.h"
|
|
15
|
|
16 /*
|
|
17 * Variables shared between getcmdline(), redrawcmdline() and others.
|
|
18 * These need to be saved when using CTRL-R |, that's why they are in a
|
|
19 * structure.
|
|
20 */
|
|
21 struct cmdline_info
|
|
22 {
|
|
23 char_u *cmdbuff; /* pointer to command line buffer */
|
|
24 int cmdbufflen; /* length of cmdbuff */
|
|
25 int cmdlen; /* number of chars in command line */
|
|
26 int cmdpos; /* current cursor position */
|
|
27 int cmdspos; /* cursor column on screen */
|
|
28 int cmdfirstc; /* ':', '/', '?', '=' or NUL */
|
|
29 int cmdindent; /* number of spaces before cmdline */
|
|
30 char_u *cmdprompt; /* message in front of cmdline */
|
|
31 int cmdattr; /* attributes for prompt */
|
|
32 int overstrike; /* Typing mode on the command line. Shared by
|
|
33 getcmdline() and put_on_cmdline(). */
|
531
|
34 int xp_context; /* type of expansion */
|
|
35 # ifdef FEAT_EVAL
|
|
36 char_u *xp_arg; /* user-defined expansion arg */
|
1039
|
37 int input_fn; /* when TRUE Invoked for input() function */
|
531
|
38 # endif
|
7
|
39 };
|
|
40
|
|
41 static struct cmdline_info ccline; /* current cmdline_info */
|
|
42
|
|
43 static int cmd_showtail; /* Only show path tail in lists ? */
|
|
44
|
|
45 #ifdef FEAT_EVAL
|
|
46 static int new_cmdpos; /* position set by set_cmdline_pos() */
|
|
47 #endif
|
|
48
|
|
49 #ifdef FEAT_CMDHIST
|
|
50 typedef struct hist_entry
|
|
51 {
|
|
52 int hisnum; /* identifying number */
|
|
53 char_u *hisstr; /* actual entry, separator char after the NUL */
|
|
54 } histentry_T;
|
|
55
|
|
56 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
|
|
57 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */
|
|
58 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0};
|
|
59 /* identifying (unique) number of newest history entry */
|
|
60 static int hislen = 0; /* actual length of history tables */
|
|
61
|
|
62 static int hist_char2type __ARGS((int c));
|
|
63
|
|
64 static int in_history __ARGS((int, char_u *, int));
|
|
65 # ifdef FEAT_EVAL
|
|
66 static int calc_hist_idx __ARGS((int histype, int num));
|
|
67 # endif
|
|
68 #endif
|
|
69
|
|
70 #ifdef FEAT_RIGHTLEFT
|
|
71 static int cmd_hkmap = 0; /* Hebrew mapping during command line */
|
|
72 #endif
|
|
73
|
|
74 #ifdef FEAT_FKMAP
|
|
75 static int cmd_fkmap = 0; /* Farsi mapping during command line */
|
|
76 #endif
|
|
77
|
|
78 static int cmdline_charsize __ARGS((int idx));
|
|
79 static void set_cmdspos __ARGS((void));
|
|
80 static void set_cmdspos_cursor __ARGS((void));
|
|
81 #ifdef FEAT_MBYTE
|
|
82 static void correct_cmdspos __ARGS((int idx, int cells));
|
|
83 #endif
|
|
84 static void alloc_cmdbuff __ARGS((int len));
|
|
85 static int realloc_cmdbuff __ARGS((int len));
|
|
86 static void draw_cmdline __ARGS((int start, int len));
|
95
|
87 static void save_cmdline __ARGS((struct cmdline_info *ccp));
|
|
88 static void restore_cmdline __ARGS((struct cmdline_info *ccp));
|
1015
|
89 static int cmdline_paste __ARGS((int regname, int literally, int remcr));
|
7
|
90 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|
|
91 static void redrawcmd_preedit __ARGS((void));
|
|
92 #endif
|
|
93 #ifdef FEAT_WILDMENU
|
|
94 static void cmdline_del __ARGS((int from));
|
|
95 #endif
|
|
96 static void redrawcmdprompt __ARGS((void));
|
|
97 static void cursorcmd __ARGS((void));
|
|
98 static int ccheck_abbr __ARGS((int));
|
|
99 static int nextwild __ARGS((expand_T *xp, int type, int options));
|
435
|
100 static void escape_fname __ARGS((char_u **pp));
|
7
|
101 static int showmatches __ARGS((expand_T *xp, int wildmenu));
|
|
102 static void set_expand_context __ARGS((expand_T *xp));
|
|
103 static int ExpandFromContext __ARGS((expand_T *xp, char_u *, int *, char_u ***, int));
|
|
104 static int expand_showtail __ARGS((expand_T *xp));
|
|
105 #ifdef FEAT_CMDL_COMPL
|
716
|
106 static int expand_shellcmd __ARGS((char_u *filepat, int *num_file, char_u ***file, int flagsarg));
|
7
|
107 static int ExpandRTDir __ARGS((char_u *pat, int *num_file, char_u ***file, char *dirname));
|
|
108 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
|
|
109 static int ExpandUserDefined __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file));
|
407
|
110 static int ExpandUserList __ARGS((expand_T *xp, int *num_file, char_u ***file));
|
7
|
111 # endif
|
|
112 #endif
|
|
113
|
|
114 #ifdef FEAT_CMDWIN
|
|
115 static int ex_window __ARGS((void));
|
|
116 #endif
|
|
117
|
|
118 /*
|
|
119 * getcmdline() - accept a command line starting with firstc.
|
|
120 *
|
|
121 * firstc == ':' get ":" command line.
|
|
122 * firstc == '/' or '?' get search pattern
|
|
123 * firstc == '=' get expression
|
|
124 * firstc == '@' get text for input() function
|
|
125 * firstc == '>' get text for debug mode
|
|
126 * firstc == NUL get text for :insert command
|
|
127 * firstc == -1 like NUL, and break on CTRL-C
|
|
128 *
|
|
129 * The line is collected in ccline.cmdbuff, which is reallocated to fit the
|
|
130 * command line.
|
|
131 *
|
|
132 * Careful: getcmdline() can be called recursively!
|
|
133 *
|
|
134 * Return pointer to allocated string if there is a commandline, NULL
|
|
135 * otherwise.
|
|
136 */
|
|
137 /*ARGSUSED*/
|
|
138 char_u *
|
|
139 getcmdline(firstc, count, indent)
|
|
140 int firstc;
|
|
141 long count; /* only used for incremental search */
|
|
142 int indent; /* indent for inside conditionals */
|
|
143 {
|
|
144 int c;
|
|
145 int i;
|
|
146 int j;
|
|
147 int gotesc = FALSE; /* TRUE when <ESC> just typed */
|
|
148 int do_abbr; /* when TRUE check for abbr. */
|
|
149 #ifdef FEAT_CMDHIST
|
|
150 char_u *lookfor = NULL; /* string to match */
|
|
151 int hiscnt; /* current history line in use */
|
|
152 int histype; /* history type to be used */
|
|
153 #endif
|
|
154 #ifdef FEAT_SEARCH_EXTRA
|
|
155 pos_T old_cursor;
|
|
156 colnr_T old_curswant;
|
|
157 colnr_T old_leftcol;
|
|
158 linenr_T old_topline;
|
|
159 # ifdef FEAT_DIFF
|
|
160 int old_topfill;
|
|
161 # endif
|
|
162 linenr_T old_botline;
|
|
163 int did_incsearch = FALSE;
|
|
164 int incsearch_postponed = FALSE;
|
|
165 #endif
|
|
166 int did_wild_list = FALSE; /* did wild_list() recently */
|
|
167 int wim_index = 0; /* index in wim_flags[] */
|
|
168 int res;
|
|
169 int save_msg_scroll = msg_scroll;
|
|
170 int save_State = State; /* remember State when called */
|
|
171 int some_key_typed = FALSE; /* one of the keys was typed */
|
|
172 #ifdef FEAT_MOUSE
|
|
173 /* mouse drag and release events are ignored, unless they are
|
|
174 * preceded with a mouse down event */
|
|
175 int ignore_drag_release = TRUE;
|
|
176 #endif
|
|
177 #ifdef FEAT_EVAL
|
|
178 int break_ctrl_c = FALSE;
|
|
179 #endif
|
|
180 expand_T xpc;
|
|
181 long *b_im_ptr = NULL;
|
195
|
182 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) || defined(FEAT_SEARCH_EXTRA)
|
|
183 /* Everything that may work recursively should save and restore the
|
|
184 * current command line in save_ccline. That includes update_screen(), a
|
|
185 * custom status line may invoke ":normal". */
|
|
186 struct cmdline_info save_ccline;
|
|
187 #endif
|
7
|
188
|
|
189 #ifdef FEAT_SNIFF
|
|
190 want_sniff_request = 0;
|
|
191 #endif
|
|
192 #ifdef FEAT_EVAL
|
|
193 if (firstc == -1)
|
|
194 {
|
|
195 firstc = NUL;
|
|
196 break_ctrl_c = TRUE;
|
|
197 }
|
|
198 #endif
|
|
199 #ifdef FEAT_RIGHTLEFT
|
|
200 /* start without Hebrew mapping for a command line */
|
|
201 if (firstc == ':' || firstc == '=' || firstc == '>')
|
|
202 cmd_hkmap = 0;
|
|
203 #endif
|
|
204
|
|
205 ccline.overstrike = FALSE; /* always start in insert mode */
|
|
206 #ifdef FEAT_SEARCH_EXTRA
|
|
207 old_cursor = curwin->w_cursor; /* needs to be restored later */
|
|
208 old_curswant = curwin->w_curswant;
|
|
209 old_leftcol = curwin->w_leftcol;
|
|
210 old_topline = curwin->w_topline;
|
|
211 # ifdef FEAT_DIFF
|
|
212 old_topfill = curwin->w_topfill;
|
|
213 # endif
|
|
214 old_botline = curwin->w_botline;
|
|
215 #endif
|
|
216
|
|
217 /*
|
|
218 * set some variables for redrawcmd()
|
|
219 */
|
|
220 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc);
|
164
|
221 ccline.cmdindent = (firstc > 0 ? indent : 0);
|
|
222
|
|
223 /* alloc initial ccline.cmdbuff */
|
|
224 alloc_cmdbuff(exmode_active ? 250 : indent + 1);
|
7
|
225 if (ccline.cmdbuff == NULL)
|
|
226 return NULL; /* out of memory */
|
|
227 ccline.cmdlen = ccline.cmdpos = 0;
|
|
228 ccline.cmdbuff[0] = NUL;
|
|
229
|
164
|
230 /* autoindent for :insert and :append */
|
|
231 if (firstc <= 0)
|
|
232 {
|
|
233 copy_spaces(ccline.cmdbuff, indent);
|
|
234 ccline.cmdbuff[indent] = NUL;
|
|
235 ccline.cmdpos = indent;
|
|
236 ccline.cmdspos = indent;
|
|
237 ccline.cmdlen = indent;
|
|
238 }
|
|
239
|
7
|
240 ExpandInit(&xpc);
|
|
241
|
|
242 #ifdef FEAT_RIGHTLEFT
|
|
243 if (curwin->w_p_rl && *curwin->w_p_rlc == 's'
|
|
244 && (firstc == '/' || firstc == '?'))
|
|
245 cmdmsg_rl = TRUE;
|
|
246 else
|
|
247 cmdmsg_rl = FALSE;
|
|
248 #endif
|
|
249
|
|
250 redir_off = TRUE; /* don't redirect the typed command */
|
|
251 if (!cmd_silent)
|
|
252 {
|
|
253 i = msg_scrolled;
|
|
254 msg_scrolled = 0; /* avoid wait_return message */
|
|
255 gotocmdline(TRUE);
|
|
256 msg_scrolled += i;
|
|
257 redrawcmdprompt(); /* draw prompt or indent */
|
|
258 set_cmdspos();
|
|
259 }
|
|
260 xpc.xp_context = EXPAND_NOTHING;
|
|
261 xpc.xp_backslash = XP_BS_NONE;
|
632
|
262 #ifndef BACKSLASH_IN_FILENAME
|
|
263 xpc.xp_shell = FALSE;
|
|
264 #endif
|
7
|
265
|
531
|
266 #if defined(FEAT_EVAL)
|
|
267 if (ccline.input_fn)
|
|
268 {
|
|
269 xpc.xp_context = ccline.xp_context;
|
|
270 xpc.xp_pattern = ccline.cmdbuff;
|
1322
|
271 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
|
531
|
272 xpc.xp_arg = ccline.xp_arg;
|
1322
|
273 # endif
|
531
|
274 }
|
|
275 #endif
|
|
276
|
7
|
277 /*
|
|
278 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when
|
|
279 * doing ":@0" when register 0 doesn't contain a CR.
|
|
280 */
|
|
281 msg_scroll = FALSE;
|
|
282
|
|
283 State = CMDLINE;
|
|
284
|
|
285 if (firstc == '/' || firstc == '?' || firstc == '@')
|
|
286 {
|
|
287 /* Use ":lmap" mappings for search pattern and input(). */
|
|
288 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT)
|
|
289 b_im_ptr = &curbuf->b_p_iminsert;
|
|
290 else
|
|
291 b_im_ptr = &curbuf->b_p_imsearch;
|
|
292 if (*b_im_ptr == B_IMODE_LMAP)
|
|
293 State |= LANGMAP;
|
|
294 #ifdef USE_IM_CONTROL
|
|
295 im_set_active(*b_im_ptr == B_IMODE_IM);
|
|
296 #endif
|
|
297 }
|
|
298 #ifdef USE_IM_CONTROL
|
|
299 else if (p_imcmdline)
|
|
300 im_set_active(TRUE);
|
|
301 #endif
|
|
302
|
|
303 #ifdef FEAT_MOUSE
|
|
304 setmouse();
|
|
305 #endif
|
|
306 #ifdef CURSOR_SHAPE
|
|
307 ui_cursor_shape(); /* may show different cursor shape */
|
|
308 #endif
|
|
309
|
571
|
310 /* When inside an autocommand for writing "exiting" may be set and
|
|
311 * terminal mode set to cooked. Need to set raw mode here then. */
|
|
312 settmode(TMODE_RAW);
|
|
313
|
7
|
314 #ifdef FEAT_CMDHIST
|
|
315 init_history();
|
|
316 hiscnt = hislen; /* set hiscnt to impossible history value */
|
|
317 histype = hist_char2type(firstc);
|
|
318 #endif
|
|
319
|
|
320 #ifdef FEAT_DIGRAPHS
|
|
321 do_digraph(-1); /* init digraph typahead */
|
|
322 #endif
|
|
323
|
|
324 /*
|
|
325 * Collect the command string, handling editing keys.
|
|
326 */
|
|
327 for (;;)
|
|
328 {
|
972
|
329 redir_off = TRUE; /* Don't redirect the typed command.
|
|
330 Repeated, because a ":redir" inside
|
|
331 completion may switch it on. */
|
7
|
332 #ifdef USE_ON_FLY_SCROLL
|
|
333 dont_scroll = FALSE; /* allow scrolling here */
|
|
334 #endif
|
|
335 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */
|
|
336
|
|
337 cursorcmd(); /* set the cursor on the right spot */
|
1472
|
338
|
|
339 /* Get a character. Ignore K_IGNORE, it should not do anything, such
|
|
340 * as stop completion. */
|
|
341 do
|
|
342 {
|
|
343 c = safe_vgetc();
|
|
344 } while (c == K_IGNORE);
|
|
345
|
7
|
346 if (KeyTyped)
|
|
347 {
|
|
348 some_key_typed = TRUE;
|
|
349 #ifdef FEAT_RIGHTLEFT
|
|
350 if (cmd_hkmap)
|
|
351 c = hkmap(c);
|
|
352 # ifdef FEAT_FKMAP
|
|
353 if (cmd_fkmap)
|
|
354 c = cmdl_fkmap(c);
|
|
355 # endif
|
|
356 if (cmdmsg_rl && !KeyStuffed)
|
|
357 {
|
|
358 /* Invert horizontal movements and operations. Only when
|
|
359 * typed by the user directly, not when the result of a
|
|
360 * mapping. */
|
|
361 switch (c)
|
|
362 {
|
|
363 case K_RIGHT: c = K_LEFT; break;
|
|
364 case K_S_RIGHT: c = K_S_LEFT; break;
|
|
365 case K_C_RIGHT: c = K_C_LEFT; break;
|
|
366 case K_LEFT: c = K_RIGHT; break;
|
|
367 case K_S_LEFT: c = K_S_RIGHT; break;
|
|
368 case K_C_LEFT: c = K_C_RIGHT; break;
|
|
369 }
|
|
370 }
|
|
371 #endif
|
|
372 }
|
|
373
|
|
374 /*
|
|
375 * Ignore got_int when CTRL-C was typed here.
|
|
376 * Don't ignore it in :global, we really need to break then, e.g., for
|
|
377 * ":g/pat/normal /pat" (without the <CR>).
|
|
378 * Don't ignore it for the input() function.
|
|
379 */
|
|
380 if ((c == Ctrl_C
|
|
381 #ifdef UNIX
|
|
382 || c == intr_char
|
|
383 #endif
|
|
384 )
|
|
385 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT)
|
|
386 && firstc != '@'
|
|
387 #endif
|
|
388 #ifdef FEAT_EVAL
|
|
389 && !break_ctrl_c
|
|
390 #endif
|
|
391 && !global_busy)
|
|
392 got_int = FALSE;
|
|
393
|
|
394 #ifdef FEAT_CMDHIST
|
|
395 /* free old command line when finished moving around in the history
|
|
396 * list */
|
|
397 if (lookfor != NULL
|
180
|
398 && c != K_S_DOWN && c != K_S_UP
|
230
|
399 && c != K_DOWN && c != K_UP
|
7
|
400 && c != K_PAGEDOWN && c != K_PAGEUP
|
|
401 && c != K_KPAGEDOWN && c != K_KPAGEUP
|
230
|
402 && c != K_LEFT && c != K_RIGHT
|
7
|
403 && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N)))
|
|
404 {
|
|
405 vim_free(lookfor);
|
|
406 lookfor = NULL;
|
|
407 }
|
|
408 #endif
|
|
409
|
|
410 /*
|
|
411 * <S-Tab> works like CTRL-P (unless 'wc' is <S-Tab>).
|
|
412 */
|
|
413 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles != -1)
|
|
414 c = Ctrl_P;
|
|
415
|
|
416 #ifdef FEAT_WILDMENU
|
|
417 /* Special translations for 'wildmenu' */
|
|
418 if (did_wild_list && p_wmnu)
|
|
419 {
|
230
|
420 if (c == K_LEFT)
|
7
|
421 c = Ctrl_P;
|
230
|
422 else if (c == K_RIGHT)
|
7
|
423 c = Ctrl_N;
|
|
424 }
|
|
425 /* Hitting CR after "emenu Name.": complete submenu */
|
|
426 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu
|
|
427 && ccline.cmdpos > 1
|
|
428 && ccline.cmdbuff[ccline.cmdpos - 1] == '.'
|
|
429 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\'
|
|
430 && (c == '\n' || c == '\r' || c == K_KENTER))
|
|
431 c = K_DOWN;
|
|
432 #endif
|
|
433
|
|
434 /* free expanded names when finished walking through matches */
|
|
435 if (xpc.xp_numfiles != -1
|
|
436 && !(c == p_wc && KeyTyped) && c != p_wcm
|
|
437 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A
|
|
438 && c != Ctrl_L)
|
|
439 {
|
|
440 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE);
|
|
441 did_wild_list = FALSE;
|
|
442 #ifdef FEAT_WILDMENU
|
230
|
443 if (!p_wmnu || (c != K_UP && c != K_DOWN))
|
7
|
444 #endif
|
|
445 xpc.xp_context = EXPAND_NOTHING;
|
|
446 wim_index = 0;
|
|
447 #ifdef FEAT_WILDMENU
|
|
448 if (p_wmnu && wild_menu_showing != 0)
|
|
449 {
|
|
450 int skt = KeyTyped;
|
532
|
451 int old_RedrawingDisabled = RedrawingDisabled;
|
531
|
452
|
|
453 if (ccline.input_fn)
|
|
454 RedrawingDisabled = 0;
|
7
|
455
|
|
456 if (wild_menu_showing == WM_SCROLLED)
|
|
457 {
|
|
458 /* Entered command line, move it up */
|
|
459 cmdline_row--;
|
|
460 redrawcmd();
|
|
461 }
|
|
462 else if (save_p_ls != -1)
|
|
463 {
|
|
464 /* restore 'laststatus' and 'winminheight' */
|
|
465 p_ls = save_p_ls;
|
|
466 p_wmh = save_p_wmh;
|
|
467 last_status(FALSE);
|
195
|
468 save_cmdline(&save_ccline);
|
7
|
469 update_screen(VALID); /* redraw the screen NOW */
|
195
|
470 restore_cmdline(&save_ccline);
|
7
|
471 redrawcmd();
|
|
472 save_p_ls = -1;
|
|
473 }
|
|
474 else
|
|
475 {
|
|
476 # ifdef FEAT_VERTSPLIT
|
|
477 win_redraw_last_status(topframe);
|
|
478 # else
|
|
479 lastwin->w_redr_status = TRUE;
|
|
480 # endif
|
|
481 redraw_statuslines();
|
|
482 }
|
532
|
483 KeyTyped = skt;
|
|
484 wild_menu_showing = 0;
|
531
|
485 if (ccline.input_fn)
|
|
486 RedrawingDisabled = old_RedrawingDisabled;
|
7
|
487 }
|
|
488 #endif
|
|
489 }
|
|
490
|
|
491 #ifdef FEAT_WILDMENU
|
|
492 /* Special translations for 'wildmenu' */
|
|
493 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu)
|
|
494 {
|
|
495 /* Hitting <Down> after "emenu Name.": complete submenu */
|
1318
|
496 if (c == K_DOWN && ccline.cmdpos > 0
|
|
497 && ccline.cmdbuff[ccline.cmdpos - 1] == '.')
|
7
|
498 c = p_wc;
|
230
|
499 else if (c == K_UP)
|
7
|
500 {
|
|
501 /* Hitting <Up>: Remove one submenu name in front of the
|
|
502 * cursor */
|
|
503 int found = FALSE;
|
|
504
|
|
505 j = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
506 i = 0;
|
|
507 while (--j > 0)
|
|
508 {
|
|
509 /* check for start of menu name */
|
|
510 if (ccline.cmdbuff[j] == ' '
|
|
511 && ccline.cmdbuff[j - 1] != '\\')
|
|
512 {
|
|
513 i = j + 1;
|
|
514 break;
|
|
515 }
|
|
516 /* check for start of submenu name */
|
|
517 if (ccline.cmdbuff[j] == '.'
|
|
518 && ccline.cmdbuff[j - 1] != '\\')
|
|
519 {
|
|
520 if (found)
|
|
521 {
|
|
522 i = j + 1;
|
|
523 break;
|
|
524 }
|
|
525 else
|
|
526 found = TRUE;
|
|
527 }
|
|
528 }
|
|
529 if (i > 0)
|
|
530 cmdline_del(i);
|
|
531 c = p_wc;
|
|
532 xpc.xp_context = EXPAND_NOTHING;
|
|
533 }
|
|
534 }
|
714
|
535 if ((xpc.xp_context == EXPAND_FILES
|
|
536 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu)
|
7
|
537 {
|
|
538 char_u upseg[5];
|
|
539
|
|
540 upseg[0] = PATHSEP;
|
|
541 upseg[1] = '.';
|
|
542 upseg[2] = '.';
|
|
543 upseg[3] = PATHSEP;
|
|
544 upseg[4] = NUL;
|
|
545
|
1318
|
546 if (c == K_DOWN
|
|
547 && ccline.cmdpos > 0
|
|
548 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP
|
|
549 && (ccline.cmdpos < 3
|
|
550 || ccline.cmdbuff[ccline.cmdpos - 2] != '.'
|
7
|
551 || ccline.cmdbuff[ccline.cmdpos - 3] != '.'))
|
|
552 {
|
|
553 /* go down a directory */
|
|
554 c = p_wc;
|
|
555 }
|
230
|
556 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN)
|
7
|
557 {
|
|
558 /* If in a direct ancestor, strip off one ../ to go down */
|
|
559 int found = FALSE;
|
|
560
|
|
561 j = ccline.cmdpos;
|
|
562 i = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
563 while (--j > i)
|
|
564 {
|
39
|
565 #ifdef FEAT_MBYTE
|
|
566 if (has_mbyte)
|
|
567 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
|
|
568 #endif
|
7
|
569 if (vim_ispathsep(ccline.cmdbuff[j]))
|
|
570 {
|
|
571 found = TRUE;
|
|
572 break;
|
|
573 }
|
|
574 }
|
|
575 if (found
|
|
576 && ccline.cmdbuff[j - 1] == '.'
|
|
577 && ccline.cmdbuff[j - 2] == '.'
|
|
578 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2))
|
|
579 {
|
|
580 cmdline_del(j - 2);
|
|
581 c = p_wc;
|
|
582 }
|
|
583 }
|
230
|
584 else if (c == K_UP)
|
7
|
585 {
|
|
586 /* go up a directory */
|
|
587 int found = FALSE;
|
|
588
|
|
589 j = ccline.cmdpos - 1;
|
|
590 i = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
591 while (--j > i)
|
|
592 {
|
|
593 #ifdef FEAT_MBYTE
|
|
594 if (has_mbyte)
|
|
595 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
|
|
596 #endif
|
|
597 if (vim_ispathsep(ccline.cmdbuff[j])
|
|
598 #ifdef BACKSLASH_IN_FILENAME
|
|
599 && vim_strchr(" *?[{`$%#", ccline.cmdbuff[j + 1])
|
|
600 == NULL
|
|
601 #endif
|
|
602 )
|
|
603 {
|
|
604 if (found)
|
|
605 {
|
|
606 i = j + 1;
|
|
607 break;
|
|
608 }
|
|
609 else
|
|
610 found = TRUE;
|
|
611 }
|
|
612 }
|
|
613
|
|
614 if (!found)
|
|
615 j = i;
|
|
616 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0)
|
|
617 j += 4;
|
|
618 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0
|
|
619 && j == i)
|
|
620 j += 3;
|
|
621 else
|
|
622 j = 0;
|
|
623 if (j > 0)
|
|
624 {
|
|
625 /* TODO this is only for DOS/UNIX systems - need to put in
|
|
626 * machine-specific stuff here and in upseg init */
|
|
627 cmdline_del(j);
|
|
628 put_on_cmdline(upseg + 1, 3, FALSE);
|
|
629 }
|
|
630 else if (ccline.cmdpos > i)
|
|
631 cmdline_del(i);
|
|
632 c = p_wc;
|
|
633 }
|
|
634 }
|
|
635 #if 0 /* If enabled <Down> on a file takes you _completely_ out of wildmenu */
|
|
636 if (p_wmnu
|
|
637 && (xpc.xp_context == EXPAND_FILES
|
|
638 || xpc.xp_context == EXPAND_MENUNAMES)
|
|
639 && (c == K_UP || c == K_DOWN))
|
|
640 xpc.xp_context = EXPAND_NOTHING;
|
|
641 #endif
|
|
642
|
|
643 #endif /* FEAT_WILDMENU */
|
|
644
|
|
645 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert
|
|
646 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */
|
|
647 if (c == Ctrl_BSL)
|
|
648 {
|
|
649 ++no_mapping;
|
|
650 ++allow_keys;
|
1389
|
651 c = plain_vgetc();
|
7
|
652 --no_mapping;
|
|
653 --allow_keys;
|
|
654 /* CTRL-\ e doesn't work when obtaining an expression. */
|
|
655 if (c != Ctrl_N && c != Ctrl_G
|
|
656 && (c != 'e' || ccline.cmdfirstc == '='))
|
|
657 {
|
|
658 vungetc(c);
|
|
659 c = Ctrl_BSL;
|
|
660 }
|
|
661 #ifdef FEAT_EVAL
|
|
662 else if (c == 'e')
|
|
663 {
|
95
|
664 char_u *p = NULL;
|
7
|
665
|
|
666 /*
|
|
667 * Replace the command line with the result of an expression.
|
625
|
668 * Need to save and restore the current command line, to be
|
|
669 * able to enter a new one...
|
7
|
670 */
|
|
671 if (ccline.cmdpos == ccline.cmdlen)
|
|
672 new_cmdpos = 99999; /* keep it at the end */
|
|
673 else
|
|
674 new_cmdpos = ccline.cmdpos;
|
95
|
675
|
|
676 save_cmdline(&save_ccline);
|
7
|
677 c = get_expr_register();
|
95
|
678 restore_cmdline(&save_ccline);
|
7
|
679 if (c == '=')
|
|
680 {
|
634
|
681 /* Need to save and restore ccline. And set "textlock"
|
632
|
682 * to avoid nasty things like going to another buffer when
|
|
683 * evaluating an expression. */
|
95
|
684 save_cmdline(&save_ccline);
|
634
|
685 ++textlock;
|
7
|
686 p = get_expr_line();
|
634
|
687 --textlock;
|
95
|
688 restore_cmdline(&save_ccline);
|
|
689
|
|
690 if (p != NULL && realloc_cmdbuff((int)STRLEN(p) + 1) == OK)
|
7
|
691 {
|
835
|
692 ccline.cmdlen = (int)STRLEN(p);
|
7
|
693 STRCPY(ccline.cmdbuff, p);
|
|
694 vim_free(p);
|
|
695
|
|
696 /* Restore the cursor or use the position set with
|
|
697 * set_cmdline_pos(). */
|
|
698 if (new_cmdpos > ccline.cmdlen)
|
|
699 ccline.cmdpos = ccline.cmdlen;
|
|
700 else
|
|
701 ccline.cmdpos = new_cmdpos;
|
|
702
|
|
703 KeyTyped = FALSE; /* Don't do p_wc completion. */
|
|
704 redrawcmd();
|
|
705 goto cmdline_changed;
|
|
706 }
|
|
707 }
|
|
708 beep_flush();
|
|
709 c = ESC;
|
|
710 }
|
|
711 #endif
|
|
712 else
|
|
713 {
|
|
714 if (c == Ctrl_G && p_im && restart_edit == 0)
|
|
715 restart_edit = 'a';
|
|
716 gotesc = TRUE; /* will free ccline.cmdbuff after putting it
|
|
717 in history */
|
|
718 goto returncmd; /* back to Normal mode */
|
|
719 }
|
|
720 }
|
|
721
|
|
722 #ifdef FEAT_CMDWIN
|
|
723 if (c == cedit_key || c == K_CMDWIN)
|
|
724 {
|
|
725 /*
|
|
726 * Open a window to edit the command line (and history).
|
|
727 */
|
|
728 c = ex_window();
|
|
729 some_key_typed = TRUE;
|
|
730 }
|
|
731 # ifdef FEAT_DIGRAPHS
|
|
732 else
|
|
733 # endif
|
|
734 #endif
|
|
735 #ifdef FEAT_DIGRAPHS
|
|
736 c = do_digraph(c);
|
|
737 #endif
|
|
738
|
|
739 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC
|
|
740 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL)))
|
|
741 {
|
168
|
742 /* In Ex mode a backslash escapes a newline. */
|
|
743 if (exmode_active
|
|
744 && c != ESC
|
1318
|
745 && ccline.cmdpos == ccline.cmdlen
|
168
|
746 && ccline.cmdpos > 0
|
|
747 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\')
|
|
748 {
|
|
749 if (c == K_KENTER)
|
|
750 c = '\n';
|
|
751 }
|
|
752 else
|
7
|
753 {
|
168
|
754 gotesc = FALSE; /* Might have typed ESC previously, don't
|
|
755 truncate the cmdline now. */
|
|
756 if (ccheck_abbr(c + ABBR_OFF))
|
|
757 goto cmdline_changed;
|
|
758 if (!cmd_silent)
|
|
759 {
|
|
760 windgoto(msg_row, 0);
|
|
761 out_flush();
|
|
762 }
|
|
763 break;
|
7
|
764 }
|
|
765 }
|
|
766
|
|
767 /*
|
|
768 * Completion for 'wildchar' or 'wildcharm' key.
|
|
769 * - hitting <ESC> twice means: abandon command line.
|
|
770 * - wildcard expansion is only done when the 'wildchar' key is really
|
|
771 * typed, not when it comes from a macro
|
|
772 */
|
|
773 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm)
|
|
774 {
|
|
775 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */
|
|
776 {
|
|
777 /* if 'wildmode' contains "list" may still need to list */
|
|
778 if (xpc.xp_numfiles > 1
|
|
779 && !did_wild_list
|
|
780 && (wim_flags[wim_index] & WIM_LIST))
|
|
781 {
|
|
782 (void)showmatches(&xpc, FALSE);
|
|
783 redrawcmd();
|
|
784 did_wild_list = TRUE;
|
|
785 }
|
|
786 if (wim_flags[wim_index] & WIM_LONGEST)
|
|
787 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP);
|
|
788 else if (wim_flags[wim_index] & WIM_FULL)
|
|
789 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP);
|
|
790 else
|
|
791 res = OK; /* don't insert 'wildchar' now */
|
|
792 }
|
|
793 else /* typed p_wc first time */
|
|
794 {
|
|
795 wim_index = 0;
|
|
796 j = ccline.cmdpos;
|
|
797 /* if 'wildmode' first contains "longest", get longest
|
|
798 * common part */
|
|
799 if (wim_flags[0] & WIM_LONGEST)
|
|
800 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP);
|
|
801 else
|
|
802 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP);
|
|
803
|
|
804 /* if interrupted while completing, behave like it failed */
|
|
805 if (got_int)
|
|
806 {
|
|
807 (void)vpeekc(); /* remove <C-C> from input stream */
|
|
808 got_int = FALSE; /* don't abandon the command line */
|
|
809 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE);
|
|
810 #ifdef FEAT_WILDMENU
|
|
811 xpc.xp_context = EXPAND_NOTHING;
|
|
812 #endif
|
|
813 goto cmdline_changed;
|
|
814 }
|
|
815
|
|
816 /* when more than one match, and 'wildmode' first contains
|
|
817 * "list", or no change and 'wildmode' contains "longest,list",
|
|
818 * list all matches */
|
|
819 if (res == OK && xpc.xp_numfiles > 1)
|
|
820 {
|
|
821 /* a "longest" that didn't do anything is skipped (but not
|
|
822 * "list:longest") */
|
|
823 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j)
|
|
824 wim_index = 1;
|
|
825 if ((wim_flags[wim_index] & WIM_LIST)
|
|
826 #ifdef FEAT_WILDMENU
|
|
827 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0)
|
|
828 #endif
|
|
829 )
|
|
830 {
|
|
831 if (!(wim_flags[0] & WIM_LONGEST))
|
|
832 {
|
|
833 #ifdef FEAT_WILDMENU
|
|
834 int p_wmnu_save = p_wmnu;
|
|
835 p_wmnu = 0;
|
|
836 #endif
|
|
837 nextwild(&xpc, WILD_PREV, 0); /* remove match */
|
|
838 #ifdef FEAT_WILDMENU
|
|
839 p_wmnu = p_wmnu_save;
|
|
840 #endif
|
|
841 }
|
|
842 #ifdef FEAT_WILDMENU
|
|
843 (void)showmatches(&xpc, p_wmnu
|
|
844 && ((wim_flags[wim_index] & WIM_LIST) == 0));
|
|
845 #else
|
|
846 (void)showmatches(&xpc, FALSE);
|
|
847 #endif
|
|
848 redrawcmd();
|
|
849 did_wild_list = TRUE;
|
|
850 if (wim_flags[wim_index] & WIM_LONGEST)
|
|
851 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP);
|
|
852 else if (wim_flags[wim_index] & WIM_FULL)
|
|
853 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP);
|
|
854 }
|
|
855 else
|
|
856 vim_beep();
|
|
857 }
|
|
858 #ifdef FEAT_WILDMENU
|
|
859 else if (xpc.xp_numfiles == -1)
|
|
860 xpc.xp_context = EXPAND_NOTHING;
|
|
861 #endif
|
|
862 }
|
|
863 if (wim_index < 3)
|
|
864 ++wim_index;
|
|
865 if (c == ESC)
|
|
866 gotesc = TRUE;
|
|
867 if (res == OK)
|
|
868 goto cmdline_changed;
|
|
869 }
|
|
870
|
|
871 gotesc = FALSE;
|
|
872
|
|
873 /* <S-Tab> goes to last match, in a clumsy way */
|
|
874 if (c == K_S_TAB && KeyTyped)
|
|
875 {
|
|
876 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0) == OK
|
|
877 && nextwild(&xpc, WILD_PREV, 0) == OK
|
|
878 && nextwild(&xpc, WILD_PREV, 0) == OK)
|
|
879 goto cmdline_changed;
|
|
880 }
|
|
881
|
|
882 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */
|
|
883 c = NL;
|
|
884
|
|
885 do_abbr = TRUE; /* default: check for abbreviation */
|
|
886
|
|
887 /*
|
|
888 * Big switch for a typed command line character.
|
|
889 */
|
|
890 switch (c)
|
|
891 {
|
|
892 case K_BS:
|
|
893 case Ctrl_H:
|
|
894 case K_DEL:
|
|
895 case K_KDEL:
|
|
896 case Ctrl_W:
|
|
897 #ifdef FEAT_FKMAP
|
|
898 if (cmd_fkmap && c == K_BS)
|
|
899 c = K_DEL;
|
|
900 #endif
|
|
901 if (c == K_KDEL)
|
|
902 c = K_DEL;
|
|
903
|
|
904 /*
|
|
905 * delete current character is the same as backspace on next
|
|
906 * character, except at end of line
|
|
907 */
|
|
908 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen)
|
|
909 ++ccline.cmdpos;
|
|
910 #ifdef FEAT_MBYTE
|
|
911 if (has_mbyte && c == K_DEL)
|
|
912 ccline.cmdpos += mb_off_next(ccline.cmdbuff,
|
|
913 ccline.cmdbuff + ccline.cmdpos);
|
|
914 #endif
|
|
915 if (ccline.cmdpos > 0)
|
|
916 {
|
|
917 char_u *p;
|
|
918
|
|
919 j = ccline.cmdpos;
|
|
920 p = ccline.cmdbuff + j;
|
|
921 #ifdef FEAT_MBYTE
|
|
922 if (has_mbyte)
|
|
923 {
|
|
924 p = mb_prevptr(ccline.cmdbuff, p);
|
|
925 if (c == Ctrl_W)
|
|
926 {
|
|
927 while (p > ccline.cmdbuff && vim_isspace(*p))
|
|
928 p = mb_prevptr(ccline.cmdbuff, p);
|
|
929 i = mb_get_class(p);
|
|
930 while (p > ccline.cmdbuff && mb_get_class(p) == i)
|
|
931 p = mb_prevptr(ccline.cmdbuff, p);
|
|
932 if (mb_get_class(p) != i)
|
474
|
933 p += (*mb_ptr2len)(p);
|
7
|
934 }
|
|
935 }
|
|
936 else
|
|
937 #endif
|
|
938 if (c == Ctrl_W)
|
|
939 {
|
|
940 while (p > ccline.cmdbuff && vim_isspace(p[-1]))
|
|
941 --p;
|
|
942 i = vim_iswordc(p[-1]);
|
|
943 while (p > ccline.cmdbuff && !vim_isspace(p[-1])
|
|
944 && vim_iswordc(p[-1]) == i)
|
|
945 --p;
|
|
946 }
|
|
947 else
|
|
948 --p;
|
|
949 ccline.cmdpos = (int)(p - ccline.cmdbuff);
|
|
950 ccline.cmdlen -= j - ccline.cmdpos;
|
|
951 i = ccline.cmdpos;
|
|
952 while (i < ccline.cmdlen)
|
|
953 ccline.cmdbuff[i++] = ccline.cmdbuff[j++];
|
|
954
|
|
955 /* Truncate at the end, required for multi-byte chars. */
|
|
956 ccline.cmdbuff[ccline.cmdlen] = NUL;
|
|
957 redrawcmd();
|
|
958 }
|
|
959 else if (ccline.cmdlen == 0 && c != Ctrl_W
|
|
960 && ccline.cmdprompt == NULL && indent == 0)
|
|
961 {
|
|
962 /* In ex and debug mode it doesn't make sense to return. */
|
|
963 if (exmode_active
|
|
964 #ifdef FEAT_EVAL
|
|
965 || ccline.cmdfirstc == '>'
|
|
966 #endif
|
|
967 )
|
|
968 goto cmdline_not_changed;
|
|
969
|
|
970 vim_free(ccline.cmdbuff); /* no commandline to return */
|
|
971 ccline.cmdbuff = NULL;
|
|
972 if (!cmd_silent)
|
|
973 {
|
|
974 #ifdef FEAT_RIGHTLEFT
|
|
975 if (cmdmsg_rl)
|
|
976 msg_col = Columns;
|
|
977 else
|
|
978 #endif
|
|
979 msg_col = 0;
|
|
980 msg_putchar(' '); /* delete ':' */
|
|
981 }
|
|
982 redraw_cmdline = TRUE;
|
|
983 goto returncmd; /* back to cmd mode */
|
|
984 }
|
|
985 goto cmdline_changed;
|
|
986
|
|
987 case K_INS:
|
|
988 case K_KINS:
|
|
989 #ifdef FEAT_FKMAP
|
|
990 /* if Farsi mode set, we are in reverse insert mode -
|
|
991 Do not change the mode */
|
|
992 if (cmd_fkmap)
|
|
993 beep_flush();
|
|
994 else
|
|
995 #endif
|
|
996 ccline.overstrike = !ccline.overstrike;
|
|
997 #ifdef CURSOR_SHAPE
|
|
998 ui_cursor_shape(); /* may show different cursor shape */
|
|
999 #endif
|
|
1000 goto cmdline_not_changed;
|
|
1001
|
|
1002 case Ctrl_HAT:
|
782
|
1003 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE))
|
7
|
1004 {
|
|
1005 /* ":lmap" mappings exists, toggle use of mappings. */
|
|
1006 State ^= LANGMAP;
|
|
1007 #ifdef USE_IM_CONTROL
|
|
1008 im_set_active(FALSE); /* Disable input method */
|
|
1009 #endif
|
|
1010 if (b_im_ptr != NULL)
|
|
1011 {
|
|
1012 if (State & LANGMAP)
|
|
1013 *b_im_ptr = B_IMODE_LMAP;
|
|
1014 else
|
|
1015 *b_im_ptr = B_IMODE_NONE;
|
|
1016 }
|
|
1017 }
|
|
1018 #ifdef USE_IM_CONTROL
|
|
1019 else
|
|
1020 {
|
|
1021 /* There are no ":lmap" mappings, toggle IM. When
|
|
1022 * 'imdisable' is set don't try getting the status, it's
|
|
1023 * always off. */
|
|
1024 if ((p_imdisable && b_im_ptr != NULL)
|
|
1025 ? *b_im_ptr == B_IMODE_IM : im_get_status())
|
|
1026 {
|
|
1027 im_set_active(FALSE); /* Disable input method */
|
|
1028 if (b_im_ptr != NULL)
|
|
1029 *b_im_ptr = B_IMODE_NONE;
|
|
1030 }
|
|
1031 else
|
|
1032 {
|
|
1033 im_set_active(TRUE); /* Enable input method */
|
|
1034 if (b_im_ptr != NULL)
|
|
1035 *b_im_ptr = B_IMODE_IM;
|
|
1036 }
|
|
1037 }
|
|
1038 #endif
|
|
1039 if (b_im_ptr != NULL)
|
|
1040 {
|
|
1041 if (b_im_ptr == &curbuf->b_p_iminsert)
|
|
1042 set_iminsert_global();
|
|
1043 else
|
|
1044 set_imsearch_global();
|
|
1045 }
|
|
1046 #ifdef CURSOR_SHAPE
|
|
1047 ui_cursor_shape(); /* may show different cursor shape */
|
|
1048 #endif
|
|
1049 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
|
|
1050 /* Show/unshow value of 'keymap' in status lines later. */
|
|
1051 status_redraw_curbuf();
|
|
1052 #endif
|
|
1053 goto cmdline_not_changed;
|
|
1054
|
|
1055 /* case '@': only in very old vi */
|
|
1056 case Ctrl_U:
|
|
1057 /* delete all characters left of the cursor */
|
|
1058 j = ccline.cmdpos;
|
|
1059 ccline.cmdlen -= j;
|
|
1060 i = ccline.cmdpos = 0;
|
|
1061 while (i < ccline.cmdlen)
|
|
1062 ccline.cmdbuff[i++] = ccline.cmdbuff[j++];
|
|
1063 /* Truncate at the end, required for multi-byte chars. */
|
|
1064 ccline.cmdbuff[ccline.cmdlen] = NUL;
|
|
1065 redrawcmd();
|
|
1066 goto cmdline_changed;
|
|
1067
|
|
1068 #ifdef FEAT_CLIPBOARD
|
|
1069 case Ctrl_Y:
|
|
1070 /* Copy the modeless selection, if there is one. */
|
|
1071 if (clip_star.state != SELECT_CLEARED)
|
|
1072 {
|
|
1073 if (clip_star.state == SELECT_DONE)
|
|
1074 clip_copy_modeless_selection(TRUE);
|
|
1075 goto cmdline_not_changed;
|
|
1076 }
|
|
1077 break;
|
|
1078 #endif
|
|
1079
|
|
1080 case ESC: /* get here if p_wc != ESC or when ESC typed twice */
|
|
1081 case Ctrl_C:
|
571
|
1082 /* In exmode it doesn't make sense to return. Except when
|
161
|
1083 * ":normal" runs out of characters. */
|
|
1084 if (exmode_active
|
|
1085 #ifdef FEAT_EX_EXTRA
|
|
1086 && (ex_normal_busy == 0 || typebuf.tb_len > 0)
|
|
1087 #endif
|
|
1088 )
|
7
|
1089 goto cmdline_not_changed;
|
|
1090
|
|
1091 gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
1092 putting it in history */
|
|
1093 goto returncmd; /* back to cmd mode */
|
|
1094
|
|
1095 case Ctrl_R: /* insert register */
|
|
1096 #ifdef USE_ON_FLY_SCROLL
|
|
1097 dont_scroll = TRUE; /* disallow scrolling here */
|
|
1098 #endif
|
|
1099 putcmdline('"', TRUE);
|
|
1100 ++no_mapping;
|
1389
|
1101 i = c = plain_vgetc(); /* CTRL-R <char> */
|
7
|
1102 if (i == Ctrl_O)
|
|
1103 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */
|
|
1104 if (i == Ctrl_R)
|
1389
|
1105 c = plain_vgetc(); /* CTRL-R CTRL-R <char> */
|
7
|
1106 --no_mapping;
|
|
1107 #ifdef FEAT_EVAL
|
|
1108 /*
|
|
1109 * Insert the result of an expression.
|
|
1110 * Need to save the current command line, to be able to enter
|
|
1111 * a new one...
|
|
1112 */
|
|
1113 new_cmdpos = -1;
|
|
1114 if (c == '=')
|
|
1115 {
|
|
1116 if (ccline.cmdfirstc == '=')/* can't do this recursively */
|
|
1117 {
|
|
1118 beep_flush();
|
|
1119 c = ESC;
|
|
1120 }
|
|
1121 else
|
|
1122 {
|
95
|
1123 save_cmdline(&save_ccline);
|
7
|
1124 c = get_expr_register();
|
95
|
1125 restore_cmdline(&save_ccline);
|
7
|
1126 }
|
|
1127 }
|
|
1128 #endif
|
|
1129 if (c != ESC) /* use ESC to cancel inserting register */
|
|
1130 {
|
1015
|
1131 cmdline_paste(c, i == Ctrl_R, FALSE);
|
606
|
1132
|
613
|
1133 #ifdef FEAT_EVAL
|
606
|
1134 /* When there was a serious error abort getting the
|
|
1135 * command line. */
|
|
1136 if (aborting())
|
|
1137 {
|
|
1138 gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
1139 putting it in history */
|
|
1140 goto returncmd; /* back to cmd mode */
|
|
1141 }
|
613
|
1142 #endif
|
7
|
1143 KeyTyped = FALSE; /* Don't do p_wc completion. */
|
|
1144 #ifdef FEAT_EVAL
|
|
1145 if (new_cmdpos >= 0)
|
|
1146 {
|
|
1147 /* set_cmdline_pos() was used */
|
|
1148 if (new_cmdpos > ccline.cmdlen)
|
|
1149 ccline.cmdpos = ccline.cmdlen;
|
|
1150 else
|
|
1151 ccline.cmdpos = new_cmdpos;
|
|
1152 }
|
|
1153 #endif
|
|
1154 }
|
|
1155 redrawcmd();
|
|
1156 goto cmdline_changed;
|
|
1157
|
|
1158 case Ctrl_D:
|
|
1159 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING)
|
|
1160 break; /* Use ^D as normal char instead */
|
|
1161
|
|
1162 redrawcmd();
|
|
1163 continue; /* don't do incremental search now */
|
|
1164
|
|
1165 case K_RIGHT:
|
|
1166 case K_S_RIGHT:
|
|
1167 case K_C_RIGHT:
|
|
1168 do
|
|
1169 {
|
|
1170 if (ccline.cmdpos >= ccline.cmdlen)
|
|
1171 break;
|
|
1172 i = cmdline_charsize(ccline.cmdpos);
|
|
1173 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows)
|
|
1174 break;
|
|
1175 ccline.cmdspos += i;
|
|
1176 #ifdef FEAT_MBYTE
|
|
1177 if (has_mbyte)
|
474
|
1178 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
|
7
|
1179 + ccline.cmdpos);
|
|
1180 else
|
|
1181 #endif
|
|
1182 ++ccline.cmdpos;
|
|
1183 }
|
180
|
1184 while ((c == K_S_RIGHT || c == K_C_RIGHT
|
|
1185 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
|
7
|
1186 && ccline.cmdbuff[ccline.cmdpos] != ' ');
|
|
1187 #ifdef FEAT_MBYTE
|
|
1188 if (has_mbyte)
|
|
1189 set_cmdspos_cursor();
|
|
1190 #endif
|
|
1191 goto cmdline_not_changed;
|
|
1192
|
|
1193 case K_LEFT:
|
|
1194 case K_S_LEFT:
|
|
1195 case K_C_LEFT:
|
1456
|
1196 if (ccline.cmdpos == 0)
|
|
1197 goto cmdline_not_changed;
|
7
|
1198 do
|
|
1199 {
|
|
1200 --ccline.cmdpos;
|
|
1201 #ifdef FEAT_MBYTE
|
|
1202 if (has_mbyte) /* move to first byte of char */
|
|
1203 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff,
|
|
1204 ccline.cmdbuff + ccline.cmdpos);
|
|
1205 #endif
|
|
1206 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos);
|
|
1207 }
|
1456
|
1208 while (ccline.cmdpos > 0
|
|
1209 && (c == K_S_LEFT || c == K_C_LEFT
|
180
|
1210 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
|
7
|
1211 && ccline.cmdbuff[ccline.cmdpos - 1] != ' ');
|
|
1212 #ifdef FEAT_MBYTE
|
|
1213 if (has_mbyte)
|
|
1214 set_cmdspos_cursor();
|
|
1215 #endif
|
|
1216 goto cmdline_not_changed;
|
|
1217
|
|
1218 case K_IGNORE:
|
1472
|
1219 /* Ignore mouse event or ex_window() result. */
|
|
1220 goto cmdline_not_changed;
|
7
|
1221
|
625
|
1222 #ifdef FEAT_GUI_W32
|
|
1223 /* On Win32 ignore <M-F4>, we get it when closing the window was
|
|
1224 * cancelled. */
|
|
1225 case K_F4:
|
|
1226 if (mod_mask == MOD_MASK_ALT)
|
|
1227 {
|
|
1228 redrawcmd(); /* somehow the cmdline is cleared */
|
|
1229 goto cmdline_not_changed;
|
|
1230 }
|
|
1231 break;
|
|
1232 #endif
|
|
1233
|
7
|
1234 #ifdef FEAT_MOUSE
|
|
1235 case K_MIDDLEDRAG:
|
|
1236 case K_MIDDLERELEASE:
|
|
1237 goto cmdline_not_changed; /* Ignore mouse */
|
|
1238
|
|
1239 case K_MIDDLEMOUSE:
|
|
1240 # ifdef FEAT_GUI
|
|
1241 /* When GUI is active, also paste when 'mouse' is empty */
|
|
1242 if (!gui.in_use)
|
|
1243 # endif
|
|
1244 if (!mouse_has(MOUSE_COMMAND))
|
|
1245 goto cmdline_not_changed; /* Ignore mouse */
|
692
|
1246 # ifdef FEAT_CLIPBOARD
|
7
|
1247 if (clip_star.available)
|
1015
|
1248 cmdline_paste('*', TRUE, TRUE);
|
7
|
1249 else
|
692
|
1250 # endif
|
1015
|
1251 cmdline_paste(0, TRUE, TRUE);
|
7
|
1252 redrawcmd();
|
|
1253 goto cmdline_changed;
|
|
1254
|
692
|
1255 # ifdef FEAT_DND
|
7
|
1256 case K_DROP:
|
1015
|
1257 cmdline_paste('~', TRUE, FALSE);
|
7
|
1258 redrawcmd();
|
|
1259 goto cmdline_changed;
|
692
|
1260 # endif
|
7
|
1261
|
|
1262 case K_LEFTDRAG:
|
|
1263 case K_LEFTRELEASE:
|
|
1264 case K_RIGHTDRAG:
|
|
1265 case K_RIGHTRELEASE:
|
|
1266 /* Ignore drag and release events when the button-down wasn't
|
|
1267 * seen before. */
|
|
1268 if (ignore_drag_release)
|
|
1269 goto cmdline_not_changed;
|
|
1270 /* FALLTHROUGH */
|
|
1271 case K_LEFTMOUSE:
|
|
1272 case K_RIGHTMOUSE:
|
|
1273 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE)
|
|
1274 ignore_drag_release = TRUE;
|
|
1275 else
|
|
1276 ignore_drag_release = FALSE;
|
|
1277 # ifdef FEAT_GUI
|
|
1278 /* When GUI is active, also move when 'mouse' is empty */
|
|
1279 if (!gui.in_use)
|
|
1280 # endif
|
|
1281 if (!mouse_has(MOUSE_COMMAND))
|
|
1282 goto cmdline_not_changed; /* Ignore mouse */
|
|
1283 # ifdef FEAT_CLIPBOARD
|
|
1284 if (mouse_row < cmdline_row && clip_star.available)
|
|
1285 {
|
|
1286 int button, is_click, is_drag;
|
|
1287
|
|
1288 /*
|
|
1289 * Handle modeless selection.
|
|
1290 */
|
|
1291 button = get_mouse_button(KEY2TERMCAP1(c),
|
|
1292 &is_click, &is_drag);
|
|
1293 if (mouse_model_popup() && button == MOUSE_LEFT
|
|
1294 && (mod_mask & MOD_MASK_SHIFT))
|
|
1295 {
|
|
1296 /* Translate shift-left to right button. */
|
|
1297 button = MOUSE_RIGHT;
|
|
1298 mod_mask &= ~MOD_MASK_SHIFT;
|
|
1299 }
|
|
1300 clip_modeless(button, is_click, is_drag);
|
|
1301 goto cmdline_not_changed;
|
|
1302 }
|
|
1303 # endif
|
|
1304
|
|
1305 set_cmdspos();
|
|
1306 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen;
|
|
1307 ++ccline.cmdpos)
|
|
1308 {
|
|
1309 i = cmdline_charsize(ccline.cmdpos);
|
|
1310 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns
|
|
1311 && mouse_col < ccline.cmdspos % Columns + i)
|
|
1312 break;
|
692
|
1313 # ifdef FEAT_MBYTE
|
7
|
1314 if (has_mbyte)
|
|
1315 {
|
|
1316 /* Count ">" for double-wide char that doesn't fit. */
|
|
1317 correct_cmdspos(ccline.cmdpos, i);
|
474
|
1318 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
|
7
|
1319 + ccline.cmdpos) - 1;
|
|
1320 }
|
692
|
1321 # endif
|
7
|
1322 ccline.cmdspos += i;
|
|
1323 }
|
|
1324 goto cmdline_not_changed;
|
|
1325
|
|
1326 /* Mouse scroll wheel: ignored here */
|
|
1327 case K_MOUSEDOWN:
|
|
1328 case K_MOUSEUP:
|
|
1329 /* Alternate buttons ignored here */
|
|
1330 case K_X1MOUSE:
|
|
1331 case K_X1DRAG:
|
|
1332 case K_X1RELEASE:
|
|
1333 case K_X2MOUSE:
|
|
1334 case K_X2DRAG:
|
|
1335 case K_X2RELEASE:
|
|
1336 goto cmdline_not_changed;
|
|
1337
|
|
1338 #endif /* FEAT_MOUSE */
|
|
1339
|
|
1340 #ifdef FEAT_GUI
|
|
1341 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */
|
|
1342 case K_LEFTRELEASE_NM:
|
|
1343 goto cmdline_not_changed;
|
|
1344
|
|
1345 case K_VER_SCROLLBAR:
|
540
|
1346 if (msg_scrolled == 0)
|
7
|
1347 {
|
|
1348 gui_do_scroll();
|
|
1349 redrawcmd();
|
|
1350 }
|
|
1351 goto cmdline_not_changed;
|
|
1352
|
|
1353 case K_HOR_SCROLLBAR:
|
540
|
1354 if (msg_scrolled == 0)
|
7
|
1355 {
|
|
1356 gui_do_horiz_scroll();
|
|
1357 redrawcmd();
|
|
1358 }
|
|
1359 goto cmdline_not_changed;
|
|
1360 #endif
|
692
|
1361 #ifdef FEAT_GUI_TABLINE
|
|
1362 case K_TABLINE:
|
|
1363 case K_TABMENU:
|
|
1364 /* Don't want to change any tabs here. Make sure the same tab
|
|
1365 * is still selected. */
|
|
1366 if (gui_use_tabline())
|
|
1367 gui_mch_set_curtab(tabpage_index(curtab));
|
|
1368 goto cmdline_not_changed;
|
|
1369 #endif
|
|
1370
|
7
|
1371 case K_SELECT: /* end of Select mode mapping - ignore */
|
|
1372 goto cmdline_not_changed;
|
|
1373
|
|
1374 case Ctrl_B: /* begin of command line */
|
|
1375 case K_HOME:
|
|
1376 case K_KHOME:
|
|
1377 case K_S_HOME:
|
|
1378 case K_C_HOME:
|
|
1379 ccline.cmdpos = 0;
|
|
1380 set_cmdspos();
|
|
1381 goto cmdline_not_changed;
|
|
1382
|
|
1383 case Ctrl_E: /* end of command line */
|
|
1384 case K_END:
|
|
1385 case K_KEND:
|
|
1386 case K_S_END:
|
|
1387 case K_C_END:
|
|
1388 ccline.cmdpos = ccline.cmdlen;
|
|
1389 set_cmdspos_cursor();
|
|
1390 goto cmdline_not_changed;
|
|
1391
|
|
1392 case Ctrl_A: /* all matches */
|
|
1393 if (nextwild(&xpc, WILD_ALL, 0) == FAIL)
|
|
1394 break;
|
|
1395 goto cmdline_changed;
|
|
1396
|
772
|
1397 case Ctrl_L:
|
|
1398 #ifdef FEAT_SEARCH_EXTRA
|
|
1399 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?'))
|
|
1400 {
|
|
1401 /* Add a character from under the cursor for 'incsearch' */
|
|
1402 if (did_incsearch
|
|
1403 && !equalpos(curwin->w_cursor, old_cursor))
|
|
1404 {
|
|
1405 c = gchar_cursor();
|
|
1406 if (c != NUL)
|
1039
|
1407 {
|
|
1408 if (c == firstc || vim_strchr((char_u *)(
|
|
1409 p_magic ? "\\^$.*[" : "\\^$"), c)
|
|
1410 != NULL)
|
|
1411 {
|
|
1412 /* put a backslash before special characters */
|
|
1413 stuffcharReadbuff(c);
|
|
1414 c = '\\';
|
|
1415 }
|
772
|
1416 break;
|
1039
|
1417 }
|
772
|
1418 }
|
|
1419 goto cmdline_not_changed;
|
|
1420 }
|
|
1421 #endif
|
|
1422
|
|
1423 /* completion: longest common part */
|
7
|
1424 if (nextwild(&xpc, WILD_LONGEST, 0) == FAIL)
|
|
1425 break;
|
|
1426 goto cmdline_changed;
|
|
1427
|
|
1428 case Ctrl_N: /* next match */
|
|
1429 case Ctrl_P: /* previous match */
|
|
1430 if (xpc.xp_numfiles > 0)
|
|
1431 {
|
|
1432 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, 0)
|
|
1433 == FAIL)
|
|
1434 break;
|
|
1435 goto cmdline_changed;
|
|
1436 }
|
|
1437
|
|
1438 #ifdef FEAT_CMDHIST
|
|
1439 case K_UP:
|
|
1440 case K_DOWN:
|
|
1441 case K_S_UP:
|
|
1442 case K_S_DOWN:
|
|
1443 case K_PAGEUP:
|
|
1444 case K_KPAGEUP:
|
|
1445 case K_PAGEDOWN:
|
|
1446 case K_KPAGEDOWN:
|
|
1447 if (hislen == 0 || firstc == NUL) /* no history */
|
|
1448 goto cmdline_not_changed;
|
|
1449
|
|
1450 i = hiscnt;
|
|
1451
|
|
1452 /* save current command string so it can be restored later */
|
|
1453 if (lookfor == NULL)
|
|
1454 {
|
|
1455 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL)
|
|
1456 goto cmdline_not_changed;
|
|
1457 lookfor[ccline.cmdpos] = NUL;
|
|
1458 }
|
|
1459
|
|
1460 j = (int)STRLEN(lookfor);
|
|
1461 for (;;)
|
|
1462 {
|
|
1463 /* one step backwards */
|
230
|
1464 if (c == K_UP|| c == K_S_UP || c == Ctrl_P
|
180
|
1465 || c == K_PAGEUP || c == K_KPAGEUP)
|
7
|
1466 {
|
|
1467 if (hiscnt == hislen) /* first time */
|
|
1468 hiscnt = hisidx[histype];
|
|
1469 else if (hiscnt == 0 && hisidx[histype] != hislen - 1)
|
|
1470 hiscnt = hislen - 1;
|
|
1471 else if (hiscnt != hisidx[histype] + 1)
|
|
1472 --hiscnt;
|
|
1473 else /* at top of list */
|
|
1474 {
|
|
1475 hiscnt = i;
|
|
1476 break;
|
|
1477 }
|
|
1478 }
|
|
1479 else /* one step forwards */
|
|
1480 {
|
|
1481 /* on last entry, clear the line */
|
|
1482 if (hiscnt == hisidx[histype])
|
|
1483 {
|
|
1484 hiscnt = hislen;
|
|
1485 break;
|
|
1486 }
|
|
1487
|
|
1488 /* not on a history line, nothing to do */
|
|
1489 if (hiscnt == hislen)
|
|
1490 break;
|
|
1491 if (hiscnt == hislen - 1) /* wrap around */
|
|
1492 hiscnt = 0;
|
|
1493 else
|
|
1494 ++hiscnt;
|
|
1495 }
|
|
1496 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL)
|
|
1497 {
|
|
1498 hiscnt = i;
|
|
1499 break;
|
|
1500 }
|
230
|
1501 if ((c != K_UP && c != K_DOWN)
|
180
|
1502 || hiscnt == i
|
7
|
1503 || STRNCMP(history[histype][hiscnt].hisstr,
|
|
1504 lookfor, (size_t)j) == 0)
|
|
1505 break;
|
|
1506 }
|
|
1507
|
|
1508 if (hiscnt != i) /* jumped to other entry */
|
|
1509 {
|
|
1510 char_u *p;
|
|
1511 int len;
|
|
1512 int old_firstc;
|
|
1513
|
|
1514 vim_free(ccline.cmdbuff);
|
|
1515 if (hiscnt == hislen)
|
|
1516 p = lookfor; /* back to the old one */
|
|
1517 else
|
|
1518 p = history[histype][hiscnt].hisstr;
|
|
1519
|
|
1520 if (histype == HIST_SEARCH
|
|
1521 && p != lookfor
|
|
1522 && (old_firstc = p[STRLEN(p) + 1]) != firstc)
|
|
1523 {
|
|
1524 /* Correct for the separator character used when
|
|
1525 * adding the history entry vs the one used now.
|
|
1526 * First loop: count length.
|
|
1527 * Second loop: copy the characters. */
|
|
1528 for (i = 0; i <= 1; ++i)
|
|
1529 {
|
|
1530 len = 0;
|
|
1531 for (j = 0; p[j] != NUL; ++j)
|
|
1532 {
|
|
1533 /* Replace old sep with new sep, unless it is
|
|
1534 * escaped. */
|
|
1535 if (p[j] == old_firstc
|
|
1536 && (j == 0 || p[j - 1] != '\\'))
|
|
1537 {
|
|
1538 if (i > 0)
|
|
1539 ccline.cmdbuff[len] = firstc;
|
|
1540 }
|
|
1541 else
|
|
1542 {
|
|
1543 /* Escape new sep, unless it is already
|
|
1544 * escaped. */
|
|
1545 if (p[j] == firstc
|
|
1546 && (j == 0 || p[j - 1] != '\\'))
|
|
1547 {
|
|
1548 if (i > 0)
|
|
1549 ccline.cmdbuff[len] = '\\';
|
|
1550 ++len;
|
|
1551 }
|
|
1552 if (i > 0)
|
|
1553 ccline.cmdbuff[len] = p[j];
|
|
1554 }
|
|
1555 ++len;
|
|
1556 }
|
|
1557 if (i == 0)
|
|
1558 {
|
|
1559 alloc_cmdbuff(len);
|
|
1560 if (ccline.cmdbuff == NULL)
|
|
1561 goto returncmd;
|
|
1562 }
|
|
1563 }
|
|
1564 ccline.cmdbuff[len] = NUL;
|
|
1565 }
|
|
1566 else
|
|
1567 {
|
|
1568 alloc_cmdbuff((int)STRLEN(p));
|
|
1569 if (ccline.cmdbuff == NULL)
|
|
1570 goto returncmd;
|
|
1571 STRCPY(ccline.cmdbuff, p);
|
|
1572 }
|
|
1573
|
|
1574 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
|
|
1575 redrawcmd();
|
|
1576 goto cmdline_changed;
|
|
1577 }
|
|
1578 beep_flush();
|
|
1579 goto cmdline_not_changed;
|
|
1580 #endif
|
|
1581
|
|
1582 case Ctrl_V:
|
|
1583 case Ctrl_Q:
|
|
1584 #ifdef FEAT_MOUSE
|
|
1585 ignore_drag_release = TRUE;
|
|
1586 #endif
|
|
1587 putcmdline('^', TRUE);
|
|
1588 c = get_literal(); /* get next (two) character(s) */
|
|
1589 do_abbr = FALSE; /* don't do abbreviation now */
|
|
1590 #ifdef FEAT_MBYTE
|
|
1591 /* may need to remove ^ when composing char was typed */
|
|
1592 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent)
|
|
1593 {
|
|
1594 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
1595 msg_putchar(' ');
|
|
1596 cursorcmd();
|
|
1597 }
|
|
1598 #endif
|
|
1599 break;
|
|
1600
|
|
1601 #ifdef FEAT_DIGRAPHS
|
|
1602 case Ctrl_K:
|
|
1603 #ifdef FEAT_MOUSE
|
|
1604 ignore_drag_release = TRUE;
|
|
1605 #endif
|
|
1606 putcmdline('?', TRUE);
|
|
1607 #ifdef USE_ON_FLY_SCROLL
|
|
1608 dont_scroll = TRUE; /* disallow scrolling here */
|
|
1609 #endif
|
|
1610 c = get_digraph(TRUE);
|
|
1611 if (c != NUL)
|
|
1612 break;
|
|
1613
|
|
1614 redrawcmd();
|
|
1615 goto cmdline_not_changed;
|
|
1616 #endif /* FEAT_DIGRAPHS */
|
|
1617
|
|
1618 #ifdef FEAT_RIGHTLEFT
|
|
1619 case Ctrl__: /* CTRL-_: switch language mode */
|
|
1620 if (!p_ari)
|
|
1621 break;
|
|
1622 #ifdef FEAT_FKMAP
|
|
1623 if (p_altkeymap)
|
|
1624 {
|
|
1625 cmd_fkmap = !cmd_fkmap;
|
|
1626 if (cmd_fkmap) /* in Farsi always in Insert mode */
|
|
1627 ccline.overstrike = FALSE;
|
|
1628 }
|
|
1629 else /* Hebrew is default */
|
|
1630 #endif
|
|
1631 cmd_hkmap = !cmd_hkmap;
|
|
1632 goto cmdline_not_changed;
|
|
1633 #endif
|
|
1634
|
|
1635 default:
|
|
1636 #ifdef UNIX
|
|
1637 if (c == intr_char)
|
|
1638 {
|
|
1639 gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
1640 putting it in history */
|
|
1641 goto returncmd; /* back to Normal mode */
|
|
1642 }
|
|
1643 #endif
|
|
1644 /*
|
|
1645 * Normal character with no special meaning. Just set mod_mask
|
|
1646 * to 0x0 so that typing Shift-Space in the GUI doesn't enter
|
|
1647 * the string <S-Space>. This should only happen after ^V.
|
|
1648 */
|
|
1649 if (!IS_SPECIAL(c))
|
|
1650 mod_mask = 0x0;
|
|
1651 break;
|
|
1652 }
|
|
1653 /*
|
|
1654 * End of switch on command line character.
|
|
1655 * We come here if we have a normal character.
|
|
1656 */
|
|
1657
|
|
1658 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && ccheck_abbr(
|
|
1659 #ifdef FEAT_MBYTE
|
|
1660 /* Add ABBR_OFF for characters above 0x100, this is
|
|
1661 * what check_abbr() expects. */
|
|
1662 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
|
|
1663 #endif
|
|
1664 c))
|
|
1665 goto cmdline_changed;
|
|
1666
|
|
1667 /*
|
|
1668 * put the character in the command line
|
|
1669 */
|
|
1670 if (IS_SPECIAL(c) || mod_mask != 0)
|
|
1671 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE);
|
|
1672 else
|
|
1673 {
|
|
1674 #ifdef FEAT_MBYTE
|
|
1675 if (has_mbyte)
|
|
1676 {
|
|
1677 j = (*mb_char2bytes)(c, IObuff);
|
|
1678 IObuff[j] = NUL; /* exclude composing chars */
|
|
1679 put_on_cmdline(IObuff, j, TRUE);
|
|
1680 }
|
|
1681 else
|
|
1682 #endif
|
|
1683 {
|
|
1684 IObuff[0] = c;
|
|
1685 put_on_cmdline(IObuff, 1, TRUE);
|
|
1686 }
|
|
1687 }
|
|
1688 goto cmdline_changed;
|
|
1689
|
|
1690 /*
|
|
1691 * This part implements incremental searches for "/" and "?"
|
|
1692 * Jump to cmdline_not_changed when a character has been read but the command
|
|
1693 * line did not change. Then we only search and redraw if something changed in
|
|
1694 * the past.
|
|
1695 * Jump to cmdline_changed when the command line did change.
|
|
1696 * (Sorry for the goto's, I know it is ugly).
|
|
1697 */
|
|
1698 cmdline_not_changed:
|
|
1699 #ifdef FEAT_SEARCH_EXTRA
|
|
1700 if (!incsearch_postponed)
|
|
1701 continue;
|
|
1702 #endif
|
|
1703
|
|
1704 cmdline_changed:
|
|
1705 #ifdef FEAT_SEARCH_EXTRA
|
|
1706 /*
|
|
1707 * 'incsearch' highlighting.
|
|
1708 */
|
|
1709 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?'))
|
|
1710 {
|
772
|
1711 pos_T end_pos;
|
|
1712
|
7
|
1713 /* if there is a character waiting, search and redraw later */
|
|
1714 if (char_avail())
|
|
1715 {
|
|
1716 incsearch_postponed = TRUE;
|
|
1717 continue;
|
|
1718 }
|
|
1719 incsearch_postponed = FALSE;
|
|
1720 curwin->w_cursor = old_cursor; /* start at old position */
|
|
1721
|
|
1722 /* If there is no command line, don't do anything */
|
|
1723 if (ccline.cmdlen == 0)
|
|
1724 i = 0;
|
|
1725 else
|
|
1726 {
|
|
1727 cursor_off(); /* so the user knows we're busy */
|
|
1728 out_flush();
|
|
1729 ++emsg_off; /* So it doesn't beep if bad expr */
|
|
1730 i = do_search(NULL, firstc, ccline.cmdbuff, count,
|
|
1731 SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK);
|
|
1732 --emsg_off;
|
|
1733 /* if interrupted while searching, behave like it failed */
|
|
1734 if (got_int)
|
|
1735 {
|
|
1736 (void)vpeekc(); /* remove <C-C> from input stream */
|
|
1737 got_int = FALSE; /* don't abandon the command line */
|
|
1738 i = 0;
|
|
1739 }
|
|
1740 else if (char_avail())
|
|
1741 /* cancelled searching because a char was typed */
|
|
1742 incsearch_postponed = TRUE;
|
|
1743 }
|
772
|
1744 if (i != 0)
|
7
|
1745 highlight_match = TRUE; /* highlight position */
|
|
1746 else
|
|
1747 highlight_match = FALSE; /* remove highlight */
|
|
1748
|
|
1749 /* first restore the old curwin values, so the screen is
|
|
1750 * positioned in the same way as the actual search command */
|
|
1751 curwin->w_leftcol = old_leftcol;
|
|
1752 curwin->w_topline = old_topline;
|
|
1753 # ifdef FEAT_DIFF
|
|
1754 curwin->w_topfill = old_topfill;
|
|
1755 # endif
|
|
1756 curwin->w_botline = old_botline;
|
|
1757 changed_cline_bef_curs();
|
|
1758 update_topline();
|
|
1759
|
|
1760 if (i != 0)
|
|
1761 {
|
481
|
1762 pos_T save_pos = curwin->w_cursor;
|
|
1763
|
7
|
1764 /*
|
772
|
1765 * First move cursor to end of match, then to the start. This
|
7
|
1766 * moves the whole match onto the screen when 'nowrap' is set.
|
|
1767 */
|
|
1768 curwin->w_cursor.lnum += search_match_lines;
|
|
1769 curwin->w_cursor.col = search_match_endcol;
|
481
|
1770 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
1771 {
|
|
1772 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
1773 coladvance((colnr_T)MAXCOL);
|
|
1774 }
|
7
|
1775 validate_cursor();
|
772
|
1776 end_pos = curwin->w_cursor;
|
481
|
1777 curwin->w_cursor = save_pos;
|
7
|
1778 }
|
798
|
1779 else
|
|
1780 end_pos = curwin->w_cursor; /* shutup gcc 4 */
|
772
|
1781
|
7
|
1782 validate_cursor();
|
979
|
1783 # ifdef FEAT_WINDOWS
|
|
1784 /* May redraw the status line to show the cursor position. */
|
|
1785 if (p_ru && curwin->w_status_height > 0)
|
|
1786 curwin->w_redr_status = TRUE;
|
|
1787 # endif
|
7
|
1788
|
195
|
1789 save_cmdline(&save_ccline);
|
743
|
1790 update_screen(SOME_VALID);
|
195
|
1791 restore_cmdline(&save_ccline);
|
|
1792
|
772
|
1793 /* Leave it at the end to make CTRL-R CTRL-W work. */
|
|
1794 if (i != 0)
|
|
1795 curwin->w_cursor = end_pos;
|
|
1796
|
7
|
1797 msg_starthere();
|
|
1798 redrawcmdline();
|
|
1799 did_incsearch = TRUE;
|
|
1800 }
|
|
1801 #else /* FEAT_SEARCH_EXTRA */
|
|
1802 ;
|
|
1803 #endif
|
|
1804
|
|
1805 #ifdef FEAT_RIGHTLEFT
|
|
1806 if (cmdmsg_rl
|
|
1807 # ifdef FEAT_ARABIC
|
534
|
1808 || (p_arshape && !p_tbidi && enc_utf8)
|
7
|
1809 # endif
|
|
1810 )
|
|
1811 /* Always redraw the whole command line to fix shaping and
|
|
1812 * right-left typing. Not efficient, but it works. */
|
|
1813 redrawcmd();
|
|
1814 #endif
|
|
1815 }
|
|
1816
|
|
1817 returncmd:
|
|
1818
|
|
1819 #ifdef FEAT_RIGHTLEFT
|
|
1820 cmdmsg_rl = FALSE;
|
|
1821 #endif
|
|
1822
|
|
1823 #ifdef FEAT_FKMAP
|
|
1824 cmd_fkmap = 0;
|
|
1825 #endif
|
|
1826
|
|
1827 ExpandCleanup(&xpc);
|
|
1828
|
|
1829 #ifdef FEAT_SEARCH_EXTRA
|
|
1830 if (did_incsearch)
|
|
1831 {
|
|
1832 curwin->w_cursor = old_cursor;
|
|
1833 curwin->w_curswant = old_curswant;
|
|
1834 curwin->w_leftcol = old_leftcol;
|
|
1835 curwin->w_topline = old_topline;
|
|
1836 # ifdef FEAT_DIFF
|
|
1837 curwin->w_topfill = old_topfill;
|
|
1838 # endif
|
|
1839 curwin->w_botline = old_botline;
|
|
1840 highlight_match = FALSE;
|
|
1841 validate_cursor(); /* needed for TAB */
|
743
|
1842 redraw_later(SOME_VALID);
|
7
|
1843 }
|
|
1844 #endif
|
|
1845
|
|
1846 if (ccline.cmdbuff != NULL)
|
|
1847 {
|
|
1848 /*
|
|
1849 * Put line in history buffer (":" and "=" only when it was typed).
|
|
1850 */
|
|
1851 #ifdef FEAT_CMDHIST
|
|
1852 if (ccline.cmdlen && firstc != NUL
|
|
1853 && (some_key_typed || histype == HIST_SEARCH))
|
|
1854 {
|
|
1855 add_to_history(histype, ccline.cmdbuff, TRUE,
|
|
1856 histype == HIST_SEARCH ? firstc : NUL);
|
|
1857 if (firstc == ':')
|
|
1858 {
|
|
1859 vim_free(new_last_cmdline);
|
|
1860 new_last_cmdline = vim_strsave(ccline.cmdbuff);
|
|
1861 }
|
|
1862 }
|
|
1863 #endif
|
|
1864
|
|
1865 if (gotesc) /* abandon command line */
|
|
1866 {
|
|
1867 vim_free(ccline.cmdbuff);
|
|
1868 ccline.cmdbuff = NULL;
|
|
1869 if (msg_scrolled == 0)
|
|
1870 compute_cmdrow();
|
|
1871 MSG("");
|
|
1872 redraw_cmdline = TRUE;
|
|
1873 }
|
|
1874 }
|
|
1875
|
|
1876 /*
|
|
1877 * If the screen was shifted up, redraw the whole screen (later).
|
|
1878 * If the line is too long, clear it, so ruler and shown command do
|
|
1879 * not get printed in the middle of it.
|
|
1880 */
|
|
1881 msg_check();
|
|
1882 msg_scroll = save_msg_scroll;
|
|
1883 redir_off = FALSE;
|
|
1884
|
|
1885 /* When the command line was typed, no need for a wait-return prompt. */
|
|
1886 if (some_key_typed)
|
|
1887 need_wait_return = FALSE;
|
|
1888
|
|
1889 State = save_State;
|
|
1890 #ifdef USE_IM_CONTROL
|
|
1891 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP)
|
|
1892 im_save_status(b_im_ptr);
|
|
1893 im_set_active(FALSE);
|
|
1894 #endif
|
|
1895 #ifdef FEAT_MOUSE
|
|
1896 setmouse();
|
|
1897 #endif
|
|
1898 #ifdef CURSOR_SHAPE
|
|
1899 ui_cursor_shape(); /* may show different cursor shape */
|
|
1900 #endif
|
|
1901
|
95
|
1902 {
|
|
1903 char_u *p = ccline.cmdbuff;
|
|
1904
|
|
1905 /* Make ccline empty, getcmdline() may try to use it. */
|
|
1906 ccline.cmdbuff = NULL;
|
|
1907 return p;
|
|
1908 }
|
7
|
1909 }
|
|
1910
|
|
1911 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO)
|
|
1912 /*
|
|
1913 * Get a command line with a prompt.
|
|
1914 * This is prepared to be called recursively from getcmdline() (e.g. by
|
|
1915 * f_input() when evaluating an expression from CTRL-R =).
|
|
1916 * Returns the command line in allocated memory, or NULL.
|
|
1917 */
|
|
1918 char_u *
|
531
|
1919 getcmdline_prompt(firstc, prompt, attr, xp_context, xp_arg)
|
7
|
1920 int firstc;
|
|
1921 char_u *prompt; /* command line prompt */
|
|
1922 int attr; /* attributes for prompt */
|
531
|
1923 int xp_context; /* type of expansion */
|
|
1924 char_u *xp_arg; /* user-defined expansion argument */
|
7
|
1925 {
|
|
1926 char_u *s;
|
|
1927 struct cmdline_info save_ccline;
|
|
1928 int msg_col_save = msg_col;
|
|
1929
|
95
|
1930 save_cmdline(&save_ccline);
|
7
|
1931 ccline.cmdprompt = prompt;
|
|
1932 ccline.cmdattr = attr;
|
531
|
1933 # ifdef FEAT_EVAL
|
|
1934 ccline.xp_context = xp_context;
|
|
1935 ccline.xp_arg = xp_arg;
|
|
1936 ccline.input_fn = (firstc == '@');
|
|
1937 # endif
|
7
|
1938 s = getcmdline(firstc, 1L, 0);
|
95
|
1939 restore_cmdline(&save_ccline);
|
7
|
1940 /* Restore msg_col, the prompt from input() may have changed it. */
|
|
1941 msg_col = msg_col_save;
|
|
1942
|
|
1943 return s;
|
|
1944 }
|
|
1945 #endif
|
|
1946
|
632
|
1947 /*
|
634
|
1948 * Return TRUE when the text must not be changed and we can't switch to
|
|
1949 * another window or buffer. Used when editing the command line, evaluating
|
|
1950 * 'balloonexpr', etc.
|
632
|
1951 */
|
|
1952 int
|
634
|
1953 text_locked()
|
632
|
1954 {
|
|
1955 #ifdef FEAT_CMDWIN
|
|
1956 if (cmdwin_type != 0)
|
|
1957 return TRUE;
|
|
1958 #endif
|
634
|
1959 return textlock != 0;
|
632
|
1960 }
|
|
1961
|
|
1962 /*
|
|
1963 * Give an error message for a command that isn't allowed while the cmdline
|
|
1964 * window is open or editing the cmdline in another way.
|
|
1965 */
|
|
1966 void
|
634
|
1967 text_locked_msg()
|
632
|
1968 {
|
|
1969 #ifdef FEAT_CMDWIN
|
|
1970 if (cmdwin_type != 0)
|
|
1971 EMSG(_(e_cmdwin));
|
|
1972 else
|
|
1973 #endif
|
|
1974 EMSG(_(e_secure));
|
|
1975 }
|
|
1976
|
819
|
1977 #if defined(FEAT_AUTOCMD) || defined(PROTO)
|
|
1978 /*
|
|
1979 * Check if "curbuf_lock" is set and return TRUE when it is and give an error
|
|
1980 * message.
|
|
1981 */
|
|
1982 int
|
|
1983 curbuf_locked()
|
|
1984 {
|
|
1985 if (curbuf_lock > 0)
|
|
1986 {
|
|
1987 EMSG(_("E788: Not allowed to edit another buffer now"));
|
|
1988 return TRUE;
|
|
1989 }
|
|
1990 return FALSE;
|
|
1991 }
|
|
1992 #endif
|
|
1993
|
7
|
1994 static int
|
|
1995 cmdline_charsize(idx)
|
|
1996 int idx;
|
|
1997 {
|
|
1998 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
1999 if (cmdline_star > 0) /* showing '*', always 1 position */
|
|
2000 return 1;
|
|
2001 #endif
|
|
2002 return ptr2cells(ccline.cmdbuff + idx);
|
|
2003 }
|
|
2004
|
|
2005 /*
|
|
2006 * Compute the offset of the cursor on the command line for the prompt and
|
|
2007 * indent.
|
|
2008 */
|
|
2009 static void
|
|
2010 set_cmdspos()
|
|
2011 {
|
531
|
2012 if (ccline.cmdfirstc != NUL)
|
7
|
2013 ccline.cmdspos = 1 + ccline.cmdindent;
|
|
2014 else
|
|
2015 ccline.cmdspos = 0 + ccline.cmdindent;
|
|
2016 }
|
|
2017
|
|
2018 /*
|
|
2019 * Compute the screen position for the cursor on the command line.
|
|
2020 */
|
|
2021 static void
|
|
2022 set_cmdspos_cursor()
|
|
2023 {
|
|
2024 int i, m, c;
|
|
2025
|
|
2026 set_cmdspos();
|
|
2027 if (KeyTyped)
|
534
|
2028 {
|
7
|
2029 m = Columns * Rows;
|
534
|
2030 if (m < 0) /* overflow, Columns or Rows at weird value */
|
|
2031 m = MAXCOL;
|
|
2032 }
|
7
|
2033 else
|
|
2034 m = MAXCOL;
|
|
2035 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i)
|
|
2036 {
|
|
2037 c = cmdline_charsize(i);
|
|
2038 #ifdef FEAT_MBYTE
|
|
2039 /* Count ">" for double-wide multi-byte char that doesn't fit. */
|
|
2040 if (has_mbyte)
|
|
2041 correct_cmdspos(i, c);
|
|
2042 #endif
|
|
2043 /* If the cmdline doesn't fit, put cursor on last visible char. */
|
|
2044 if ((ccline.cmdspos += c) >= m)
|
|
2045 {
|
|
2046 ccline.cmdpos = i - 1;
|
|
2047 ccline.cmdspos -= c;
|
|
2048 break;
|
|
2049 }
|
|
2050 #ifdef FEAT_MBYTE
|
|
2051 if (has_mbyte)
|
474
|
2052 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1;
|
7
|
2053 #endif
|
|
2054 }
|
|
2055 }
|
|
2056
|
|
2057 #ifdef FEAT_MBYTE
|
|
2058 /*
|
|
2059 * Check if the character at "idx", which is "cells" wide, is a multi-byte
|
|
2060 * character that doesn't fit, so that a ">" must be displayed.
|
|
2061 */
|
|
2062 static void
|
|
2063 correct_cmdspos(idx, cells)
|
|
2064 int idx;
|
|
2065 int cells;
|
|
2066 {
|
474
|
2067 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1
|
7
|
2068 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1
|
|
2069 && ccline.cmdspos % Columns + cells > Columns)
|
|
2070 ccline.cmdspos++;
|
|
2071 }
|
|
2072 #endif
|
|
2073
|
|
2074 /*
|
|
2075 * Get an Ex command line for the ":" command.
|
|
2076 */
|
|
2077 /* ARGSUSED */
|
|
2078 char_u *
|
|
2079 getexline(c, dummy, indent)
|
|
2080 int c; /* normally ':', NUL for ":append" */
|
|
2081 void *dummy; /* cookie not used */
|
|
2082 int indent; /* indent for inside conditionals */
|
|
2083 {
|
|
2084 /* When executing a register, remove ':' that's in front of each line. */
|
|
2085 if (exec_from_reg && vpeekc() == ':')
|
|
2086 (void)vgetc();
|
|
2087 return getcmdline(c, 1L, indent);
|
|
2088 }
|
|
2089
|
|
2090 /*
|
|
2091 * Get an Ex command line for Ex mode.
|
|
2092 * In Ex mode we only use the OS supplied line editing features and no
|
|
2093 * mappings or abbreviations.
|
168
|
2094 * Returns a string in allocated memory or NULL.
|
7
|
2095 */
|
|
2096 /* ARGSUSED */
|
|
2097 char_u *
|
168
|
2098 getexmodeline(promptc, dummy, indent)
|
|
2099 int promptc; /* normally ':', NUL for ":append" and '?' for
|
|
2100 :s prompt */
|
7
|
2101 void *dummy; /* cookie not used */
|
|
2102 int indent; /* indent for inside conditionals */
|
|
2103 {
|
168
|
2104 garray_T line_ga;
|
|
2105 char_u *pend;
|
|
2106 int startcol = 0;
|
1329
|
2107 int c1 = 0;
|
168
|
2108 int escaped = FALSE; /* CTRL-V typed */
|
|
2109 int vcol = 0;
|
|
2110 char_u *p;
|
1329
|
2111 int prev_char;
|
7
|
2112
|
|
2113 /* Switch cursor on now. This avoids that it happens after the "\n", which
|
|
2114 * confuses the system function that computes tabstops. */
|
|
2115 cursor_on();
|
|
2116
|
|
2117 /* always start in column 0; write a newline if necessary */
|
|
2118 compute_cmdrow();
|
168
|
2119 if ((msg_col || msg_didout) && promptc != '?')
|
7
|
2120 msg_putchar('\n');
|
168
|
2121 if (promptc == ':')
|
7
|
2122 {
|
164
|
2123 /* indent that is only displayed, not in the line itself */
|
168
|
2124 if (p_prompt)
|
|
2125 msg_putchar(':');
|
7
|
2126 while (indent-- > 0)
|
|
2127 msg_putchar(' ');
|
|
2128 startcol = msg_col;
|
|
2129 }
|
|
2130
|
|
2131 ga_init2(&line_ga, 1, 30);
|
|
2132
|
164
|
2133 /* autoindent for :insert and :append is in the line itself */
|
168
|
2134 if (promptc <= 0)
|
164
|
2135 {
|
|
2136 vcol = indent;
|
|
2137 while (indent >= 8)
|
|
2138 {
|
|
2139 ga_append(&line_ga, TAB);
|
|
2140 msg_puts((char_u *)" ");
|
|
2141 indent -= 8;
|
|
2142 }
|
|
2143 while (indent-- > 0)
|
|
2144 {
|
|
2145 ga_append(&line_ga, ' ');
|
|
2146 msg_putchar(' ');
|
|
2147 }
|
|
2148 }
|
168
|
2149 ++no_mapping;
|
|
2150 ++allow_keys;
|
164
|
2151
|
7
|
2152 /*
|
|
2153 * Get the line, one character at a time.
|
|
2154 */
|
|
2155 got_int = FALSE;
|
168
|
2156 while (!got_int)
|
7
|
2157 {
|
|
2158 if (ga_grow(&line_ga, 40) == FAIL)
|
|
2159 break;
|
164
|
2160 pend = (char_u *)line_ga.ga_data + line_ga.ga_len;
|
7
|
2161
|
168
|
2162 /* Get one character at a time. Don't use inchar(), it can't handle
|
|
2163 * special characters. */
|
1329
|
2164 prev_char = c1;
|
168
|
2165 c1 = vgetc();
|
7
|
2166
|
|
2167 /*
|
168
|
2168 * Handle line editing.
|
|
2169 * Previously this was left to the system, putting the terminal in
|
|
2170 * cooked mode, but then CTRL-D and CTRL-T can't be used properly.
|
7
|
2171 */
|
168
|
2172 if (got_int)
|
|
2173 {
|
|
2174 msg_putchar('\n');
|
|
2175 break;
|
|
2176 }
|
|
2177
|
|
2178 if (!escaped)
|
7
|
2179 {
|
168
|
2180 /* CR typed means "enter", which is NL */
|
|
2181 if (c1 == '\r')
|
|
2182 c1 = '\n';
|
|
2183
|
|
2184 if (c1 == BS || c1 == K_BS
|
|
2185 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL)
|
7
|
2186 {
|
168
|
2187 if (line_ga.ga_len > 0)
|
|
2188 {
|
|
2189 --line_ga.ga_len;
|
|
2190 goto redraw;
|
|
2191 }
|
|
2192 continue;
|
7
|
2193 }
|
|
2194
|
168
|
2195 if (c1 == Ctrl_U)
|
7
|
2196 {
|
168
|
2197 msg_col = startcol;
|
|
2198 msg_clr_eos();
|
|
2199 line_ga.ga_len = 0;
|
|
2200 continue;
|
|
2201 }
|
|
2202
|
|
2203 if (c1 == Ctrl_T)
|
|
2204 {
|
|
2205 p = (char_u *)line_ga.ga_data;
|
|
2206 p[line_ga.ga_len] = NUL;
|
|
2207 indent = get_indent_str(p, 8);
|
|
2208 indent += curbuf->b_p_sw - indent % curbuf->b_p_sw;
|
|
2209 add_indent:
|
|
2210 while (get_indent_str(p, 8) < indent)
|
7
|
2211 {
|
168
|
2212 char_u *s = skipwhite(p);
|
|
2213
|
|
2214 ga_grow(&line_ga, 1);
|
|
2215 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1);
|
|
2216 *s = ' ';
|
|
2217 ++line_ga.ga_len;
|
7
|
2218 }
|
168
|
2219 redraw:
|
|
2220 /* redraw the line */
|
|
2221 msg_col = startcol;
|
|
2222 vcol = 0;
|
|
2223 for (p = (char_u *)line_ga.ga_data;
|
|
2224 p < (char_u *)line_ga.ga_data + line_ga.ga_len; ++p)
|
7
|
2225 {
|
168
|
2226 if (*p == TAB)
|
7
|
2227 {
|
168
|
2228 do
|
7
|
2229 {
|
168
|
2230 msg_putchar(' ');
|
|
2231 } while (++vcol % 8);
|
7
|
2232 }
|
168
|
2233 else
|
164
|
2234 {
|
168
|
2235 msg_outtrans_len(p, 1);
|
|
2236 vcol += char2cells(*p);
|
7
|
2237 }
|
|
2238 }
|
168
|
2239 msg_clr_eos();
|
1329
|
2240 windgoto(msg_row, msg_col);
|
168
|
2241 continue;
|
|
2242 }
|
|
2243
|
|
2244 if (c1 == Ctrl_D)
|
|
2245 {
|
|
2246 /* Delete one shiftwidth. */
|
|
2247 p = (char_u *)line_ga.ga_data;
|
|
2248 if (prev_char == '0' || prev_char == '^')
|
7
|
2249 {
|
168
|
2250 if (prev_char == '^')
|
|
2251 ex_keep_indent = TRUE;
|
|
2252 indent = 0;
|
|
2253 p[--line_ga.ga_len] = NUL;
|
7
|
2254 }
|
|
2255 else
|
|
2256 {
|
168
|
2257 p[line_ga.ga_len] = NUL;
|
|
2258 indent = get_indent_str(p, 8);
|
|
2259 --indent;
|
|
2260 indent -= indent % curbuf->b_p_sw;
|
|
2261 }
|
|
2262 while (get_indent_str(p, 8) > indent)
|
|
2263 {
|
|
2264 char_u *s = skipwhite(p);
|
|
2265
|
|
2266 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1);
|
|
2267 --line_ga.ga_len;
|
7
|
2268 }
|
168
|
2269 goto add_indent;
|
|
2270 }
|
|
2271
|
|
2272 if (c1 == Ctrl_V || c1 == Ctrl_Q)
|
|
2273 {
|
|
2274 escaped = TRUE;
|
|
2275 continue;
|
7
|
2276 }
|
168
|
2277
|
|
2278 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */
|
|
2279 if (IS_SPECIAL(c1))
|
|
2280 continue;
|
7
|
2281 }
|
168
|
2282
|
|
2283 if (IS_SPECIAL(c1))
|
|
2284 c1 = '?';
|
|
2285 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1;
|
|
2286 if (c1 == '\n')
|
|
2287 msg_putchar('\n');
|
|
2288 else if (c1 == TAB)
|
|
2289 {
|
|
2290 /* Don't use chartabsize(), 'ts' can be different */
|
|
2291 do
|
|
2292 {
|
|
2293 msg_putchar(' ');
|
|
2294 } while (++vcol % 8);
|
|
2295 }
|
7
|
2296 else
|
|
2297 {
|
168
|
2298 msg_outtrans_len(
|
|
2299 ((char_u *)line_ga.ga_data) + line_ga.ga_len, 1);
|
|
2300 vcol += char2cells(c1);
|
7
|
2301 }
|
168
|
2302 ++line_ga.ga_len;
|
|
2303 escaped = FALSE;
|
|
2304
|
|
2305 windgoto(msg_row, msg_col);
|
164
|
2306 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len;
|
168
|
2307
|
|
2308 /* we are done when a NL is entered, but not when it comes after a
|
|
2309 * backslash */
|
|
2310 if (line_ga.ga_len > 0 && pend[-1] == '\n'
|
|
2311 && (line_ga.ga_len <= 1 || pend[-2] != '\\'))
|
7
|
2312 {
|
|
2313 --line_ga.ga_len;
|
164
|
2314 --pend;
|
|
2315 *pend = NUL;
|
168
|
2316 break;
|
7
|
2317 }
|
|
2318 }
|
|
2319
|
168
|
2320 --no_mapping;
|
|
2321 --allow_keys;
|
|
2322
|
7
|
2323 /* make following messages go to the next line */
|
|
2324 msg_didout = FALSE;
|
|
2325 msg_col = 0;
|
|
2326 if (msg_row < Rows - 1)
|
|
2327 ++msg_row;
|
|
2328 emsg_on_display = FALSE; /* don't want ui_delay() */
|
|
2329
|
|
2330 if (got_int)
|
|
2331 ga_clear(&line_ga);
|
|
2332
|
|
2333 return (char_u *)line_ga.ga_data;
|
|
2334 }
|
|
2335
|
502
|
2336 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \
|
|
2337 || defined(FEAT_MOUSESHAPE) || defined(PROTO)
|
7
|
2338 /*
|
|
2339 * Return TRUE if ccline.overstrike is on.
|
|
2340 */
|
|
2341 int
|
|
2342 cmdline_overstrike()
|
|
2343 {
|
|
2344 return ccline.overstrike;
|
|
2345 }
|
|
2346
|
|
2347 /*
|
|
2348 * Return TRUE if the cursor is at the end of the cmdline.
|
|
2349 */
|
|
2350 int
|
|
2351 cmdline_at_end()
|
|
2352 {
|
|
2353 return (ccline.cmdpos >= ccline.cmdlen);
|
|
2354 }
|
|
2355 #endif
|
|
2356
|
574
|
2357 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO)
|
7
|
2358 /*
|
|
2359 * Return the virtual column number at the current cursor position.
|
|
2360 * This is used by the IM code to obtain the start of the preedit string.
|
|
2361 */
|
|
2362 colnr_T
|
|
2363 cmdline_getvcol_cursor()
|
|
2364 {
|
|
2365 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen)
|
|
2366 return MAXCOL;
|
|
2367
|
|
2368 # ifdef FEAT_MBYTE
|
|
2369 if (has_mbyte)
|
|
2370 {
|
|
2371 colnr_T col;
|
|
2372 int i = 0;
|
|
2373
|
|
2374 for (col = 0; i < ccline.cmdpos; ++col)
|
474
|
2375 i += (*mb_ptr2len)(ccline.cmdbuff + i);
|
7
|
2376
|
|
2377 return col;
|
|
2378 }
|
|
2379 else
|
|
2380 # endif
|
|
2381 return ccline.cmdpos;
|
|
2382 }
|
|
2383 #endif
|
|
2384
|
|
2385 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|
|
2386 /*
|
|
2387 * If part of the command line is an IM preedit string, redraw it with
|
|
2388 * IM feedback attributes. The cursor position is restored after drawing.
|
|
2389 */
|
|
2390 static void
|
|
2391 redrawcmd_preedit()
|
|
2392 {
|
|
2393 if ((State & CMDLINE)
|
|
2394 && xic != NULL
|
976
|
2395 /* && im_get_status() doesn't work when using SCIM */
|
7
|
2396 && !p_imdisable
|
|
2397 && im_is_preediting())
|
|
2398 {
|
|
2399 int cmdpos = 0;
|
|
2400 int cmdspos;
|
|
2401 int old_row;
|
|
2402 int old_col;
|
|
2403 colnr_T col;
|
|
2404
|
|
2405 old_row = msg_row;
|
|
2406 old_col = msg_col;
|
531
|
2407 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent;
|
7
|
2408
|
|
2409 # ifdef FEAT_MBYTE
|
|
2410 if (has_mbyte)
|
|
2411 {
|
|
2412 for (col = 0; col < preedit_start_col
|
|
2413 && cmdpos < ccline.cmdlen; ++col)
|
|
2414 {
|
|
2415 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos);
|
474
|
2416 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos);
|
7
|
2417 }
|
|
2418 }
|
|
2419 else
|
|
2420 # endif
|
|
2421 {
|
|
2422 cmdspos += preedit_start_col;
|
|
2423 cmdpos += preedit_start_col;
|
|
2424 }
|
|
2425
|
|
2426 msg_row = cmdline_row + (cmdspos / (int)Columns);
|
|
2427 msg_col = cmdspos % (int)Columns;
|
|
2428 if (msg_row >= Rows)
|
|
2429 msg_row = Rows - 1;
|
|
2430
|
|
2431 for (col = 0; cmdpos < ccline.cmdlen; ++col)
|
|
2432 {
|
|
2433 int char_len;
|
|
2434 int char_attr;
|
|
2435
|
|
2436 char_attr = im_get_feedback_attr(col);
|
|
2437 if (char_attr < 0)
|
|
2438 break; /* end of preedit string */
|
|
2439
|
|
2440 # ifdef FEAT_MBYTE
|
|
2441 if (has_mbyte)
|
474
|
2442 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos);
|
7
|
2443 else
|
|
2444 # endif
|
|
2445 char_len = 1;
|
|
2446
|
|
2447 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr);
|
|
2448 cmdpos += char_len;
|
|
2449 }
|
|
2450
|
|
2451 msg_row = old_row;
|
|
2452 msg_col = old_col;
|
|
2453 }
|
|
2454 }
|
|
2455 #endif /* FEAT_XIM && FEAT_GUI_GTK */
|
|
2456
|
|
2457 /*
|
|
2458 * Allocate a new command line buffer.
|
|
2459 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen.
|
|
2460 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen.
|
|
2461 */
|
|
2462 static void
|
|
2463 alloc_cmdbuff(len)
|
|
2464 int len;
|
|
2465 {
|
|
2466 /*
|
|
2467 * give some extra space to avoid having to allocate all the time
|
|
2468 */
|
|
2469 if (len < 80)
|
|
2470 len = 100;
|
|
2471 else
|
|
2472 len += 20;
|
|
2473
|
|
2474 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */
|
|
2475 ccline.cmdbufflen = len;
|
|
2476 }
|
|
2477
|
|
2478 /*
|
|
2479 * Re-allocate the command line to length len + something extra.
|
|
2480 * return FAIL for failure, OK otherwise
|
|
2481 */
|
|
2482 static int
|
|
2483 realloc_cmdbuff(len)
|
|
2484 int len;
|
|
2485 {
|
|
2486 char_u *p;
|
|
2487
|
|
2488 p = ccline.cmdbuff;
|
|
2489 alloc_cmdbuff(len); /* will get some more */
|
|
2490 if (ccline.cmdbuff == NULL) /* out of memory */
|
|
2491 {
|
|
2492 ccline.cmdbuff = p; /* keep the old one */
|
|
2493 return FAIL;
|
|
2494 }
|
|
2495 mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen + 1);
|
|
2496 vim_free(p);
|
|
2497 return OK;
|
|
2498 }
|
|
2499
|
359
|
2500 #if defined(FEAT_ARABIC) || defined(PROTO)
|
|
2501 static char_u *arshape_buf = NULL;
|
|
2502
|
|
2503 # if defined(EXITFREE) || defined(PROTO)
|
|
2504 void
|
|
2505 free_cmdline_buf()
|
|
2506 {
|
|
2507 vim_free(arshape_buf);
|
|
2508 }
|
|
2509 # endif
|
|
2510 #endif
|
|
2511
|
7
|
2512 /*
|
|
2513 * Draw part of the cmdline at the current cursor position. But draw stars
|
|
2514 * when cmdline_star is TRUE.
|
|
2515 */
|
|
2516 static void
|
|
2517 draw_cmdline(start, len)
|
|
2518 int start;
|
|
2519 int len;
|
|
2520 {
|
|
2521 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
2522 int i;
|
|
2523
|
|
2524 if (cmdline_star > 0)
|
|
2525 for (i = 0; i < len; ++i)
|
|
2526 {
|
|
2527 msg_putchar('*');
|
|
2528 # ifdef FEAT_MBYTE
|
|
2529 if (has_mbyte)
|
474
|
2530 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1;
|
7
|
2531 # endif
|
|
2532 }
|
|
2533 else
|
|
2534 #endif
|
|
2535 #ifdef FEAT_ARABIC
|
|
2536 if (p_arshape && !p_tbidi && enc_utf8 && len > 0)
|
|
2537 {
|
|
2538 static int buflen = 0;
|
|
2539 char_u *p;
|
|
2540 int j;
|
|
2541 int newlen = 0;
|
|
2542 int mb_l;
|
719
|
2543 int pc, pc1 = 0;
|
7
|
2544 int prev_c = 0;
|
|
2545 int prev_c1 = 0;
|
714
|
2546 int u8c;
|
|
2547 int u8cc[MAX_MCO];
|
7
|
2548 int nc = 0;
|
|
2549
|
|
2550 /*
|
|
2551 * Do arabic shaping into a temporary buffer. This is very
|
|
2552 * inefficient!
|
|
2553 */
|
507
|
2554 if (len * 2 + 2 > buflen)
|
7
|
2555 {
|
|
2556 /* Re-allocate the buffer. We keep it around to avoid a lot of
|
|
2557 * alloc()/free() calls. */
|
359
|
2558 vim_free(arshape_buf);
|
507
|
2559 buflen = len * 2 + 2;
|
359
|
2560 arshape_buf = alloc(buflen);
|
|
2561 if (arshape_buf == NULL)
|
7
|
2562 return; /* out of memory */
|
|
2563 }
|
|
2564
|
507
|
2565 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start)))
|
|
2566 {
|
|
2567 /* Prepend a space to draw the leading composing char on. */
|
|
2568 arshape_buf[0] = ' ';
|
|
2569 newlen = 1;
|
|
2570 }
|
|
2571
|
7
|
2572 for (j = start; j < start + len; j += mb_l)
|
|
2573 {
|
|
2574 p = ccline.cmdbuff + j;
|
714
|
2575 u8c = utfc_ptr2char_len(p, u8cc, start + len - j);
|
474
|
2576 mb_l = utfc_ptr2len_len(p, start + len - j);
|
7
|
2577 if (ARABIC_CHAR(u8c))
|
|
2578 {
|
|
2579 /* Do Arabic shaping. */
|
|
2580 if (cmdmsg_rl)
|
|
2581 {
|
|
2582 /* displaying from right to left */
|
|
2583 pc = prev_c;
|
|
2584 pc1 = prev_c1;
|
714
|
2585 prev_c1 = u8cc[0];
|
7
|
2586 if (j + mb_l >= start + len)
|
|
2587 nc = NUL;
|
|
2588 else
|
|
2589 nc = utf_ptr2char(p + mb_l);
|
|
2590 }
|
|
2591 else
|
|
2592 {
|
|
2593 /* displaying from left to right */
|
|
2594 if (j + mb_l >= start + len)
|
|
2595 pc = NUL;
|
|
2596 else
|
714
|
2597 {
|
|
2598 int pcc[MAX_MCO];
|
|
2599
|
|
2600 pc = utfc_ptr2char_len(p + mb_l, pcc,
|
7
|
2601 start + len - j - mb_l);
|
714
|
2602 pc1 = pcc[0];
|
|
2603 }
|
7
|
2604 nc = prev_c;
|
|
2605 }
|
|
2606 prev_c = u8c;
|
|
2607
|
714
|
2608 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc);
|
7
|
2609
|
359
|
2610 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen);
|
714
|
2611 if (u8cc[0] != 0)
|
7
|
2612 {
|
714
|
2613 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen);
|
|
2614 if (u8cc[1] != 0)
|
|
2615 newlen += (*mb_char2bytes)(u8cc[1],
|
359
|
2616 arshape_buf + newlen);
|
7
|
2617 }
|
|
2618 }
|
|
2619 else
|
|
2620 {
|
|
2621 prev_c = u8c;
|
359
|
2622 mch_memmove(arshape_buf + newlen, p, mb_l);
|
7
|
2623 newlen += mb_l;
|
|
2624 }
|
|
2625 }
|
|
2626
|
359
|
2627 msg_outtrans_len(arshape_buf, newlen);
|
7
|
2628 }
|
|
2629 else
|
|
2630 #endif
|
|
2631 msg_outtrans_len(ccline.cmdbuff + start, len);
|
|
2632 }
|
|
2633
|
|
2634 /*
|
|
2635 * Put a character on the command line. Shifts the following text to the
|
|
2636 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
|
2637 * "c" must be printable (fit in one display cell)!
|
|
2638 */
|
|
2639 void
|
|
2640 putcmdline(c, shift)
|
|
2641 int c;
|
|
2642 int shift;
|
|
2643 {
|
|
2644 if (cmd_silent)
|
|
2645 return;
|
|
2646 msg_no_more = TRUE;
|
|
2647 msg_putchar(c);
|
|
2648 if (shift)
|
|
2649 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
2650 msg_no_more = FALSE;
|
|
2651 cursorcmd();
|
|
2652 }
|
|
2653
|
|
2654 /*
|
|
2655 * Undo a putcmdline(c, FALSE).
|
|
2656 */
|
|
2657 void
|
|
2658 unputcmdline()
|
|
2659 {
|
|
2660 if (cmd_silent)
|
|
2661 return;
|
|
2662 msg_no_more = TRUE;
|
|
2663 if (ccline.cmdlen == ccline.cmdpos)
|
|
2664 msg_putchar(' ');
|
|
2665 else
|
|
2666 draw_cmdline(ccline.cmdpos, 1);
|
|
2667 msg_no_more = FALSE;
|
|
2668 cursorcmd();
|
|
2669 }
|
|
2670
|
|
2671 /*
|
|
2672 * Put the given string, of the given length, onto the command line.
|
|
2673 * If len is -1, then STRLEN() is used to calculate the length.
|
|
2674 * If 'redraw' is TRUE then the new part of the command line, and the remaining
|
|
2675 * part will be redrawn, otherwise it will not. If this function is called
|
|
2676 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be
|
|
2677 * called afterwards.
|
|
2678 */
|
|
2679 int
|
|
2680 put_on_cmdline(str, len, redraw)
|
|
2681 char_u *str;
|
|
2682 int len;
|
|
2683 int redraw;
|
|
2684 {
|
|
2685 int retval;
|
|
2686 int i;
|
|
2687 int m;
|
|
2688 int c;
|
|
2689
|
|
2690 if (len < 0)
|
|
2691 len = (int)STRLEN(str);
|
|
2692
|
|
2693 /* Check if ccline.cmdbuff needs to be longer */
|
|
2694 if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen)
|
|
2695 retval = realloc_cmdbuff(ccline.cmdlen + len);
|
|
2696 else
|
|
2697 retval = OK;
|
|
2698 if (retval == OK)
|
|
2699 {
|
|
2700 if (!ccline.overstrike)
|
|
2701 {
|
|
2702 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
|
2703 ccline.cmdbuff + ccline.cmdpos,
|
|
2704 (size_t)(ccline.cmdlen - ccline.cmdpos));
|
|
2705 ccline.cmdlen += len;
|
|
2706 }
|
|
2707 else
|
|
2708 {
|
|
2709 #ifdef FEAT_MBYTE
|
|
2710 if (has_mbyte)
|
|
2711 {
|
|
2712 /* Count nr of characters in the new string. */
|
|
2713 m = 0;
|
474
|
2714 for (i = 0; i < len; i += (*mb_ptr2len)(str + i))
|
7
|
2715 ++m;
|
|
2716 /* Count nr of bytes in cmdline that are overwritten by these
|
|
2717 * characters. */
|
|
2718 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0;
|
474
|
2719 i += (*mb_ptr2len)(ccline.cmdbuff + i))
|
7
|
2720 --m;
|
|
2721 if (i < ccline.cmdlen)
|
|
2722 {
|
|
2723 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
|
2724 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i));
|
|
2725 ccline.cmdlen += ccline.cmdpos + len - i;
|
|
2726 }
|
|
2727 else
|
|
2728 ccline.cmdlen = ccline.cmdpos + len;
|
|
2729 }
|
|
2730 else
|
|
2731 #endif
|
|
2732 if (ccline.cmdpos + len > ccline.cmdlen)
|
|
2733 ccline.cmdlen = ccline.cmdpos + len;
|
|
2734 }
|
|
2735 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len);
|
|
2736 ccline.cmdbuff[ccline.cmdlen] = NUL;
|
|
2737
|
|
2738 #ifdef FEAT_MBYTE
|
|
2739 if (enc_utf8)
|
|
2740 {
|
|
2741 /* When the inserted text starts with a composing character,
|
|
2742 * backup to the character before it. There could be two of them.
|
|
2743 */
|
|
2744 i = 0;
|
|
2745 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
|
2746 while (ccline.cmdpos > 0 && utf_iscomposing(c))
|
|
2747 {
|
|
2748 i = (*mb_head_off)(ccline.cmdbuff,
|
|
2749 ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
|
2750 ccline.cmdpos -= i;
|
|
2751 len += i;
|
|
2752 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
|
2753 }
|
|
2754 # ifdef FEAT_ARABIC
|
|
2755 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c))
|
|
2756 {
|
|
2757 /* Check the previous character for Arabic combining pair. */
|
|
2758 i = (*mb_head_off)(ccline.cmdbuff,
|
|
2759 ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
|
2760 if (arabic_combine(utf_ptr2char(ccline.cmdbuff
|
|
2761 + ccline.cmdpos - i), c))
|
|
2762 {
|
|
2763 ccline.cmdpos -= i;
|
|
2764 len += i;
|
|
2765 }
|
|
2766 else
|
|
2767 i = 0;
|
|
2768 }
|
|
2769 # endif
|
|
2770 if (i != 0)
|
|
2771 {
|
|
2772 /* Also backup the cursor position. */
|
|
2773 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos);
|
|
2774 ccline.cmdspos -= i;
|
|
2775 msg_col -= i;
|
|
2776 if (msg_col < 0)
|
|
2777 {
|
|
2778 msg_col += Columns;
|
|
2779 --msg_row;
|
|
2780 }
|
|
2781 }
|
|
2782 }
|
|
2783 #endif
|
|
2784
|
|
2785 if (redraw && !cmd_silent)
|
|
2786 {
|
|
2787 msg_no_more = TRUE;
|
|
2788 i = cmdline_row;
|
|
2789 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
2790 /* Avoid clearing the rest of the line too often. */
|
|
2791 if (cmdline_row != i || ccline.overstrike)
|
|
2792 msg_clr_eos();
|
|
2793 msg_no_more = FALSE;
|
|
2794 }
|
|
2795 #ifdef FEAT_FKMAP
|
|
2796 /*
|
|
2797 * If we are in Farsi command mode, the character input must be in
|
|
2798 * Insert mode. So do not advance the cmdpos.
|
|
2799 */
|
|
2800 if (!cmd_fkmap)
|
|
2801 #endif
|
|
2802 {
|
|
2803 if (KeyTyped)
|
534
|
2804 {
|
7
|
2805 m = Columns * Rows;
|
534
|
2806 if (m < 0) /* overflow, Columns or Rows at weird value */
|
|
2807 m = MAXCOL;
|
|
2808 }
|
7
|
2809 else
|
|
2810 m = MAXCOL;
|
|
2811 for (i = 0; i < len; ++i)
|
|
2812 {
|
|
2813 c = cmdline_charsize(ccline.cmdpos);
|
|
2814 #ifdef FEAT_MBYTE
|
|
2815 /* count ">" for a double-wide char that doesn't fit. */
|
|
2816 if (has_mbyte)
|
|
2817 correct_cmdspos(ccline.cmdpos, c);
|
|
2818 #endif
|
|
2819 /* Stop cursor at the end of the screen */
|
|
2820 if (ccline.cmdspos + c >= m)
|
|
2821 break;
|
|
2822 ccline.cmdspos += c;
|
|
2823 #ifdef FEAT_MBYTE
|
|
2824 if (has_mbyte)
|
|
2825 {
|
474
|
2826 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1;
|
7
|
2827 if (c > len - i - 1)
|
|
2828 c = len - i - 1;
|
|
2829 ccline.cmdpos += c;
|
|
2830 i += c;
|
|
2831 }
|
|
2832 #endif
|
|
2833 ++ccline.cmdpos;
|
|
2834 }
|
|
2835 }
|
|
2836 }
|
|
2837 if (redraw)
|
|
2838 msg_check();
|
|
2839 return retval;
|
|
2840 }
|
|
2841
|
95
|
2842 static struct cmdline_info prev_ccline;
|
|
2843 static int prev_ccline_used = FALSE;
|
|
2844
|
|
2845 /*
|
|
2846 * Save ccline, because obtaining the "=" register may execute "normal :cmd"
|
|
2847 * and overwrite it. But get_cmdline_str() may need it, thus make it
|
|
2848 * available globally in prev_ccline.
|
|
2849 */
|
|
2850 static void
|
|
2851 save_cmdline(ccp)
|
|
2852 struct cmdline_info *ccp;
|
|
2853 {
|
|
2854 if (!prev_ccline_used)
|
|
2855 {
|
|
2856 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info));
|
|
2857 prev_ccline_used = TRUE;
|
|
2858 }
|
|
2859 *ccp = prev_ccline;
|
|
2860 prev_ccline = ccline;
|
|
2861 ccline.cmdbuff = NULL;
|
|
2862 ccline.cmdprompt = NULL;
|
|
2863 }
|
|
2864
|
|
2865 /*
|
1214
|
2866 * Restore ccline after it has been saved with save_cmdline().
|
95
|
2867 */
|
|
2868 static void
|
|
2869 restore_cmdline(ccp)
|
|
2870 struct cmdline_info *ccp;
|
|
2871 {
|
|
2872 ccline = prev_ccline;
|
|
2873 prev_ccline = *ccp;
|
|
2874 }
|
|
2875
|
849
|
2876 #if defined(FEAT_EVAL) || defined(PROTO)
|
|
2877 /*
|
|
2878 * Save the command line into allocated memory. Returns a pointer to be
|
|
2879 * passed to restore_cmdline_alloc() later.
|
|
2880 * Returns NULL when failed.
|
|
2881 */
|
|
2882 char_u *
|
|
2883 save_cmdline_alloc()
|
|
2884 {
|
|
2885 struct cmdline_info *p;
|
|
2886
|
|
2887 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info));
|
|
2888 if (p != NULL)
|
|
2889 save_cmdline(p);
|
|
2890 return (char_u *)p;
|
|
2891 }
|
|
2892
|
|
2893 /*
|
|
2894 * Restore the command line from the return value of save_cmdline_alloc().
|
|
2895 */
|
|
2896 void
|
|
2897 restore_cmdline_alloc(p)
|
|
2898 char_u *p;
|
|
2899 {
|
|
2900 if (p != NULL)
|
|
2901 {
|
|
2902 restore_cmdline((struct cmdline_info *)p);
|
|
2903 vim_free(p);
|
|
2904 }
|
|
2905 }
|
|
2906 #endif
|
|
2907
|
15
|
2908 /*
|
|
2909 * paste a yank register into the command line.
|
|
2910 * used by CTRL-R command in command-line mode
|
|
2911 * insert_reg() can't be used here, because special characters from the
|
|
2912 * register contents will be interpreted as commands.
|
|
2913 *
|
|
2914 * return FAIL for failure, OK otherwise
|
|
2915 */
|
|
2916 static int
|
1015
|
2917 cmdline_paste(regname, literally, remcr)
|
15
|
2918 int regname;
|
|
2919 int literally; /* Insert text literally instead of "as typed" */
|
1015
|
2920 int remcr; /* remove trailing CR */
|
15
|
2921 {
|
|
2922 long i;
|
|
2923 char_u *arg;
|
772
|
2924 char_u *p;
|
15
|
2925 int allocated;
|
|
2926 struct cmdline_info save_ccline;
|
|
2927
|
|
2928 /* check for valid regname; also accept special characters for CTRL-R in
|
|
2929 * the command line */
|
|
2930 if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W
|
|
2931 && regname != Ctrl_A && !valid_yank_reg(regname, FALSE))
|
|
2932 return FAIL;
|
|
2933
|
|
2934 /* A register containing CTRL-R can cause an endless loop. Allow using
|
|
2935 * CTRL-C to break the loop. */
|
|
2936 line_breakcheck();
|
|
2937 if (got_int)
|
|
2938 return FAIL;
|
|
2939
|
|
2940 #ifdef FEAT_CLIPBOARD
|
|
2941 regname = may_get_selection(regname);
|
|
2942 #endif
|
|
2943
|
634
|
2944 /* Need to save and restore ccline. And set "textlock" to avoid nasty
|
632
|
2945 * things like going to another buffer when evaluating an expression. */
|
95
|
2946 save_cmdline(&save_ccline);
|
634
|
2947 ++textlock;
|
15
|
2948 i = get_spec_reg(regname, &arg, &allocated, TRUE);
|
634
|
2949 --textlock;
|
95
|
2950 restore_cmdline(&save_ccline);
|
15
|
2951
|
|
2952 if (i)
|
|
2953 {
|
|
2954 /* Got the value of a special register in "arg". */
|
|
2955 if (arg == NULL)
|
|
2956 return FAIL;
|
772
|
2957
|
|
2958 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate
|
|
2959 * part of the word. */
|
|
2960 p = arg;
|
|
2961 if (p_is && regname == Ctrl_W)
|
|
2962 {
|
|
2963 char_u *w;
|
|
2964 int len;
|
|
2965
|
|
2966 /* Locate start of last word in the cmd buffer. */
|
|
2967 for (w = ccline.cmdbuff + ccline.cmdlen; w > ccline.cmdbuff; )
|
|
2968 {
|
|
2969 #ifdef FEAT_MBYTE
|
|
2970 if (has_mbyte)
|
|
2971 {
|
|
2972 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1;
|
|
2973 if (!vim_iswordc(mb_ptr2char(w - len)))
|
|
2974 break;
|
|
2975 w -= len;
|
|
2976 }
|
|
2977 else
|
|
2978 #endif
|
|
2979 {
|
|
2980 if (!vim_iswordc(w[-1]))
|
|
2981 break;
|
|
2982 --w;
|
|
2983 }
|
|
2984 }
|
835
|
2985 len = (int)((ccline.cmdbuff + ccline.cmdlen) - w);
|
772
|
2986 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
|
|
2987 p += len;
|
|
2988 }
|
|
2989
|
|
2990 cmdline_paste_str(p, literally);
|
15
|
2991 if (allocated)
|
|
2992 vim_free(arg);
|
|
2993 return OK;
|
|
2994 }
|
|
2995
|
1015
|
2996 return cmdline_paste_reg(regname, literally, remcr);
|
15
|
2997 }
|
|
2998
|
|
2999 /*
|
|
3000 * Put a string on the command line.
|
|
3001 * When "literally" is TRUE, insert literally.
|
|
3002 * When "literally" is FALSE, insert as typed, but don't leave the command
|
|
3003 * line.
|
|
3004 */
|
|
3005 void
|
|
3006 cmdline_paste_str(s, literally)
|
|
3007 char_u *s;
|
|
3008 int literally;
|
|
3009 {
|
|
3010 int c, cv;
|
|
3011
|
|
3012 if (literally)
|
|
3013 put_on_cmdline(s, -1, TRUE);
|
|
3014 else
|
|
3015 while (*s != NUL)
|
|
3016 {
|
|
3017 cv = *s;
|
|
3018 if (cv == Ctrl_V && s[1])
|
|
3019 ++s;
|
|
3020 #ifdef FEAT_MBYTE
|
|
3021 if (has_mbyte)
|
|
3022 {
|
|
3023 c = mb_ptr2char(s);
|
|
3024 s += mb_char2len(c);
|
|
3025 }
|
|
3026 else
|
|
3027 #endif
|
|
3028 c = *s++;
|
|
3029 if (cv == Ctrl_V || c == ESC || c == Ctrl_C || c == CAR || c == NL
|
|
3030 #ifdef UNIX
|
|
3031 || c == intr_char
|
|
3032 #endif
|
|
3033 || (c == Ctrl_BSL && *s == Ctrl_N))
|
|
3034 stuffcharReadbuff(Ctrl_V);
|
|
3035 stuffcharReadbuff(c);
|
|
3036 }
|
|
3037 }
|
|
3038
|
7
|
3039 #ifdef FEAT_WILDMENU
|
|
3040 /*
|
|
3041 * Delete characters on the command line, from "from" to the current
|
|
3042 * position.
|
|
3043 */
|
|
3044 static void
|
|
3045 cmdline_del(from)
|
|
3046 int from;
|
|
3047 {
|
|
3048 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos,
|
|
3049 (size_t)(ccline.cmdlen - ccline.cmdpos + 1));
|
|
3050 ccline.cmdlen -= ccline.cmdpos - from;
|
|
3051 ccline.cmdpos = from;
|
|
3052 }
|
|
3053 #endif
|
|
3054
|
|
3055 /*
|
1214
|
3056 * this function is called when the screen size changes and with incremental
|
7
|
3057 * search
|
|
3058 */
|
|
3059 void
|
|
3060 redrawcmdline()
|
|
3061 {
|
|
3062 if (cmd_silent)
|
|
3063 return;
|
|
3064 need_wait_return = FALSE;
|
|
3065 compute_cmdrow();
|
|
3066 redrawcmd();
|
|
3067 cursorcmd();
|
|
3068 }
|
|
3069
|
|
3070 static void
|
|
3071 redrawcmdprompt()
|
|
3072 {
|
|
3073 int i;
|
|
3074
|
|
3075 if (cmd_silent)
|
|
3076 return;
|
531
|
3077 if (ccline.cmdfirstc != NUL)
|
7
|
3078 msg_putchar(ccline.cmdfirstc);
|
|
3079 if (ccline.cmdprompt != NULL)
|
|
3080 {
|
|
3081 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr);
|
|
3082 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
|
|
3083 /* do the reverse of set_cmdspos() */
|
531
|
3084 if (ccline.cmdfirstc != NUL)
|
7
|
3085 --ccline.cmdindent;
|
|
3086 }
|
|
3087 else
|
|
3088 for (i = ccline.cmdindent; i > 0; --i)
|
|
3089 msg_putchar(' ');
|
|
3090 }
|
|
3091
|
|
3092 /*
|
|
3093 * Redraw what is currently on the command line.
|
|
3094 */
|
|
3095 void
|
|
3096 redrawcmd()
|
|
3097 {
|
|
3098 if (cmd_silent)
|
|
3099 return;
|
|
3100
|
683
|
3101 /* when 'incsearch' is set there may be no command line while redrawing */
|
|
3102 if (ccline.cmdbuff == NULL)
|
|
3103 {
|
|
3104 windgoto(cmdline_row, 0);
|
|
3105 msg_clr_eos();
|
|
3106 return;
|
|
3107 }
|
|
3108
|
7
|
3109 msg_start();
|
|
3110 redrawcmdprompt();
|
|
3111
|
|
3112 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */
|
|
3113 msg_no_more = TRUE;
|
|
3114 draw_cmdline(0, ccline.cmdlen);
|
|
3115 msg_clr_eos();
|
|
3116 msg_no_more = FALSE;
|
|
3117
|
|
3118 set_cmdspos_cursor();
|
|
3119
|
|
3120 /*
|
|
3121 * An emsg() before may have set msg_scroll. This is used in normal mode,
|
|
3122 * in cmdline mode we can reset them now.
|
|
3123 */
|
|
3124 msg_scroll = FALSE; /* next message overwrites cmdline */
|
|
3125
|
|
3126 /* Typing ':' at the more prompt may set skip_redraw. We don't want this
|
|
3127 * in cmdline mode */
|
|
3128 skip_redraw = FALSE;
|
|
3129 }
|
|
3130
|
|
3131 void
|
|
3132 compute_cmdrow()
|
|
3133 {
|
540
|
3134 if (exmode_active || msg_scrolled != 0)
|
7
|
3135 cmdline_row = Rows - 1;
|
|
3136 else
|
|
3137 cmdline_row = W_WINROW(lastwin) + lastwin->w_height
|
|
3138 + W_STATUS_HEIGHT(lastwin);
|
|
3139 }
|
|
3140
|
|
3141 static void
|
|
3142 cursorcmd()
|
|
3143 {
|
|
3144 if (cmd_silent)
|
|
3145 return;
|
|
3146
|
|
3147 #ifdef FEAT_RIGHTLEFT
|
|
3148 if (cmdmsg_rl)
|
|
3149 {
|
|
3150 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1));
|
|
3151 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1;
|
|
3152 if (msg_row <= 0)
|
|
3153 msg_row = Rows - 1;
|
|
3154 }
|
|
3155 else
|
|
3156 #endif
|
|
3157 {
|
|
3158 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns);
|
|
3159 msg_col = ccline.cmdspos % (int)Columns;
|
|
3160 if (msg_row >= Rows)
|
|
3161 msg_row = Rows - 1;
|
|
3162 }
|
|
3163
|
|
3164 windgoto(msg_row, msg_col);
|
|
3165 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|
|
3166 redrawcmd_preedit();
|
|
3167 #endif
|
|
3168 #ifdef MCH_CURSOR_SHAPE
|
|
3169 mch_update_cursor();
|
|
3170 #endif
|
|
3171 }
|
|
3172
|
|
3173 void
|
|
3174 gotocmdline(clr)
|
|
3175 int clr;
|
|
3176 {
|
|
3177 msg_start();
|
|
3178 #ifdef FEAT_RIGHTLEFT
|
|
3179 if (cmdmsg_rl)
|
|
3180 msg_col = Columns - 1;
|
|
3181 else
|
|
3182 #endif
|
|
3183 msg_col = 0; /* always start in column 0 */
|
|
3184 if (clr) /* clear the bottom line(s) */
|
|
3185 msg_clr_eos(); /* will reset clear_cmdline */
|
|
3186 windgoto(cmdline_row, 0);
|
|
3187 }
|
|
3188
|
|
3189 /*
|
|
3190 * Check the word in front of the cursor for an abbreviation.
|
|
3191 * Called when the non-id character "c" has been entered.
|
|
3192 * When an abbreviation is recognized it is removed from the text with
|
|
3193 * backspaces and the replacement string is inserted, followed by "c".
|
|
3194 */
|
|
3195 static int
|
|
3196 ccheck_abbr(c)
|
|
3197 int c;
|
|
3198 {
|
|
3199 if (p_paste || no_abbr) /* no abbreviations or in paste mode */
|
|
3200 return FALSE;
|
|
3201
|
|
3202 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, 0);
|
|
3203 }
|
|
3204
|
|
3205 /*
|
|
3206 * Return FAIL if this is not an appropriate context in which to do
|
|
3207 * completion of anything, return OK if it is (even if there are no matches).
|
|
3208 * For the caller, this means that the character is just passed through like a
|
|
3209 * normal character (instead of being expanded). This allows :s/^I^D etc.
|
|
3210 */
|
|
3211 static int
|
|
3212 nextwild(xp, type, options)
|
|
3213 expand_T *xp;
|
|
3214 int type;
|
|
3215 int options; /* extra options for ExpandOne() */
|
|
3216 {
|
|
3217 int i, j;
|
|
3218 char_u *p1;
|
|
3219 char_u *p2;
|
|
3220 int oldlen;
|
|
3221 int difflen;
|
|
3222 int v;
|
|
3223
|
|
3224 if (xp->xp_numfiles == -1)
|
|
3225 {
|
|
3226 set_expand_context(xp);
|
|
3227 cmd_showtail = expand_showtail(xp);
|
|
3228 }
|
|
3229
|
|
3230 if (xp->xp_context == EXPAND_UNSUCCESSFUL)
|
|
3231 {
|
|
3232 beep_flush();
|
|
3233 return OK; /* Something illegal on command line */
|
|
3234 }
|
|
3235 if (xp->xp_context == EXPAND_NOTHING)
|
|
3236 {
|
|
3237 /* Caller can use the character as a normal char instead */
|
|
3238 return FAIL;
|
|
3239 }
|
|
3240
|
|
3241 MSG_PUTS("..."); /* show that we are busy */
|
|
3242 out_flush();
|
|
3243
|
|
3244 i = (int)(xp->xp_pattern - ccline.cmdbuff);
|
|
3245 oldlen = ccline.cmdpos - i;
|
|
3246
|
|
3247 if (type == WILD_NEXT || type == WILD_PREV)
|
|
3248 {
|
|
3249 /*
|
|
3250 * Get next/previous match for a previous expanded pattern.
|
|
3251 */
|
|
3252 p2 = ExpandOne(xp, NULL, NULL, 0, type);
|
|
3253 }
|
|
3254 else
|
|
3255 {
|
|
3256 /*
|
|
3257 * Translate string into pattern and expand it.
|
|
3258 */
|
|
3259 if ((p1 = addstar(&ccline.cmdbuff[i], oldlen, xp->xp_context)) == NULL)
|
|
3260 p2 = NULL;
|
|
3261 else
|
|
3262 {
|
|
3263 p2 = ExpandOne(xp, p1, vim_strnsave(&ccline.cmdbuff[i], oldlen),
|
|
3264 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
|
|
3265 |options, type);
|
|
3266 vim_free(p1);
|
|
3267 /* longest match: make sure it is not shorter (happens with :help */
|
|
3268 if (p2 != NULL && type == WILD_LONGEST)
|
|
3269 {
|
|
3270 for (j = 0; j < oldlen; ++j)
|
|
3271 if (ccline.cmdbuff[i + j] == '*'
|
|
3272 || ccline.cmdbuff[i + j] == '?')
|
|
3273 break;
|
|
3274 if ((int)STRLEN(p2) < j)
|
|
3275 {
|
|
3276 vim_free(p2);
|
|
3277 p2 = NULL;
|
|
3278 }
|
|
3279 }
|
|
3280 }
|
|
3281 }
|
|
3282
|
|
3283 if (p2 != NULL && !got_int)
|
|
3284 {
|
|
3285 difflen = (int)STRLEN(p2) - oldlen;
|
|
3286 if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4)
|
|
3287 {
|
|
3288 v = realloc_cmdbuff(ccline.cmdlen + difflen);
|
|
3289 xp->xp_pattern = ccline.cmdbuff + i;
|
|
3290 }
|
|
3291 else
|
|
3292 v = OK;
|
|
3293 if (v == OK)
|
|
3294 {
|
323
|
3295 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen],
|
|
3296 &ccline.cmdbuff[ccline.cmdpos],
|
|
3297 (size_t)(ccline.cmdlen - ccline.cmdpos + 1));
|
|
3298 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2));
|
7
|
3299 ccline.cmdlen += difflen;
|
|
3300 ccline.cmdpos += difflen;
|
|
3301 }
|
|
3302 }
|
|
3303 vim_free(p2);
|
|
3304
|
|
3305 redrawcmd();
|
33
|
3306 cursorcmd();
|
7
|
3307
|
|
3308 /* When expanding a ":map" command and no matches are found, assume that
|
|
3309 * the key is supposed to be inserted literally */
|
|
3310 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
|
|
3311 return FAIL;
|
|
3312
|
|
3313 if (xp->xp_numfiles <= 0 && p2 == NULL)
|
|
3314 beep_flush();
|
|
3315 else if (xp->xp_numfiles == 1)
|
|
3316 /* free expanded pattern */
|
|
3317 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
|
|
3318
|
|
3319 return OK;
|
|
3320 }
|
|
3321
|
|
3322 /*
|
|
3323 * Do wildcard expansion on the string 'str'.
|
|
3324 * Chars that should not be expanded must be preceded with a backslash.
|
|
3325 * Return a pointer to alloced memory containing the new string.
|
|
3326 * Return NULL for failure.
|
|
3327 *
|
1412
|
3328 * "orig" is the originally expanded string, copied to allocated memory. It
|
|
3329 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
|
|
3330 * WILD_PREV "orig" should be NULL.
|
|
3331 *
|
838
|
3332 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
|
|
3333 * is WILD_EXPAND_FREE or WILD_ALL.
|
7
|
3334 *
|
|
3335 * mode = WILD_FREE: just free previously expanded matches
|
|
3336 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
|
|
3337 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches
|
|
3338 * mode = WILD_NEXT: use next match in multiple match, wrap to first
|
|
3339 * mode = WILD_PREV: use previous match in multiple match, wrap to first
|
|
3340 * mode = WILD_ALL: return all matches concatenated
|
|
3341 * mode = WILD_LONGEST: return longest matched part
|
|
3342 *
|
|
3343 * options = WILD_LIST_NOTFOUND: list entries without a match
|
|
3344 * options = WILD_HOME_REPLACE: do home_replace() for buffer names
|
|
3345 * options = WILD_USE_NL: Use '\n' for WILD_ALL
|
|
3346 * options = WILD_NO_BEEP: Don't beep for multiple matches
|
|
3347 * options = WILD_ADD_SLASH: add a slash after directory names
|
|
3348 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries
|
|
3349 * options = WILD_SILENT: don't print warning messages
|
|
3350 * options = WILD_ESCAPE: put backslash before special chars
|
|
3351 *
|
|
3352 * The variables xp->xp_context and xp->xp_backslash must have been set!
|
|
3353 */
|
|
3354 char_u *
|
|
3355 ExpandOne(xp, str, orig, options, mode)
|
|
3356 expand_T *xp;
|
|
3357 char_u *str;
|
|
3358 char_u *orig; /* allocated copy of original of expanded string */
|
|
3359 int options;
|
|
3360 int mode;
|
|
3361 {
|
|
3362 char_u *ss = NULL;
|
|
3363 static int findex;
|
|
3364 static char_u *orig_save = NULL; /* kept value of orig */
|
1432
|
3365 int orig_saved = FALSE;
|
7
|
3366 int i;
|
|
3367 long_u len;
|
|
3368 int non_suf_match; /* number without matching suffix */
|
|
3369
|
|
3370 /*
|
|
3371 * first handle the case of using an old match
|
|
3372 */
|
|
3373 if (mode == WILD_NEXT || mode == WILD_PREV)
|
|
3374 {
|
|
3375 if (xp->xp_numfiles > 0)
|
|
3376 {
|
|
3377 if (mode == WILD_PREV)
|
|
3378 {
|
|
3379 if (findex == -1)
|
|
3380 findex = xp->xp_numfiles;
|
|
3381 --findex;
|
|
3382 }
|
|
3383 else /* mode == WILD_NEXT */
|
|
3384 ++findex;
|
|
3385
|
|
3386 /*
|
|
3387 * When wrapping around, return the original string, set findex to
|
|
3388 * -1.
|
|
3389 */
|
|
3390 if (findex < 0)
|
|
3391 {
|
|
3392 if (orig_save == NULL)
|
|
3393 findex = xp->xp_numfiles - 1;
|
|
3394 else
|
|
3395 findex = -1;
|
|
3396 }
|
|
3397 if (findex >= xp->xp_numfiles)
|
|
3398 {
|
|
3399 if (orig_save == NULL)
|
|
3400 findex = 0;
|
|
3401 else
|
|
3402 findex = -1;
|
|
3403 }
|
|
3404 #ifdef FEAT_WILDMENU
|
|
3405 if (p_wmnu)
|
|
3406 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
|
|
3407 findex, cmd_showtail);
|
|
3408 #endif
|
|
3409 if (findex == -1)
|
|
3410 return vim_strsave(orig_save);
|
|
3411 return vim_strsave(xp->xp_files[findex]);
|
|
3412 }
|
|
3413 else
|
|
3414 return NULL;
|
|
3415 }
|
|
3416
|
1412
|
3417 /* free old names */
|
7
|
3418 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
|
|
3419 {
|
|
3420 FreeWild(xp->xp_numfiles, xp->xp_files);
|
|
3421 xp->xp_numfiles = -1;
|
|
3422 vim_free(orig_save);
|
|
3423 orig_save = NULL;
|
|
3424 }
|
|
3425 findex = 0;
|
|
3426
|
|
3427 if (mode == WILD_FREE) /* only release file name */
|
|
3428 return NULL;
|
|
3429
|
|
3430 if (xp->xp_numfiles == -1)
|
|
3431 {
|
|
3432 vim_free(orig_save);
|
|
3433 orig_save = orig;
|
1432
|
3434 orig_saved = TRUE;
|
7
|
3435
|
|
3436 /*
|
|
3437 * Do the expansion.
|
|
3438 */
|
|
3439 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files,
|
|
3440 options) == FAIL)
|
|
3441 {
|
|
3442 #ifdef FNAME_ILLEGAL
|
|
3443 /* Illegal file name has been silently skipped. But when there
|
|
3444 * are wildcards, the real problem is that there was no match,
|
|
3445 * causing the pattern to be added, which has illegal characters.
|
|
3446 */
|
|
3447 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND))
|
|
3448 EMSG2(_(e_nomatch2), str);
|
|
3449 #endif
|
|
3450 }
|
|
3451 else if (xp->xp_numfiles == 0)
|
|
3452 {
|
|
3453 if (!(options & WILD_SILENT))
|
|
3454 EMSG2(_(e_nomatch2), str);
|
|
3455 }
|
|
3456 else
|
|
3457 {
|
|
3458 /* Escape the matches for use on the command line. */
|
|
3459 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
|
|
3460
|
|
3461 /*
|
|
3462 * Check for matching suffixes in file names.
|
|
3463 */
|
|
3464 if (mode != WILD_ALL && mode != WILD_LONGEST)
|
|
3465 {
|
|
3466 if (xp->xp_numfiles)
|
|
3467 non_suf_match = xp->xp_numfiles;
|
|
3468 else
|
|
3469 non_suf_match = 1;
|
|
3470 if ((xp->xp_context == EXPAND_FILES
|
|
3471 || xp->xp_context == EXPAND_DIRECTORIES)
|
|
3472 && xp->xp_numfiles > 1)
|
|
3473 {
|
|
3474 /*
|
|
3475 * More than one match; check suffix.
|
|
3476 * The files will have been sorted on matching suffix in
|
|
3477 * expand_wildcards, only need to check the first two.
|
|
3478 */
|
|
3479 non_suf_match = 0;
|
|
3480 for (i = 0; i < 2; ++i)
|
|
3481 if (match_suffix(xp->xp_files[i]))
|
|
3482 ++non_suf_match;
|
|
3483 }
|
|
3484 if (non_suf_match != 1)
|
|
3485 {
|
|
3486 /* Can we ever get here unless it's while expanding
|
|
3487 * interactively? If not, we can get rid of this all
|
|
3488 * together. Don't really want to wait for this message
|
|
3489 * (and possibly have to hit return to continue!).
|
|
3490 */
|
|
3491 if (!(options & WILD_SILENT))
|
|
3492 EMSG(_(e_toomany));
|
|
3493 else if (!(options & WILD_NO_BEEP))
|
|
3494 beep_flush();
|
|
3495 }
|
|
3496 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
|
|
3497 ss = vim_strsave(xp->xp_files[0]);
|
|
3498 }
|
|
3499 }
|
|
3500 }
|
|
3501
|
|
3502 /* Find longest common part */
|
|
3503 if (mode == WILD_LONGEST && xp->xp_numfiles > 0)
|
|
3504 {
|
|
3505 for (len = 0; xp->xp_files[0][len]; ++len)
|
|
3506 {
|
|
3507 for (i = 0; i < xp->xp_numfiles; ++i)
|
|
3508 {
|
|
3509 #ifdef CASE_INSENSITIVE_FILENAME
|
|
3510 if (xp->xp_context == EXPAND_DIRECTORIES
|
|
3511 || xp->xp_context == EXPAND_FILES
|
714
|
3512 || xp->xp_context == EXPAND_SHELLCMD
|
7
|
3513 || xp->xp_context == EXPAND_BUFFERS)
|
|
3514 {
|
|
3515 if (TOLOWER_LOC(xp->xp_files[i][len]) !=
|
|
3516 TOLOWER_LOC(xp->xp_files[0][len]))
|
|
3517 break;
|
|
3518 }
|
|
3519 else
|
|
3520 #endif
|
|
3521 if (xp->xp_files[i][len] != xp->xp_files[0][len])
|
|
3522 break;
|
|
3523 }
|
|
3524 if (i < xp->xp_numfiles)
|
|
3525 {
|
|
3526 if (!(options & WILD_NO_BEEP))
|
|
3527 vim_beep();
|
|
3528 break;
|
|
3529 }
|
|
3530 }
|
|
3531 ss = alloc((unsigned)len + 1);
|
|
3532 if (ss)
|
419
|
3533 vim_strncpy(ss, xp->xp_files[0], (size_t)len);
|
7
|
3534 findex = -1; /* next p_wc gets first one */
|
|
3535 }
|
|
3536
|
|
3537 /* Concatenate all matching names */
|
|
3538 if (mode == WILD_ALL && xp->xp_numfiles > 0)
|
|
3539 {
|
|
3540 len = 0;
|
|
3541 for (i = 0; i < xp->xp_numfiles; ++i)
|
|
3542 len += (long_u)STRLEN(xp->xp_files[i]) + 1;
|
|
3543 ss = lalloc(len, TRUE);
|
|
3544 if (ss != NULL)
|
|
3545 {
|
|
3546 *ss = NUL;
|
|
3547 for (i = 0; i < xp->xp_numfiles; ++i)
|
|
3548 {
|
|
3549 STRCAT(ss, xp->xp_files[i]);
|
|
3550 if (i != xp->xp_numfiles - 1)
|
|
3551 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
|
|
3552 }
|
|
3553 }
|
|
3554 }
|
|
3555
|
|
3556 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
|
|
3557 ExpandCleanup(xp);
|
|
3558
|
1412
|
3559 /* Free "orig" if it wasn't stored in "orig_save". */
|
1432
|
3560 if (!orig_saved)
|
1412
|
3561 vim_free(orig);
|
|
3562
|
7
|
3563 return ss;
|
|
3564 }
|
|
3565
|
|
3566 /*
|
|
3567 * Prepare an expand structure for use.
|
|
3568 */
|
|
3569 void
|
|
3570 ExpandInit(xp)
|
|
3571 expand_T *xp;
|
|
3572 {
|
|
3573 xp->xp_backslash = XP_BS_NONE;
|
632
|
3574 #ifndef BACKSLASH_IN_FILENAME
|
|
3575 xp->xp_shell = FALSE;
|
|
3576 #endif
|
7
|
3577 xp->xp_numfiles = -1;
|
|
3578 xp->xp_files = NULL;
|
632
|
3579 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
3580 xp->xp_arg = NULL;
|
|
3581 #endif
|
7
|
3582 }
|
|
3583
|
|
3584 /*
|
|
3585 * Cleanup an expand structure after use.
|
|
3586 */
|
|
3587 void
|
|
3588 ExpandCleanup(xp)
|
|
3589 expand_T *xp;
|
|
3590 {
|
|
3591 if (xp->xp_numfiles >= 0)
|
|
3592 {
|
|
3593 FreeWild(xp->xp_numfiles, xp->xp_files);
|
|
3594 xp->xp_numfiles = -1;
|
|
3595 }
|
|
3596 }
|
|
3597
|
|
3598 void
|
|
3599 ExpandEscape(xp, str, numfiles, files, options)
|
|
3600 expand_T *xp;
|
|
3601 char_u *str;
|
|
3602 int numfiles;
|
|
3603 char_u **files;
|
|
3604 int options;
|
|
3605 {
|
|
3606 int i;
|
|
3607 char_u *p;
|
|
3608
|
|
3609 /*
|
|
3610 * May change home directory back to "~"
|
|
3611 */
|
|
3612 if (options & WILD_HOME_REPLACE)
|
|
3613 tilde_replace(str, numfiles, files);
|
|
3614
|
|
3615 if (options & WILD_ESCAPE)
|
|
3616 {
|
|
3617 if (xp->xp_context == EXPAND_FILES
|
714
|
3618 || xp->xp_context == EXPAND_SHELLCMD
|
7
|
3619 || xp->xp_context == EXPAND_BUFFERS
|
|
3620 || xp->xp_context == EXPAND_DIRECTORIES)
|
|
3621 {
|
|
3622 /*
|
|
3623 * Insert a backslash into a file name before a space, \, %, #
|
|
3624 * and wildmatch characters, except '~'.
|
|
3625 */
|
|
3626 for (i = 0; i < numfiles; ++i)
|
|
3627 {
|
|
3628 /* for ":set path=" we need to escape spaces twice */
|
|
3629 if (xp->xp_backslash == XP_BS_THREE)
|
|
3630 {
|
|
3631 p = vim_strsave_escaped(files[i], (char_u *)" ");
|
|
3632 if (p != NULL)
|
|
3633 {
|
|
3634 vim_free(files[i]);
|
|
3635 files[i] = p;
|
719
|
3636 #if defined(BACKSLASH_IN_FILENAME)
|
7
|
3637 p = vim_strsave_escaped(files[i], (char_u *)" ");
|
|
3638 if (p != NULL)
|
|
3639 {
|
|
3640 vim_free(files[i]);
|
|
3641 files[i] = p;
|
|
3642 }
|
|
3643 #endif
|
|
3644 }
|
|
3645 }
|
|
3646 #ifdef BACKSLASH_IN_FILENAME
|
|
3647 {
|
|
3648 char_u buf[20];
|
|
3649 int j = 0;
|
|
3650
|
|
3651 /* Don't escape '[' and '{' if they are in 'isfname'. */
|
|
3652 for (p = PATH_ESC_CHARS; *p != NUL; ++p)
|
|
3653 if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
|
|
3654 buf[j++] = *p;
|
|
3655 buf[j] = NUL;
|
|
3656 p = vim_strsave_escaped(files[i], buf);
|
|
3657 }
|
|
3658 #else
|
632
|
3659 p = vim_strsave_escaped(files[i],
|
|
3660 xp->xp_shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
|
7
|
3661 #endif
|
|
3662 if (p != NULL)
|
|
3663 {
|
|
3664 vim_free(files[i]);
|
|
3665 files[i] = p;
|
|
3666 }
|
|
3667
|
|
3668 /* If 'str' starts with "\~", replace "~" at start of
|
|
3669 * files[i] with "\~". */
|
|
3670 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~')
|
435
|
3671 escape_fname(&files[i]);
|
7
|
3672 }
|
|
3673 xp->xp_backslash = XP_BS_NONE;
|
435
|
3674
|
|
3675 /* If the first file starts with a '+' escape it. Otherwise it
|
|
3676 * could be seen as "+cmd". */
|
|
3677 if (*files[0] == '+')
|
|
3678 escape_fname(&files[0]);
|
7
|
3679 }
|
|
3680 else if (xp->xp_context == EXPAND_TAGS)
|
|
3681 {
|
|
3682 /*
|
|
3683 * Insert a backslash before characters in a tag name that
|
|
3684 * would terminate the ":tag" command.
|
|
3685 */
|
|
3686 for (i = 0; i < numfiles; ++i)
|
|
3687 {
|
|
3688 p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
|
|
3689 if (p != NULL)
|
|
3690 {
|
|
3691 vim_free(files[i]);
|
|
3692 files[i] = p;
|
|
3693 }
|
|
3694 }
|
|
3695 }
|
|
3696 }
|
|
3697 }
|
|
3698
|
|
3699 /*
|
435
|
3700 * Put a backslash before the file name in "pp", which is in allocated memory.
|
|
3701 */
|
|
3702 static void
|
|
3703 escape_fname(pp)
|
|
3704 char_u **pp;
|
|
3705 {
|
|
3706 char_u *p;
|
|
3707
|
|
3708 p = alloc((unsigned)(STRLEN(*pp) + 2));
|
|
3709 if (p != NULL)
|
|
3710 {
|
|
3711 p[0] = '\\';
|
|
3712 STRCPY(p + 1, *pp);
|
|
3713 vim_free(*pp);
|
|
3714 *pp = p;
|
|
3715 }
|
|
3716 }
|
|
3717
|
|
3718 /*
|
7
|
3719 * For each file name in files[num_files]:
|
|
3720 * If 'orig_pat' starts with "~/", replace the home directory with "~".
|
|
3721 */
|
|
3722 void
|
|
3723 tilde_replace(orig_pat, num_files, files)
|
|
3724 char_u *orig_pat;
|
|
3725 int num_files;
|
|
3726 char_u **files;
|
|
3727 {
|
|
3728 int i;
|
|
3729 char_u *p;
|
|
3730
|
|
3731 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1]))
|
|
3732 {
|
|
3733 for (i = 0; i < num_files; ++i)
|
|
3734 {
|
|
3735 p = home_replace_save(NULL, files[i]);
|
|
3736 if (p != NULL)
|
|
3737 {
|
|
3738 vim_free(files[i]);
|
|
3739 files[i] = p;
|
|
3740 }
|
|
3741 }
|
|
3742 }
|
|
3743 }
|
|
3744
|
|
3745 /*
|
|
3746 * Show all matches for completion on the command line.
|
|
3747 * Returns EXPAND_NOTHING when the character that triggered expansion should
|
|
3748 * be inserted like a normal character.
|
|
3749 */
|
|
3750 /*ARGSUSED*/
|
|
3751 static int
|
|
3752 showmatches(xp, wildmenu)
|
|
3753 expand_T *xp;
|
|
3754 int wildmenu;
|
|
3755 {
|
|
3756 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m])
|
|
3757 int num_files;
|
|
3758 char_u **files_found;
|
|
3759 int i, j, k;
|
|
3760 int maxlen;
|
|
3761 int lines;
|
|
3762 int columns;
|
|
3763 char_u *p;
|
|
3764 int lastlen;
|
|
3765 int attr;
|
|
3766 int showtail;
|
|
3767
|
|
3768 if (xp->xp_numfiles == -1)
|
|
3769 {
|
|
3770 set_expand_context(xp);
|
|
3771 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos,
|
|
3772 &num_files, &files_found);
|
|
3773 showtail = expand_showtail(xp);
|
|
3774 if (i != EXPAND_OK)
|
|
3775 return i;
|
|
3776
|
|
3777 }
|
|
3778 else
|
|
3779 {
|
|
3780 num_files = xp->xp_numfiles;
|
|
3781 files_found = xp->xp_files;
|
|
3782 showtail = cmd_showtail;
|
|
3783 }
|
|
3784
|
|
3785 #ifdef FEAT_WILDMENU
|
|
3786 if (!wildmenu)
|
|
3787 {
|
|
3788 #endif
|
|
3789 msg_didany = FALSE; /* lines_left will be set */
|
|
3790 msg_start(); /* prepare for paging */
|
|
3791 msg_putchar('\n');
|
|
3792 out_flush();
|
|
3793 cmdline_row = msg_row;
|
|
3794 msg_didany = FALSE; /* lines_left will be set again */
|
|
3795 msg_start(); /* prepare for paging */
|
|
3796 #ifdef FEAT_WILDMENU
|
|
3797 }
|
|
3798 #endif
|
|
3799
|
|
3800 if (got_int)
|
|
3801 got_int = FALSE; /* only int. the completion, not the cmd line */
|
|
3802 #ifdef FEAT_WILDMENU
|
|
3803 else if (wildmenu)
|
|
3804 win_redr_status_matches(xp, num_files, files_found, 0, showtail);
|
|
3805 #endif
|
|
3806 else
|
|
3807 {
|
|
3808 /* find the length of the longest file name */
|
|
3809 maxlen = 0;
|
|
3810 for (i = 0; i < num_files; ++i)
|
|
3811 {
|
|
3812 if (!showtail && (xp->xp_context == EXPAND_FILES
|
714
|
3813 || xp->xp_context == EXPAND_SHELLCMD
|
7
|
3814 || xp->xp_context == EXPAND_BUFFERS))
|
|
3815 {
|
|
3816 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE);
|
|
3817 j = vim_strsize(NameBuff);
|
|
3818 }
|
|
3819 else
|
|
3820 j = vim_strsize(L_SHOWFILE(i));
|
|
3821 if (j > maxlen)
|
|
3822 maxlen = j;
|
|
3823 }
|
|
3824
|
|
3825 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
3826 lines = num_files;
|
|
3827 else
|
|
3828 {
|
|
3829 /* compute the number of columns and lines for the listing */
|
|
3830 maxlen += 2; /* two spaces between file names */
|
|
3831 columns = ((int)Columns + 2) / maxlen;
|
|
3832 if (columns < 1)
|
|
3833 columns = 1;
|
|
3834 lines = (num_files + columns - 1) / columns;
|
|
3835 }
|
|
3836
|
|
3837 attr = hl_attr(HLF_D); /* find out highlighting for directories */
|
|
3838
|
|
3839 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
3840 {
|
|
3841 MSG_PUTS_ATTR(_("tagname"), hl_attr(HLF_T));
|
|
3842 msg_clr_eos();
|
|
3843 msg_advance(maxlen - 3);
|
|
3844 MSG_PUTS_ATTR(_(" kind file\n"), hl_attr(HLF_T));
|
|
3845 }
|
|
3846
|
|
3847 /* list the files line by line */
|
|
3848 for (i = 0; i < lines; ++i)
|
|
3849 {
|
|
3850 lastlen = 999;
|
|
3851 for (k = i; k < num_files; k += lines)
|
|
3852 {
|
|
3853 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
3854 {
|
|
3855 msg_outtrans_attr(files_found[k], hl_attr(HLF_D));
|
|
3856 p = files_found[k] + STRLEN(files_found[k]) + 1;
|
|
3857 msg_advance(maxlen + 1);
|
|
3858 msg_puts(p);
|
|
3859 msg_advance(maxlen + 3);
|
|
3860 msg_puts_long_attr(p + 2, hl_attr(HLF_D));
|
|
3861 break;
|
|
3862 }
|
|
3863 for (j = maxlen - lastlen; --j >= 0; )
|
|
3864 msg_putchar(' ');
|
|
3865 if (xp->xp_context == EXPAND_FILES
|
714
|
3866 || xp->xp_context == EXPAND_SHELLCMD
|
7
|
3867 || xp->xp_context == EXPAND_BUFFERS)
|
|
3868 {
|
|
3869 /* highlight directories */
|
|
3870 j = (mch_isdir(files_found[k]));
|
|
3871 if (showtail)
|
|
3872 p = L_SHOWFILE(k);
|
|
3873 else
|
|
3874 {
|
|
3875 home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
|
|
3876 TRUE);
|
|
3877 p = NameBuff;
|
|
3878 }
|
|
3879 }
|
|
3880 else
|
|
3881 {
|
|
3882 j = FALSE;
|
|
3883 p = L_SHOWFILE(k);
|
|
3884 }
|
|
3885 lastlen = msg_outtrans_attr(p, j ? attr : 0);
|
|
3886 }
|
|
3887 if (msg_col > 0) /* when not wrapped around */
|
|
3888 {
|
|
3889 msg_clr_eos();
|
|
3890 msg_putchar('\n');
|
|
3891 }
|
|
3892 out_flush(); /* show one line at a time */
|
|
3893 if (got_int)
|
|
3894 {
|
|
3895 got_int = FALSE;
|
|
3896 break;
|
|
3897 }
|
|
3898 }
|
|
3899
|
|
3900 /*
|
|
3901 * we redraw the command below the lines that we have just listed
|
|
3902 * This is a bit tricky, but it saves a lot of screen updating.
|
|
3903 */
|
|
3904 cmdline_row = msg_row; /* will put it back later */
|
|
3905 }
|
|
3906
|
|
3907 if (xp->xp_numfiles == -1)
|
|
3908 FreeWild(num_files, files_found);
|
|
3909
|
|
3910 return EXPAND_OK;
|
|
3911 }
|
|
3912
|
|
3913 /*
|
|
3914 * Private gettail for showmatches() (and win_redr_status_matches()):
|
|
3915 * Find tail of file name path, but ignore trailing "/".
|
|
3916 */
|
|
3917 char_u *
|
|
3918 sm_gettail(s)
|
|
3919 char_u *s;
|
|
3920 {
|
|
3921 char_u *p;
|
|
3922 char_u *t = s;
|
|
3923 int had_sep = FALSE;
|
|
3924
|
|
3925 for (p = s; *p != NUL; )
|
|
3926 {
|
|
3927 if (vim_ispathsep(*p)
|
|
3928 #ifdef BACKSLASH_IN_FILENAME
|
|
3929 && !rem_backslash(p)
|
|
3930 #endif
|
|
3931 )
|
|
3932 had_sep = TRUE;
|
|
3933 else if (had_sep)
|
|
3934 {
|
|
3935 t = p;
|
|
3936 had_sep = FALSE;
|
|
3937 }
|
39
|
3938 mb_ptr_adv(p);
|
7
|
3939 }
|
|
3940 return t;
|
|
3941 }
|
|
3942
|
|
3943 /*
|
|
3944 * Return TRUE if we only need to show the tail of completion matches.
|
|
3945 * When not completing file names or there is a wildcard in the path FALSE is
|
|
3946 * returned.
|
|
3947 */
|
|
3948 static int
|
|
3949 expand_showtail(xp)
|
|
3950 expand_T *xp;
|
|
3951 {
|
|
3952 char_u *s;
|
|
3953 char_u *end;
|
|
3954
|
|
3955 /* When not completing file names a "/" may mean something different. */
|
714
|
3956 if (xp->xp_context != EXPAND_FILES
|
|
3957 && xp->xp_context != EXPAND_SHELLCMD
|
|
3958 && xp->xp_context != EXPAND_DIRECTORIES)
|
7
|
3959 return FALSE;
|
|
3960
|
|
3961 end = gettail(xp->xp_pattern);
|
|
3962 if (end == xp->xp_pattern) /* there is no path separator */
|
|
3963 return FALSE;
|
|
3964
|
|
3965 for (s = xp->xp_pattern; s < end; s++)
|
|
3966 {
|
|
3967 /* Skip escaped wildcards. Only when the backslash is not a path
|
|
3968 * separator, on DOS the '*' "path\*\file" must not be skipped. */
|
|
3969 if (rem_backslash(s))
|
|
3970 ++s;
|
|
3971 else if (vim_strchr((char_u *)"*?[", *s) != NULL)
|
|
3972 return FALSE;
|
|
3973 }
|
|
3974 return TRUE;
|
|
3975 }
|
|
3976
|
|
3977 /*
|
|
3978 * Prepare a string for expansion.
|
|
3979 * When expanding file names: The string will be used with expand_wildcards().
|
|
3980 * Copy the file name into allocated memory and add a '*' at the end.
|
|
3981 * When expanding other names: The string will be used with regcomp(). Copy
|
|
3982 * the name into allocated memory and prepend "^".
|
|
3983 */
|
|
3984 char_u *
|
|
3985 addstar(fname, len, context)
|
|
3986 char_u *fname;
|
|
3987 int len;
|
|
3988 int context; /* EXPAND_FILES etc. */
|
|
3989 {
|
|
3990 char_u *retval;
|
|
3991 int i, j;
|
|
3992 int new_len;
|
|
3993 char_u *tail;
|
|
3994
|
714
|
3995 if (context != EXPAND_FILES
|
|
3996 && context != EXPAND_SHELLCMD
|
|
3997 && context != EXPAND_DIRECTORIES)
|
7
|
3998 {
|
|
3999 /*
|
|
4000 * Matching will be done internally (on something other than files).
|
|
4001 * So we convert the file-matching-type wildcards into our kind for
|
|
4002 * use with vim_regcomp(). First work out how long it will be:
|
|
4003 */
|
|
4004
|
|
4005 /* For help tags the translation is done in find_help_tags().
|
|
4006 * For a tag pattern starting with "/" no translation is needed. */
|
|
4007 if (context == EXPAND_HELP
|
|
4008 || context == EXPAND_COLORS
|
|
4009 || context == EXPAND_COMPILER
|
|
4010 || (context == EXPAND_TAGS && fname[0] == '/'))
|
|
4011 retval = vim_strnsave(fname, len);
|
|
4012 else
|
|
4013 {
|
|
4014 new_len = len + 2; /* +2 for '^' at start, NUL at end */
|
|
4015 for (i = 0; i < len; i++)
|
|
4016 {
|
|
4017 if (fname[i] == '*' || fname[i] == '~')
|
|
4018 new_len++; /* '*' needs to be replaced by ".*"
|
|
4019 '~' needs to be replaced by "\~" */
|
|
4020
|
|
4021 /* Buffer names are like file names. "." should be literal */
|
|
4022 if (context == EXPAND_BUFFERS && fname[i] == '.')
|
|
4023 new_len++; /* "." becomes "\." */
|
|
4024
|
|
4025 /* Custom expansion takes care of special things, match
|
|
4026 * backslashes literally (perhaps also for other types?) */
|
634
|
4027 if ((context == EXPAND_USER_DEFINED
|
|
4028 || context == EXPAND_USER_LIST) && fname[i] == '\\')
|
7
|
4029 new_len++; /* '\' becomes "\\" */
|
|
4030 }
|
|
4031 retval = alloc(new_len);
|
|
4032 if (retval != NULL)
|
|
4033 {
|
|
4034 retval[0] = '^';
|
|
4035 j = 1;
|
|
4036 for (i = 0; i < len; i++, j++)
|
|
4037 {
|
|
4038 /* Skip backslash. But why? At least keep it for custom
|
|
4039 * expansion. */
|
|
4040 if (context != EXPAND_USER_DEFINED
|
407
|
4041 && context != EXPAND_USER_LIST
|
|
4042 && fname[i] == '\\'
|
|
4043 && ++i == len)
|
7
|
4044 break;
|
|
4045
|
|
4046 switch (fname[i])
|
|
4047 {
|
|
4048 case '*': retval[j++] = '.';
|
|
4049 break;
|
|
4050 case '~': retval[j++] = '\\';
|
|
4051 break;
|
|
4052 case '?': retval[j] = '.';
|
|
4053 continue;
|
|
4054 case '.': if (context == EXPAND_BUFFERS)
|
|
4055 retval[j++] = '\\';
|
|
4056 break;
|
407
|
4057 case '\\': if (context == EXPAND_USER_DEFINED
|
|
4058 || context == EXPAND_USER_LIST)
|
7
|
4059 retval[j++] = '\\';
|
|
4060 break;
|
|
4061 }
|
|
4062 retval[j] = fname[i];
|
|
4063 }
|
|
4064 retval[j] = NUL;
|
|
4065 }
|
|
4066 }
|
|
4067 }
|
|
4068 else
|
|
4069 {
|
|
4070 retval = alloc(len + 4);
|
|
4071 if (retval != NULL)
|
|
4072 {
|
419
|
4073 vim_strncpy(retval, fname, len);
|
7
|
4074
|
|
4075 /*
|
831
|
4076 * Don't add a star to *, ~, ~user, $var or `cmd`.
|
|
4077 * * would become **, which walks the whole tree.
|
7
|
4078 * ~ would be at the start of the file name, but not the tail.
|
|
4079 * $ could be anywhere in the tail.
|
|
4080 * ` could be anywhere in the file name.
|
1484
|
4081 * When the name ends in '$' don't add a star, remove the '$'.
|
7
|
4082 */
|
|
4083 tail = gettail(retval);
|
|
4084 if ((*retval != '~' || tail != retval)
|
831
|
4085 && (len == 0 || retval[len - 1] != '*')
|
7
|
4086 && vim_strchr(tail, '$') == NULL
|
|
4087 && vim_strchr(retval, '`') == NULL)
|
|
4088 retval[len++] = '*';
|
1484
|
4089 else if (len > 0 && retval[len - 1] == '$')
|
|
4090 --len;
|
7
|
4091 retval[len] = NUL;
|
|
4092 }
|
|
4093 }
|
|
4094 return retval;
|
|
4095 }
|
|
4096
|
|
4097 /*
|
|
4098 * Must parse the command line so far to work out what context we are in.
|
|
4099 * Completion can then be done based on that context.
|
|
4100 * This routine sets the variables:
|
|
4101 * xp->xp_pattern The start of the pattern to be expanded within
|
|
4102 * the command line (ends at the cursor).
|
|
4103 * xp->xp_context The type of thing to expand. Will be one of:
|
|
4104 *
|
|
4105 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on
|
|
4106 * the command line, like an unknown command. Caller
|
|
4107 * should beep.
|
|
4108 * EXPAND_NOTHING Unrecognised context for completion, use char like
|
|
4109 * a normal char, rather than for completion. eg
|
|
4110 * :s/^I/
|
|
4111 * EXPAND_COMMANDS Cursor is still touching the command, so complete
|
|
4112 * it.
|
|
4113 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands.
|
|
4114 * EXPAND_FILES After command with XFILE set, or after setting
|
|
4115 * with P_EXPAND set. eg :e ^I, :w>>^I
|
|
4116 * EXPAND_DIRECTORIES In some cases this is used instead of the latter
|
|
4117 * when we know only directories are of interest. eg
|
|
4118 * :set dir=^I
|
714
|
4119 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd".
|
7
|
4120 * EXPAND_SETTINGS Complete variable names. eg :set d^I
|
|
4121 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I
|
|
4122 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I
|
|
4123 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect
|
|
4124 * EXPAND_HELP Complete tags from the file 'helpfile'/tags
|
|
4125 * EXPAND_EVENTS Complete event names
|
|
4126 * EXPAND_SYNTAX Complete :syntax command arguments
|
|
4127 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names
|
|
4128 * EXPAND_AUGROUP Complete autocommand group names
|
|
4129 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I
|
|
4130 * EXPAND_MAPPINGS Complete mapping and abbreviation names,
|
|
4131 * eg :unmap a^I , :cunab x^I
|
|
4132 * EXPAND_FUNCTIONS Complete internal or user defined function names,
|
|
4133 * eg :call sub^I
|
|
4134 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I
|
|
4135 * EXPAND_EXPRESSION Complete internal or user defined function/variable
|
|
4136 * names in expressions, eg :while s^I
|
|
4137 * EXPAND_ENV_VARS Complete environment variable names
|
|
4138 */
|
|
4139 static void
|
|
4140 set_expand_context(xp)
|
|
4141 expand_T *xp;
|
|
4142 {
|
168
|
4143 /* only expansion for ':', '>' and '=' command-lines */
|
7
|
4144 if (ccline.cmdfirstc != ':'
|
|
4145 #ifdef FEAT_EVAL
|
168
|
4146 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '='
|
531
|
4147 && !ccline.input_fn
|
7
|
4148 #endif
|
|
4149 )
|
|
4150 {
|
|
4151 xp->xp_context = EXPAND_NOTHING;
|
|
4152 return;
|
|
4153 }
|
|
4154 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos);
|
|
4155 }
|
|
4156
|
|
4157 void
|
|
4158 set_cmd_context(xp, str, len, col)
|
|
4159 expand_T *xp;
|
|
4160 char_u *str; /* start of command line */
|
|
4161 int len; /* length of command line (excl. NUL) */
|
|
4162 int col; /* position of cursor */
|
|
4163 {
|
|
4164 int old_char = NUL;
|
|
4165 char_u *nextcomm;
|
|
4166
|
|
4167 /*
|
|
4168 * Avoid a UMR warning from Purify, only save the character if it has been
|
|
4169 * written before.
|
|
4170 */
|
|
4171 if (col < len)
|
|
4172 old_char = str[col];
|
|
4173 str[col] = NUL;
|
|
4174 nextcomm = str;
|
168
|
4175
|
|
4176 #ifdef FEAT_EVAL
|
|
4177 if (ccline.cmdfirstc == '=')
|
1322
|
4178 {
|
|
4179 # ifdef FEAT_CMDL_COMPL
|
168
|
4180 /* pass CMD_SIZE because there is no real command */
|
|
4181 set_context_for_expression(xp, str, CMD_SIZE);
|
1322
|
4182 # endif
|
|
4183 }
|
531
|
4184 else if (ccline.input_fn)
|
|
4185 {
|
|
4186 xp->xp_context = ccline.xp_context;
|
|
4187 xp->xp_pattern = ccline.cmdbuff;
|
1322
|
4188 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
|
531
|
4189 xp->xp_arg = ccline.xp_arg;
|
1322
|
4190 # endif
|
531
|
4191 }
|
168
|
4192 else
|
|
4193 #endif
|
|
4194 while (nextcomm != NULL)
|
|
4195 nextcomm = set_one_cmd_context(xp, nextcomm);
|
|
4196
|
7
|
4197 str[col] = old_char;
|
|
4198 }
|
|
4199
|
|
4200 /*
|
|
4201 * Expand the command line "str" from context "xp".
|
|
4202 * "xp" must have been set by set_cmd_context().
|
|
4203 * xp->xp_pattern points into "str", to where the text that is to be expanded
|
|
4204 * starts.
|
|
4205 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the
|
|
4206 * cursor.
|
|
4207 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the
|
|
4208 * key that triggered expansion literally.
|
|
4209 * Returns EXPAND_OK otherwise.
|
|
4210 */
|
|
4211 int
|
|
4212 expand_cmdline(xp, str, col, matchcount, matches)
|
|
4213 expand_T *xp;
|
|
4214 char_u *str; /* start of command line */
|
|
4215 int col; /* position of cursor */
|
|
4216 int *matchcount; /* return: nr of matches */
|
|
4217 char_u ***matches; /* return: array of pointers to matches */
|
|
4218 {
|
|
4219 char_u *file_str = NULL;
|
|
4220
|
|
4221 if (xp->xp_context == EXPAND_UNSUCCESSFUL)
|
|
4222 {
|
|
4223 beep_flush();
|
|
4224 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */
|
|
4225 }
|
|
4226 if (xp->xp_context == EXPAND_NOTHING)
|
|
4227 {
|
|
4228 /* Caller can use the character as a normal char instead */
|
|
4229 return EXPAND_NOTHING;
|
|
4230 }
|
|
4231
|
|
4232 /* add star to file name, or convert to regexp if not exp. files. */
|
|
4233 file_str = addstar(xp->xp_pattern,
|
|
4234 (int)(str + col - xp->xp_pattern), xp->xp_context);
|
|
4235 if (file_str == NULL)
|
|
4236 return EXPAND_UNSUCCESSFUL;
|
|
4237
|
|
4238 /* find all files that match the description */
|
|
4239 if (ExpandFromContext(xp, file_str, matchcount, matches,
|
|
4240 WILD_ADD_SLASH|WILD_SILENT) == FAIL)
|
|
4241 {
|
|
4242 *matchcount = 0;
|
|
4243 *matches = NULL;
|
|
4244 }
|
|
4245 vim_free(file_str);
|
|
4246
|
|
4247 return EXPAND_OK;
|
|
4248 }
|
|
4249
|
|
4250 #ifdef FEAT_MULTI_LANG
|
|
4251 /*
|
|
4252 * Cleanup matches for help tags: remove "@en" if "en" is the only language.
|
|
4253 */
|
|
4254 static void cleanup_help_tags __ARGS((int num_file, char_u **file));
|
|
4255
|
|
4256 static void
|
|
4257 cleanup_help_tags(num_file, file)
|
|
4258 int num_file;
|
|
4259 char_u **file;
|
|
4260 {
|
|
4261 int i, j;
|
|
4262 int len;
|
|
4263
|
|
4264 for (i = 0; i < num_file; ++i)
|
|
4265 {
|
|
4266 len = (int)STRLEN(file[i]) - 3;
|
|
4267 if (len > 0 && STRCMP(file[i] + len, "@en") == 0)
|
|
4268 {
|
|
4269 /* Sorting on priority means the same item in another language may
|
|
4270 * be anywhere. Search all items for a match up to the "@en". */
|
|
4271 for (j = 0; j < num_file; ++j)
|
|
4272 if (j != i
|
|
4273 && (int)STRLEN(file[j]) == len + 3
|
|
4274 && STRNCMP(file[i], file[j], len + 1) == 0)
|
|
4275 break;
|
|
4276 if (j == num_file)
|
|
4277 file[i][len] = NUL;
|
|
4278 }
|
|
4279 }
|
|
4280 }
|
|
4281 #endif
|
|
4282
|
|
4283 /*
|
|
4284 * Do the expansion based on xp->xp_context and "pat".
|
|
4285 */
|
|
4286 static int
|
|
4287 ExpandFromContext(xp, pat, num_file, file, options)
|
|
4288 expand_T *xp;
|
|
4289 char_u *pat;
|
|
4290 int *num_file;
|
|
4291 char_u ***file;
|
|
4292 int options;
|
|
4293 {
|
|
4294 #ifdef FEAT_CMDL_COMPL
|
|
4295 regmatch_T regmatch;
|
|
4296 #endif
|
|
4297 int ret;
|
|
4298 int flags;
|
|
4299
|
|
4300 flags = EW_DIR; /* include directories */
|
|
4301 if (options & WILD_LIST_NOTFOUND)
|
|
4302 flags |= EW_NOTFOUND;
|
|
4303 if (options & WILD_ADD_SLASH)
|
|
4304 flags |= EW_ADDSLASH;
|
|
4305 if (options & WILD_KEEP_ALL)
|
|
4306 flags |= EW_KEEPALL;
|
|
4307 if (options & WILD_SILENT)
|
|
4308 flags |= EW_SILENT;
|
|
4309
|
|
4310 if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES)
|
|
4311 {
|
|
4312 /*
|
|
4313 * Expand file or directory names.
|
|
4314 */
|
|
4315 int free_pat = FALSE;
|
|
4316 int i;
|
|
4317
|
|
4318 /* for ":set path=" and ":set tags=" halve backslashes for escaped
|
|
4319 * space */
|
|
4320 if (xp->xp_backslash != XP_BS_NONE)
|
|
4321 {
|
|
4322 free_pat = TRUE;
|
|
4323 pat = vim_strsave(pat);
|
|
4324 for (i = 0; pat[i]; ++i)
|
|
4325 if (pat[i] == '\\')
|
|
4326 {
|
|
4327 if (xp->xp_backslash == XP_BS_THREE
|
|
4328 && pat[i + 1] == '\\'
|
|
4329 && pat[i + 2] == '\\'
|
|
4330 && pat[i + 3] == ' ')
|
1341
|
4331 mch_memmove(pat + i, pat + i + 3,
|
|
4332 STRLEN(pat + i + 3) + 1);
|
7
|
4333 if (xp->xp_backslash == XP_BS_ONE
|
|
4334 && pat[i + 1] == ' ')
|
1341
|
4335 mch_memmove(pat + i, pat + i + 1, STRLEN(pat + i));
|
7
|
4336 }
|
|
4337 }
|
|
4338
|
|
4339 if (xp->xp_context == EXPAND_FILES)
|
|
4340 flags |= EW_FILE;
|
|
4341 else
|
|
4342 flags = (flags | EW_DIR) & ~EW_FILE;
|
|
4343 ret = expand_wildcards(1, &pat, num_file, file, flags);
|
|
4344 if (free_pat)
|
|
4345 vim_free(pat);
|
|
4346 return ret;
|
|
4347 }
|
|
4348
|
|
4349 *file = (char_u **)"";
|
|
4350 *num_file = 0;
|
|
4351 if (xp->xp_context == EXPAND_HELP)
|
|
4352 {
|
|
4353 if (find_help_tags(pat, num_file, file, FALSE) == OK)
|
|
4354 {
|
|
4355 #ifdef FEAT_MULTI_LANG
|
|
4356 cleanup_help_tags(*num_file, *file);
|
|
4357 #endif
|
|
4358 return OK;
|
|
4359 }
|
|
4360 return FAIL;
|
|
4361 }
|
|
4362
|
|
4363 #ifndef FEAT_CMDL_COMPL
|
|
4364 return FAIL;
|
|
4365 #else
|
716
|
4366 if (xp->xp_context == EXPAND_SHELLCMD)
|
|
4367 return expand_shellcmd(pat, num_file, file, flags);
|
7
|
4368 if (xp->xp_context == EXPAND_OLD_SETTING)
|
|
4369 return ExpandOldSetting(num_file, file);
|
|
4370 if (xp->xp_context == EXPAND_BUFFERS)
|
|
4371 return ExpandBufnames(pat, num_file, file, options);
|
|
4372 if (xp->xp_context == EXPAND_TAGS
|
|
4373 || xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
4374 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file);
|
|
4375 if (xp->xp_context == EXPAND_COLORS)
|
|
4376 return ExpandRTDir(pat, num_file, file, "colors");
|
|
4377 if (xp->xp_context == EXPAND_COMPILER)
|
|
4378 return ExpandRTDir(pat, num_file, file, "compiler");
|
407
|
4379 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
|
|
4380 if (xp->xp_context == EXPAND_USER_LIST)
|
856
|
4381 return ExpandUserList(xp, num_file, file);
|
407
|
4382 # endif
|
7
|
4383
|
|
4384 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
|
|
4385 if (regmatch.regprog == NULL)
|
|
4386 return FAIL;
|
|
4387
|
|
4388 /* set ignore-case according to p_ic, p_scs and pat */
|
|
4389 regmatch.rm_ic = ignorecase(pat);
|
|
4390
|
|
4391 if (xp->xp_context == EXPAND_SETTINGS
|
|
4392 || xp->xp_context == EXPAND_BOOL_SETTINGS)
|
|
4393 ret = ExpandSettings(xp, ®match, num_file, file);
|
|
4394 else if (xp->xp_context == EXPAND_MAPPINGS)
|
|
4395 ret = ExpandMappings(®match, num_file, file);
|
|
4396 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
|
|
4397 else if (xp->xp_context == EXPAND_USER_DEFINED)
|
|
4398 ret = ExpandUserDefined(xp, ®match, num_file, file);
|
|
4399 # endif
|
|
4400 else
|
|
4401 {
|
|
4402 static struct expgen
|
|
4403 {
|
|
4404 int context;
|
|
4405 char_u *((*func)__ARGS((expand_T *, int)));
|
|
4406 int ic;
|
|
4407 } tab[] =
|
|
4408 {
|
|
4409 {EXPAND_COMMANDS, get_command_name, FALSE},
|
|
4410 #ifdef FEAT_USR_CMDS
|
|
4411 {EXPAND_USER_COMMANDS, get_user_commands, FALSE},
|
|
4412 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE},
|
|
4413 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE},
|
|
4414 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE},
|
|
4415 #endif
|
|
4416 #ifdef FEAT_EVAL
|
|
4417 {EXPAND_USER_VARS, get_user_var_name, FALSE},
|
|
4418 {EXPAND_FUNCTIONS, get_function_name, FALSE},
|
|
4419 {EXPAND_USER_FUNC, get_user_func_name, FALSE},
|
|
4420 {EXPAND_EXPRESSION, get_expr_name, FALSE},
|
|
4421 #endif
|
|
4422 #ifdef FEAT_MENU
|
|
4423 {EXPAND_MENUS, get_menu_name, FALSE},
|
|
4424 {EXPAND_MENUNAMES, get_menu_names, FALSE},
|
|
4425 #endif
|
|
4426 #ifdef FEAT_SYN_HL
|
|
4427 {EXPAND_SYNTAX, get_syntax_name, TRUE},
|
|
4428 #endif
|
|
4429 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE},
|
|
4430 #ifdef FEAT_AUTOCMD
|
|
4431 {EXPAND_EVENTS, get_event_name, TRUE},
|
|
4432 {EXPAND_AUGROUP, get_augroup_name, TRUE},
|
|
4433 #endif
|
|
4434 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
4435 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
|
|
4436 {EXPAND_LANGUAGE, get_lang_arg, TRUE},
|
|
4437 #endif
|
|
4438 {EXPAND_ENV_VARS, get_env_name, TRUE},
|
|
4439 };
|
|
4440 int i;
|
|
4441
|
|
4442 /*
|
|
4443 * Find a context in the table and call the ExpandGeneric() with the
|
|
4444 * right function to do the expansion.
|
|
4445 */
|
|
4446 ret = FAIL;
|
|
4447 for (i = 0; i < sizeof(tab) / sizeof(struct expgen); ++i)
|
|
4448 if (xp->xp_context == tab[i].context)
|
|
4449 {
|
|
4450 if (tab[i].ic)
|
|
4451 regmatch.rm_ic = TRUE;
|
|
4452 ret = ExpandGeneric(xp, ®match, num_file, file, tab[i].func);
|
|
4453 break;
|
|
4454 }
|
|
4455 }
|
|
4456
|
|
4457 vim_free(regmatch.regprog);
|
|
4458
|
|
4459 return ret;
|
|
4460 #endif /* FEAT_CMDL_COMPL */
|
|
4461 }
|
|
4462
|
|
4463 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
4464 /*
|
|
4465 * Expand a list of names.
|
|
4466 *
|
|
4467 * Generic function for command line completion. It calls a function to
|
|
4468 * obtain strings, one by one. The strings are matched against a regexp
|
|
4469 * program. Matching strings are copied into an array, which is returned.
|
|
4470 *
|
|
4471 * Returns OK when no problems encountered, FAIL for error (out of memory).
|
|
4472 */
|
|
4473 int
|
|
4474 ExpandGeneric(xp, regmatch, num_file, file, func)
|
|
4475 expand_T *xp;
|
|
4476 regmatch_T *regmatch;
|
|
4477 int *num_file;
|
|
4478 char_u ***file;
|
|
4479 char_u *((*func)__ARGS((expand_T *, int)));
|
|
4480 /* returns a string from the list */
|
|
4481 {
|
|
4482 int i;
|
|
4483 int count = 0;
|
480
|
4484 int round;
|
7
|
4485 char_u *str;
|
|
4486
|
|
4487 /* do this loop twice:
|
480
|
4488 * round == 0: count the number of matching names
|
|
4489 * round == 1: copy the matching names into allocated memory
|
7
|
4490 */
|
480
|
4491 for (round = 0; round <= 1; ++round)
|
7
|
4492 {
|
|
4493 for (i = 0; ; ++i)
|
|
4494 {
|
|
4495 str = (*func)(xp, i);
|
|
4496 if (str == NULL) /* end of list */
|
|
4497 break;
|
|
4498 if (*str == NUL) /* skip empty strings */
|
|
4499 continue;
|
|
4500
|
|
4501 if (vim_regexec(regmatch, str, (colnr_T)0))
|
|
4502 {
|
480
|
4503 if (round)
|
7
|
4504 {
|
|
4505 str = vim_strsave_escaped(str, (char_u *)" \t\\.");
|
|
4506 (*file)[count] = str;
|
|
4507 #ifdef FEAT_MENU
|
|
4508 if (func == get_menu_names && str != NULL)
|
|
4509 {
|
|
4510 /* test for separator added by get_menu_names() */
|
|
4511 str += STRLEN(str) - 1;
|
|
4512 if (*str == '\001')
|
|
4513 *str = '.';
|
|
4514 }
|
|
4515 #endif
|
|
4516 }
|
|
4517 ++count;
|
|
4518 }
|
|
4519 }
|
480
|
4520 if (round == 0)
|
7
|
4521 {
|
|
4522 if (count == 0)
|
|
4523 return OK;
|
|
4524 *num_file = count;
|
|
4525 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *)));
|
|
4526 if (*file == NULL)
|
|
4527 {
|
|
4528 *file = (char_u **)"";
|
|
4529 return FAIL;
|
|
4530 }
|
|
4531 count = 0;
|
|
4532 }
|
|
4533 }
|
480
|
4534
|
828
|
4535 /* Sort the results. Keep menu's in the specified order. */
|
|
4536 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS)
|
|
4537 sort_strings(*file, *num_file);
|
480
|
4538
|
1322
|
4539 #ifdef FEAT_CMDL_COMPL
|
|
4540 /* Reset the variables used for special highlight names expansion, so that
|
|
4541 * they don't show up when getting normal highlight names by ID. */
|
|
4542 reset_expand_highlight();
|
|
4543 #endif
|
|
4544
|
7
|
4545 return OK;
|
|
4546 }
|
|
4547
|
716
|
4548 /*
|
|
4549 * Complete a shell command.
|
|
4550 * Returns FAIL or OK;
|
|
4551 */
|
|
4552 static int
|
|
4553 expand_shellcmd(filepat, num_file, file, flagsarg)
|
|
4554 char_u *filepat; /* pattern to match with command names */
|
|
4555 int *num_file; /* return: number of matches */
|
|
4556 char_u ***file; /* return: array with matches */
|
|
4557 int flagsarg; /* EW_ flags */
|
|
4558 {
|
|
4559 char_u *pat;
|
|
4560 int i;
|
|
4561 char_u *path;
|
|
4562 int mustfree = FALSE;
|
|
4563 garray_T ga;
|
|
4564 char_u *buf = alloc(MAXPATHL);
|
|
4565 size_t l;
|
|
4566 char_u *s, *e;
|
|
4567 int flags = flagsarg;
|
|
4568 int ret;
|
|
4569
|
|
4570 if (buf == NULL)
|
|
4571 return FAIL;
|
|
4572
|
|
4573 /* for ":set path=" and ":set tags=" halve backslashes for escaped
|
|
4574 * space */
|
|
4575 pat = vim_strsave(filepat);
|
|
4576 for (i = 0; pat[i]; ++i)
|
|
4577 if (pat[i] == '\\' && pat[i + 1] == ' ')
|
1341
|
4578 mch_memmove(pat + i, pat + i + 1, STRLEN(pat + i));
|
716
|
4579
|
|
4580 flags |= EW_FILE | EW_EXEC;
|
|
4581
|
|
4582 /* For an absolute name we don't use $PATH. */
|
955
|
4583 if (mch_isFullName(pat))
|
|
4584 path = (char_u *)" ";
|
|
4585 else if ((pat[0] == '.' && (vim_ispathsep(pat[1])
|
716
|
4586 || (pat[1] == '.' && vim_ispathsep(pat[2])))))
|
|
4587 path = (char_u *)".";
|
|
4588 else
|
|
4589 path = vim_getenv((char_u *)"PATH", &mustfree);
|
|
4590
|
|
4591 /*
|
|
4592 * Go over all directories in $PATH. Expand matches in that directory and
|
|
4593 * collect them in "ga".
|
|
4594 */
|
|
4595 ga_init2(&ga, (int)sizeof(char *), 10);
|
|
4596 for (s = path; *s != NUL; s = e)
|
|
4597 {
|
955
|
4598 if (*s == ' ')
|
|
4599 ++s; /* Skip space used for absolute path name. */
|
|
4600
|
716
|
4601 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
|
|
4602 e = vim_strchr(s, ';');
|
|
4603 #else
|
|
4604 e = vim_strchr(s, ':');
|
|
4605 #endif
|
|
4606 if (e == NULL)
|
|
4607 e = s + STRLEN(s);
|
|
4608
|
|
4609 l = e - s;
|
|
4610 if (l > MAXPATHL - 5)
|
|
4611 break;
|
|
4612 vim_strncpy(buf, s, l);
|
|
4613 add_pathsep(buf);
|
|
4614 l = STRLEN(buf);
|
|
4615 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
|
|
4616
|
|
4617 /* Expand matches in one directory of $PATH. */
|
|
4618 ret = expand_wildcards(1, &buf, num_file, file, flags);
|
|
4619 if (ret == OK)
|
|
4620 {
|
|
4621 if (ga_grow(&ga, *num_file) == FAIL)
|
|
4622 FreeWild(*num_file, *file);
|
|
4623 else
|
|
4624 {
|
|
4625 for (i = 0; i < *num_file; ++i)
|
|
4626 {
|
|
4627 s = (*file)[i];
|
|
4628 if (STRLEN(s) > l)
|
|
4629 {
|
|
4630 /* Remove the path again. */
|
|
4631 mch_memmove(s, s + l, STRLEN(s + l) + 1);
|
|
4632 ((char_u **)ga.ga_data)[ga.ga_len++] = s;
|
|
4633 }
|
|
4634 else
|
|
4635 vim_free(s);
|
|
4636 }
|
|
4637 vim_free(*file);
|
|
4638 }
|
|
4639 }
|
|
4640 if (*e != NUL)
|
|
4641 ++e;
|
|
4642 }
|
|
4643 *file = ga.ga_data;
|
|
4644 *num_file = ga.ga_len;
|
|
4645
|
|
4646 vim_free(buf);
|
|
4647 vim_free(pat);
|
|
4648 if (mustfree)
|
|
4649 vim_free(path);
|
|
4650 return OK;
|
|
4651 }
|
|
4652
|
|
4653
|
7
|
4654 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
|
410
|
4655 static void * call_user_expand_func __ARGS((void *(*user_expand_func) __ARGS((char_u *, int, char_u **, int)), expand_T *xp, int *num_file, char_u ***file));
|
|
4656
|
7
|
4657 /*
|
1518
|
4658 * Call "user_expand_func()" to invoke a user defined VimL function and return
|
407
|
4659 * the result (either a string or a List).
|
7
|
4660 */
|
407
|
4661 static void *
|
|
4662 call_user_expand_func(user_expand_func, xp, num_file, file)
|
|
4663 void *(*user_expand_func) __ARGS((char_u *, int, char_u **, int));
|
7
|
4664 expand_T *xp;
|
|
4665 int *num_file;
|
|
4666 char_u ***file;
|
|
4667 {
|
407
|
4668 char_u keep;
|
|
4669 char_u num[50];
|
7
|
4670 char_u *args[3];
|
|
4671 int save_current_SID = current_SID;
|
407
|
4672 void *ret;
|
13
|
4673 struct cmdline_info save_ccline;
|
7
|
4674
|
|
4675 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0')
|
407
|
4676 return NULL;
|
7
|
4677 *num_file = 0;
|
|
4678 *file = NULL;
|
|
4679
|
1518
|
4680 if (ccline.cmdbuff == NULL)
|
|
4681 {
|
|
4682 /* Completion from Insert mode, pass fake arguments. */
|
|
4683 keep = 0;
|
|
4684 sprintf((char *)num, "%d", STRLEN(xp->xp_pattern));
|
|
4685 args[1] = xp->xp_pattern;
|
|
4686 }
|
|
4687 else
|
|
4688 {
|
|
4689 /* Completion on the command line, pass real arguments. */
|
|
4690 keep = ccline.cmdbuff[ccline.cmdlen];
|
|
4691 ccline.cmdbuff[ccline.cmdlen] = 0;
|
|
4692 sprintf((char *)num, "%d", ccline.cmdpos);
|
|
4693 args[1] = ccline.cmdbuff;
|
|
4694 }
|
7
|
4695 args[0] = xp->xp_pattern;
|
|
4696 args[2] = num;
|
|
4697
|
13
|
4698 /* Save the cmdline, we don't know what the function may do. */
|
|
4699 save_ccline = ccline;
|
|
4700 ccline.cmdbuff = NULL;
|
|
4701 ccline.cmdprompt = NULL;
|
7
|
4702 current_SID = xp->xp_scriptID;
|
13
|
4703
|
407
|
4704 ret = user_expand_func(xp->xp_arg, 3, args, FALSE);
|
13
|
4705
|
|
4706 ccline = save_ccline;
|
7
|
4707 current_SID = save_current_SID;
|
1518
|
4708 if (ccline.cmdbuff != NULL)
|
|
4709 ccline.cmdbuff[ccline.cmdlen] = keep;
|
407
|
4710
|
|
4711 return ret;
|
|
4712 }
|
|
4713
|
|
4714 /*
|
|
4715 * Expand names with a function defined by the user.
|
|
4716 */
|
|
4717 static int
|
|
4718 ExpandUserDefined(xp, regmatch, num_file, file)
|
|
4719 expand_T *xp;
|
|
4720 regmatch_T *regmatch;
|
|
4721 int *num_file;
|
|
4722 char_u ***file;
|
|
4723 {
|
|
4724 char_u *retstr;
|
|
4725 char_u *s;
|
|
4726 char_u *e;
|
|
4727 char_u keep;
|
|
4728 garray_T ga;
|
|
4729
|
|
4730 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file);
|
|
4731 if (retstr == NULL)
|
7
|
4732 return FAIL;
|
|
4733
|
|
4734 ga_init2(&ga, (int)sizeof(char *), 3);
|
407
|
4735 for (s = retstr; *s != NUL; s = e)
|
7
|
4736 {
|
|
4737 e = vim_strchr(s, '\n');
|
|
4738 if (e == NULL)
|
|
4739 e = s + STRLEN(s);
|
|
4740 keep = *e;
|
|
4741 *e = 0;
|
|
4742
|
|
4743 if (xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0)
|
|
4744 {
|
|
4745 *e = keep;
|
|
4746 if (*e != NUL)
|
|
4747 ++e;
|
|
4748 continue;
|
|
4749 }
|
|
4750
|
|
4751 if (ga_grow(&ga, 1) == FAIL)
|
|
4752 break;
|
|
4753
|
|
4754 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s));
|
|
4755 ++ga.ga_len;
|
|
4756
|
|
4757 *e = keep;
|
|
4758 if (*e != NUL)
|
|
4759 ++e;
|
|
4760 }
|
407
|
4761 vim_free(retstr);
|
|
4762 *file = ga.ga_data;
|
|
4763 *num_file = ga.ga_len;
|
|
4764 return OK;
|
|
4765 }
|
|
4766
|
|
4767 /*
|
|
4768 * Expand names with a list returned by a function defined by the user.
|
|
4769 */
|
|
4770 static int
|
|
4771 ExpandUserList(xp, num_file, file)
|
|
4772 expand_T *xp;
|
|
4773 int *num_file;
|
|
4774 char_u ***file;
|
|
4775 {
|
|
4776 list_T *retlist;
|
|
4777 listitem_T *li;
|
|
4778 garray_T ga;
|
|
4779
|
|
4780 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file);
|
|
4781 if (retlist == NULL)
|
|
4782 return FAIL;
|
|
4783
|
|
4784 ga_init2(&ga, (int)sizeof(char *), 3);
|
|
4785 /* Loop over the items in the list. */
|
|
4786 for (li = retlist->lv_first; li != NULL; li = li->li_next)
|
|
4787 {
|
|
4788 if (li->li_tv.v_type != VAR_STRING)
|
|
4789 continue; /* Skip non-string items */
|
|
4790
|
|
4791 if (ga_grow(&ga, 1) == FAIL)
|
|
4792 break;
|
|
4793
|
|
4794 ((char_u **)ga.ga_data)[ga.ga_len] =
|
|
4795 vim_strsave(li->li_tv.vval.v_string);
|
|
4796 ++ga.ga_len;
|
|
4797 }
|
|
4798 list_unref(retlist);
|
|
4799
|
7
|
4800 *file = ga.ga_data;
|
|
4801 *num_file = ga.ga_len;
|
|
4802 return OK;
|
|
4803 }
|
|
4804 #endif
|
|
4805
|
|
4806 /*
|
|
4807 * Expand color scheme names: 'runtimepath'/colors/{pat}.vim
|
|
4808 * or compiler names.
|
|
4809 */
|
|
4810 static int
|
|
4811 ExpandRTDir(pat, num_file, file, dirname)
|
|
4812 char_u *pat;
|
|
4813 int *num_file;
|
|
4814 char_u ***file;
|
|
4815 char *dirname; /* "colors" or "compiler" */
|
|
4816 {
|
|
4817 char_u *all;
|
|
4818 char_u *s;
|
|
4819 char_u *e;
|
|
4820 garray_T ga;
|
|
4821
|
|
4822 *num_file = 0;
|
|
4823 *file = NULL;
|
|
4824 s = alloc((unsigned)(STRLEN(pat) + STRLEN(dirname) + 7));
|
|
4825 if (s == NULL)
|
|
4826 return FAIL;
|
|
4827 sprintf((char *)s, "%s/%s*.vim", dirname, pat);
|
|
4828 all = globpath(p_rtp, s);
|
|
4829 vim_free(s);
|
|
4830 if (all == NULL)
|
|
4831 return FAIL;
|
|
4832
|
|
4833 ga_init2(&ga, (int)sizeof(char *), 3);
|
|
4834 for (s = all; *s != NUL; s = e)
|
|
4835 {
|
|
4836 e = vim_strchr(s, '\n');
|
|
4837 if (e == NULL)
|
|
4838 e = s + STRLEN(s);
|
|
4839 if (ga_grow(&ga, 1) == FAIL)
|
|
4840 break;
|
|
4841 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
|
|
4842 {
|
39
|
4843 for (s = e - 4; s > all; mb_ptr_back(all, s))
|
7
|
4844 if (*s == '\n' || vim_ispathsep(*s))
|
|
4845 break;
|
|
4846 ++s;
|
|
4847 ((char_u **)ga.ga_data)[ga.ga_len] =
|
|
4848 vim_strnsave(s, (int)(e - s - 4));
|
|
4849 ++ga.ga_len;
|
|
4850 }
|
|
4851 if (*e != NUL)
|
|
4852 ++e;
|
|
4853 }
|
|
4854 vim_free(all);
|
|
4855 *file = ga.ga_data;
|
|
4856 *num_file = ga.ga_len;
|
|
4857 return OK;
|
|
4858 }
|
|
4859
|
|
4860 #endif
|
|
4861
|
|
4862 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO)
|
|
4863 /*
|
|
4864 * Expand "file" for all comma-separated directories in "path".
|
|
4865 * Returns an allocated string with all matches concatenated, separated by
|
|
4866 * newlines. Returns NULL for an error or no matches.
|
|
4867 */
|
|
4868 char_u *
|
|
4869 globpath(path, file)
|
|
4870 char_u *path;
|
|
4871 char_u *file;
|
|
4872 {
|
|
4873 expand_T xpc;
|
|
4874 char_u *buf;
|
|
4875 garray_T ga;
|
|
4876 int i;
|
|
4877 int len;
|
|
4878 int num_p;
|
|
4879 char_u **p;
|
|
4880 char_u *cur = NULL;
|
|
4881
|
|
4882 buf = alloc(MAXPATHL);
|
|
4883 if (buf == NULL)
|
|
4884 return NULL;
|
|
4885
|
632
|
4886 ExpandInit(&xpc);
|
7
|
4887 xpc.xp_context = EXPAND_FILES;
|
632
|
4888
|
7
|
4889 ga_init2(&ga, 1, 100);
|
|
4890
|
|
4891 /* Loop over all entries in {path}. */
|
|
4892 while (*path != NUL)
|
|
4893 {
|
|
4894 /* Copy one item of the path to buf[] and concatenate the file name. */
|
|
4895 copy_option_part(&path, buf, MAXPATHL, ",");
|
|
4896 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
|
|
4897 {
|
|
4898 add_pathsep(buf);
|
|
4899 STRCAT(buf, file);
|
|
4900 if (ExpandFromContext(&xpc, buf, &num_p, &p, WILD_SILENT) != FAIL
|
|
4901 && num_p > 0)
|
|
4902 {
|
|
4903 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT);
|
|
4904 for (len = 0, i = 0; i < num_p; ++i)
|
835
|
4905 len += (int)STRLEN(p[i]) + 1;
|
7
|
4906
|
|
4907 /* Concatenate new results to previous ones. */
|
|
4908 if (ga_grow(&ga, len) == OK)
|
|
4909 {
|
|
4910 cur = (char_u *)ga.ga_data + ga.ga_len;
|
|
4911 for (i = 0; i < num_p; ++i)
|
|
4912 {
|
|
4913 STRCPY(cur, p[i]);
|
|
4914 cur += STRLEN(p[i]);
|
|
4915 *cur++ = '\n';
|
|
4916 }
|
|
4917 ga.ga_len += len;
|
|
4918 }
|
|
4919 FreeWild(num_p, p);
|
|
4920 }
|
|
4921 }
|
|
4922 }
|
|
4923 if (cur != NULL)
|
|
4924 *--cur = 0; /* Replace trailing newline with NUL */
|
|
4925
|
|
4926 vim_free(buf);
|
|
4927 return (char_u *)ga.ga_data;
|
|
4928 }
|
|
4929
|
|
4930 #endif
|
|
4931
|
|
4932 #if defined(FEAT_CMDHIST) || defined(PROTO)
|
|
4933
|
|
4934 /*********************************
|
|
4935 * Command line history stuff *
|
|
4936 *********************************/
|
|
4937
|
|
4938 /*
|
|
4939 * Translate a history character to the associated type number.
|
|
4940 */
|
|
4941 static int
|
|
4942 hist_char2type(c)
|
|
4943 int c;
|
|
4944 {
|
|
4945 if (c == ':')
|
|
4946 return HIST_CMD;
|
|
4947 if (c == '=')
|
|
4948 return HIST_EXPR;
|
|
4949 if (c == '@')
|
|
4950 return HIST_INPUT;
|
|
4951 if (c == '>')
|
|
4952 return HIST_DEBUG;
|
|
4953 return HIST_SEARCH; /* must be '?' or '/' */
|
|
4954 }
|
|
4955
|
|
4956 /*
|
|
4957 * Table of history names.
|
|
4958 * These names are used in :history and various hist...() functions.
|
|
4959 * It is sufficient to give the significant prefix of a history name.
|
|
4960 */
|
|
4961
|
|
4962 static char *(history_names[]) =
|
|
4963 {
|
|
4964 "cmd",
|
|
4965 "search",
|
|
4966 "expr",
|
|
4967 "input",
|
|
4968 "debug",
|
|
4969 NULL
|
|
4970 };
|
|
4971
|
|
4972 /*
|
|
4973 * init_history() - Initialize the command line history.
|
|
4974 * Also used to re-allocate the history when the size changes.
|
|
4975 */
|
356
|
4976 void
|
7
|
4977 init_history()
|
|
4978 {
|
|
4979 int newlen; /* new length of history table */
|
|
4980 histentry_T *temp;
|
|
4981 int i;
|
|
4982 int j;
|
|
4983 int type;
|
|
4984
|
|
4985 /*
|
|
4986 * If size of history table changed, reallocate it
|
|
4987 */
|
|
4988 newlen = (int)p_hi;
|
|
4989 if (newlen != hislen) /* history length changed */
|
|
4990 {
|
|
4991 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */
|
|
4992 {
|
|
4993 if (newlen)
|
|
4994 {
|
|
4995 temp = (histentry_T *)lalloc(
|
|
4996 (long_u)(newlen * sizeof(histentry_T)), TRUE);
|
|
4997 if (temp == NULL) /* out of memory! */
|
|
4998 {
|
|
4999 if (type == 0) /* first one: just keep the old length */
|
|
5000 {
|
|
5001 newlen = hislen;
|
|
5002 break;
|
|
5003 }
|
|
5004 /* Already changed one table, now we can only have zero
|
|
5005 * length for all tables. */
|
|
5006 newlen = 0;
|
|
5007 type = -1;
|
|
5008 continue;
|
|
5009 }
|
|
5010 }
|
|
5011 else
|
|
5012 temp = NULL;
|
|
5013 if (newlen == 0 || temp != NULL)
|
|
5014 {
|
|
5015 if (hisidx[type] < 0) /* there are no entries yet */
|
|
5016 {
|
|
5017 for (i = 0; i < newlen; ++i)
|
|
5018 {
|
|
5019 temp[i].hisnum = 0;
|
|
5020 temp[i].hisstr = NULL;
|
|
5021 }
|
|
5022 }
|
|
5023 else if (newlen > hislen) /* array becomes bigger */
|
|
5024 {
|
|
5025 for (i = 0; i <= hisidx[type]; ++i)
|
|
5026 temp[i] = history[type][i];
|
|
5027 j = i;
|
|
5028 for ( ; i <= newlen - (hislen - hisidx[type]); ++i)
|
|
5029 {
|
|
5030 temp[i].hisnum = 0;
|
|
5031 temp[i].hisstr = NULL;
|
|
5032 }
|
|
5033 for ( ; j < hislen; ++i, ++j)
|
|
5034 temp[i] = history[type][j];
|
|
5035 }
|
|
5036 else /* array becomes smaller or 0 */
|
|
5037 {
|
|
5038 j = hisidx[type];
|
|
5039 for (i = newlen - 1; ; --i)
|
|
5040 {
|
|
5041 if (i >= 0) /* copy newest entries */
|
|
5042 temp[i] = history[type][j];
|
|
5043 else /* remove older entries */
|
|
5044 vim_free(history[type][j].hisstr);
|
|
5045 if (--j < 0)
|
|
5046 j = hislen - 1;
|
|
5047 if (j == hisidx[type])
|
|
5048 break;
|
|
5049 }
|
|
5050 hisidx[type] = newlen - 1;
|
|
5051 }
|
|
5052 vim_free(history[type]);
|
|
5053 history[type] = temp;
|
|
5054 }
|
|
5055 }
|
|
5056 hislen = newlen;
|
|
5057 }
|
|
5058 }
|
|
5059
|
|
5060 /*
|
|
5061 * Check if command line 'str' is already in history.
|
|
5062 * If 'move_to_front' is TRUE, matching entry is moved to end of history.
|
|
5063 */
|
|
5064 static int
|
|
5065 in_history(type, str, move_to_front)
|
|
5066 int type;
|
|
5067 char_u *str;
|
|
5068 int move_to_front; /* Move the entry to the front if it exists */
|
|
5069 {
|
|
5070 int i;
|
|
5071 int last_i = -1;
|
|
5072
|
|
5073 if (hisidx[type] < 0)
|
|
5074 return FALSE;
|
|
5075 i = hisidx[type];
|
|
5076 do
|
|
5077 {
|
|
5078 if (history[type][i].hisstr == NULL)
|
|
5079 return FALSE;
|
|
5080 if (STRCMP(str, history[type][i].hisstr) == 0)
|
|
5081 {
|
|
5082 if (!move_to_front)
|
|
5083 return TRUE;
|
|
5084 last_i = i;
|
|
5085 break;
|
|
5086 }
|
|
5087 if (--i < 0)
|
|
5088 i = hislen - 1;
|
|
5089 } while (i != hisidx[type]);
|
|
5090
|
|
5091 if (last_i >= 0)
|
|
5092 {
|
|
5093 str = history[type][i].hisstr;
|
|
5094 while (i != hisidx[type])
|
|
5095 {
|
|
5096 if (++i >= hislen)
|
|
5097 i = 0;
|
|
5098 history[type][last_i] = history[type][i];
|
|
5099 last_i = i;
|
|
5100 }
|
|
5101 history[type][i].hisstr = str;
|
|
5102 history[type][i].hisnum = ++hisnum[type];
|
|
5103 return TRUE;
|
|
5104 }
|
|
5105 return FALSE;
|
|
5106 }
|
|
5107
|
|
5108 /*
|
|
5109 * Convert history name (from table above) to its HIST_ equivalent.
|
|
5110 * When "name" is empty, return "cmd" history.
|
|
5111 * Returns -1 for unknown history name.
|
|
5112 */
|
|
5113 int
|
|
5114 get_histtype(name)
|
|
5115 char_u *name;
|
|
5116 {
|
|
5117 int i;
|
|
5118 int len = (int)STRLEN(name);
|
|
5119
|
|
5120 /* No argument: use current history. */
|
|
5121 if (len == 0)
|
|
5122 return hist_char2type(ccline.cmdfirstc);
|
|
5123
|
|
5124 for (i = 0; history_names[i] != NULL; ++i)
|
|
5125 if (STRNICMP(name, history_names[i], len) == 0)
|
|
5126 return i;
|
|
5127
|
|
5128 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL)
|
|
5129 return hist_char2type(name[0]);
|
|
5130
|
|
5131 return -1;
|
|
5132 }
|
|
5133
|
|
5134 static int last_maptick = -1; /* last seen maptick */
|
|
5135
|
|
5136 /*
|
|
5137 * Add the given string to the given history. If the string is already in the
|
|
5138 * history then it is moved to the front. "histype" may be one of he HIST_
|
|
5139 * values.
|
|
5140 */
|
|
5141 void
|
|
5142 add_to_history(histype, new_entry, in_map, sep)
|
|
5143 int histype;
|
|
5144 char_u *new_entry;
|
|
5145 int in_map; /* consider maptick when inside a mapping */
|
|
5146 int sep; /* separator character used (search hist) */
|
|
5147 {
|
|
5148 histentry_T *hisptr;
|
|
5149 int len;
|
|
5150
|
|
5151 if (hislen == 0) /* no history */
|
|
5152 return;
|
|
5153
|
|
5154 /*
|
|
5155 * Searches inside the same mapping overwrite each other, so that only
|
|
5156 * the last line is kept. Be careful not to remove a line that was moved
|
|
5157 * down, only lines that were added.
|
|
5158 */
|
|
5159 if (histype == HIST_SEARCH && in_map)
|
|
5160 {
|
|
5161 if (maptick == last_maptick)
|
|
5162 {
|
|
5163 /* Current line is from the same mapping, remove it */
|
|
5164 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]];
|
|
5165 vim_free(hisptr->hisstr);
|
|
5166 hisptr->hisstr = NULL;
|
|
5167 hisptr->hisnum = 0;
|
|
5168 --hisnum[histype];
|
|
5169 if (--hisidx[HIST_SEARCH] < 0)
|
|
5170 hisidx[HIST_SEARCH] = hislen - 1;
|
|
5171 }
|
|
5172 last_maptick = -1;
|
|
5173 }
|
|
5174 if (!in_history(histype, new_entry, TRUE))
|
|
5175 {
|
|
5176 if (++hisidx[histype] == hislen)
|
|
5177 hisidx[histype] = 0;
|
|
5178 hisptr = &history[histype][hisidx[histype]];
|
|
5179 vim_free(hisptr->hisstr);
|
|
5180
|
|
5181 /* Store the separator after the NUL of the string. */
|
835
|
5182 len = (int)STRLEN(new_entry);
|
7
|
5183 hisptr->hisstr = vim_strnsave(new_entry, len + 2);
|
|
5184 if (hisptr->hisstr != NULL)
|
|
5185 hisptr->hisstr[len + 1] = sep;
|
|
5186
|
|
5187 hisptr->hisnum = ++hisnum[histype];
|
|
5188 if (histype == HIST_SEARCH && in_map)
|
|
5189 last_maptick = maptick;
|
|
5190 }
|
|
5191 }
|
|
5192
|
|
5193 #if defined(FEAT_EVAL) || defined(PROTO)
|
|
5194
|
|
5195 /*
|
|
5196 * Get identifier of newest history entry.
|
|
5197 * "histype" may be one of the HIST_ values.
|
|
5198 */
|
|
5199 int
|
|
5200 get_history_idx(histype)
|
|
5201 int histype;
|
|
5202 {
|
|
5203 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
|
|
5204 || hisidx[histype] < 0)
|
|
5205 return -1;
|
|
5206
|
|
5207 return history[histype][hisidx[histype]].hisnum;
|
|
5208 }
|
|
5209
|
95
|
5210 static struct cmdline_info *get_ccline_ptr __ARGS((void));
|
|
5211
|
|
5212 /*
|
|
5213 * Get pointer to the command line info to use. cmdline_paste() may clear
|
|
5214 * ccline and put the previous value in prev_ccline.
|
|
5215 */
|
|
5216 static struct cmdline_info *
|
|
5217 get_ccline_ptr()
|
|
5218 {
|
|
5219 if ((State & CMDLINE) == 0)
|
|
5220 return NULL;
|
|
5221 if (ccline.cmdbuff != NULL)
|
|
5222 return &ccline;
|
|
5223 if (prev_ccline_used && prev_ccline.cmdbuff != NULL)
|
|
5224 return &prev_ccline;
|
|
5225 return NULL;
|
|
5226 }
|
|
5227
|
7
|
5228 /*
|
|
5229 * Get the current command line in allocated memory.
|
|
5230 * Only works when the command line is being edited.
|
|
5231 * Returns NULL when something is wrong.
|
|
5232 */
|
|
5233 char_u *
|
|
5234 get_cmdline_str()
|
|
5235 {
|
95
|
5236 struct cmdline_info *p = get_ccline_ptr();
|
|
5237
|
|
5238 if (p == NULL)
|
7
|
5239 return NULL;
|
95
|
5240 return vim_strnsave(p->cmdbuff, p->cmdlen);
|
7
|
5241 }
|
|
5242
|
|
5243 /*
|
|
5244 * Get the current command line position, counted in bytes.
|
|
5245 * Zero is the first position.
|
|
5246 * Only works when the command line is being edited.
|
|
5247 * Returns -1 when something is wrong.
|
|
5248 */
|
|
5249 int
|
|
5250 get_cmdline_pos()
|
|
5251 {
|
95
|
5252 struct cmdline_info *p = get_ccline_ptr();
|
|
5253
|
|
5254 if (p == NULL)
|
7
|
5255 return -1;
|
95
|
5256 return p->cmdpos;
|
7
|
5257 }
|
|
5258
|
|
5259 /*
|
|
5260 * Set the command line byte position to "pos". Zero is the first position.
|
|
5261 * Only works when the command line is being edited.
|
|
5262 * Returns 1 when failed, 0 when OK.
|
|
5263 */
|
|
5264 int
|
|
5265 set_cmdline_pos(pos)
|
|
5266 int pos;
|
|
5267 {
|
95
|
5268 struct cmdline_info *p = get_ccline_ptr();
|
|
5269
|
|
5270 if (p == NULL)
|
7
|
5271 return 1;
|
|
5272
|
|
5273 /* The position is not set directly but after CTRL-\ e or CTRL-R = has
|
|
5274 * changed the command line. */
|
|
5275 if (pos < 0)
|
|
5276 new_cmdpos = 0;
|
|
5277 else
|
|
5278 new_cmdpos = pos;
|
|
5279 return 0;
|
|
5280 }
|
|
5281
|
|
5282 /*
|
531
|
5283 * Get the current command-line type.
|
532
|
5284 * Returns ':' or '/' or '?' or '@' or '>' or '-'
|
531
|
5285 * Only works when the command line is being edited.
|
|
5286 * Returns NUL when something is wrong.
|
|
5287 */
|
|
5288 int
|
|
5289 get_cmdline_type()
|
|
5290 {
|
|
5291 struct cmdline_info *p = get_ccline_ptr();
|
|
5292
|
|
5293 if (p == NULL)
|
|
5294 return NUL;
|
532
|
5295 if (p->cmdfirstc == NUL)
|
|
5296 return (p->input_fn) ? '@' : '-';
|
531
|
5297 return p->cmdfirstc;
|
|
5298 }
|
|
5299
|
|
5300 /*
|
7
|
5301 * Calculate history index from a number:
|
|
5302 * num > 0: seen as identifying number of a history entry
|
|
5303 * num < 0: relative position in history wrt newest entry
|
|
5304 * "histype" may be one of the HIST_ values.
|
|
5305 */
|
|
5306 static int
|
|
5307 calc_hist_idx(histype, num)
|
|
5308 int histype;
|
|
5309 int num;
|
|
5310 {
|
|
5311 int i;
|
|
5312 histentry_T *hist;
|
|
5313 int wrapped = FALSE;
|
|
5314
|
|
5315 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
|
|
5316 || (i = hisidx[histype]) < 0 || num == 0)
|
|
5317 return -1;
|
|
5318
|
|
5319 hist = history[histype];
|
|
5320 if (num > 0)
|
|
5321 {
|
|
5322 while (hist[i].hisnum > num)
|
|
5323 if (--i < 0)
|
|
5324 {
|
|
5325 if (wrapped)
|
|
5326 break;
|
|
5327 i += hislen;
|
|
5328 wrapped = TRUE;
|
|
5329 }
|
|
5330 if (hist[i].hisnum == num && hist[i].hisstr != NULL)
|
|
5331 return i;
|
|
5332 }
|
|
5333 else if (-num <= hislen)
|
|
5334 {
|
|
5335 i += num + 1;
|
|
5336 if (i < 0)
|
|
5337 i += hislen;
|
|
5338 if (hist[i].hisstr != NULL)
|
|
5339 return i;
|
|
5340 }
|
|
5341 return -1;
|
|
5342 }
|
|
5343
|
|
5344 /*
|
|
5345 * Get a history entry by its index.
|
|
5346 * "histype" may be one of the HIST_ values.
|
|
5347 */
|
|
5348 char_u *
|
|
5349 get_history_entry(histype, idx)
|
|
5350 int histype;
|
|
5351 int idx;
|
|
5352 {
|
|
5353 idx = calc_hist_idx(histype, idx);
|
|
5354 if (idx >= 0)
|
|
5355 return history[histype][idx].hisstr;
|
|
5356 else
|
|
5357 return (char_u *)"";
|
|
5358 }
|
|
5359
|
|
5360 /*
|
|
5361 * Clear all entries of a history.
|
|
5362 * "histype" may be one of the HIST_ values.
|
|
5363 */
|
|
5364 int
|
|
5365 clr_history(histype)
|
|
5366 int histype;
|
|
5367 {
|
|
5368 int i;
|
|
5369 histentry_T *hisptr;
|
|
5370
|
|
5371 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT)
|
|
5372 {
|
|
5373 hisptr = history[histype];
|
|
5374 for (i = hislen; i--;)
|
|
5375 {
|
|
5376 vim_free(hisptr->hisstr);
|
|
5377 hisptr->hisnum = 0;
|
|
5378 hisptr++->hisstr = NULL;
|
|
5379 }
|
|
5380 hisidx[histype] = -1; /* mark history as cleared */
|
|
5381 hisnum[histype] = 0; /* reset identifier counter */
|
|
5382 return OK;
|
|
5383 }
|
|
5384 return FAIL;
|
|
5385 }
|
|
5386
|
|
5387 /*
|
|
5388 * Remove all entries matching {str} from a history.
|
|
5389 * "histype" may be one of the HIST_ values.
|
|
5390 */
|
|
5391 int
|
|
5392 del_history_entry(histype, str)
|
|
5393 int histype;
|
|
5394 char_u *str;
|
|
5395 {
|
|
5396 regmatch_T regmatch;
|
|
5397 histentry_T *hisptr;
|
|
5398 int idx;
|
|
5399 int i;
|
|
5400 int last;
|
|
5401 int found = FALSE;
|
|
5402
|
|
5403 regmatch.regprog = NULL;
|
|
5404 regmatch.rm_ic = FALSE; /* always match case */
|
|
5405 if (hislen != 0
|
|
5406 && histype >= 0
|
|
5407 && histype < HIST_COUNT
|
|
5408 && *str != NUL
|
|
5409 && (idx = hisidx[histype]) >= 0
|
|
5410 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING))
|
|
5411 != NULL)
|
|
5412 {
|
|
5413 i = last = idx;
|
|
5414 do
|
|
5415 {
|
|
5416 hisptr = &history[histype][i];
|
|
5417 if (hisptr->hisstr == NULL)
|
|
5418 break;
|
|
5419 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0))
|
|
5420 {
|
|
5421 found = TRUE;
|
|
5422 vim_free(hisptr->hisstr);
|
|
5423 hisptr->hisstr = NULL;
|
|
5424 hisptr->hisnum = 0;
|
|
5425 }
|
|
5426 else
|
|
5427 {
|
|
5428 if (i != last)
|
|
5429 {
|
|
5430 history[histype][last] = *hisptr;
|
|
5431 hisptr->hisstr = NULL;
|
|
5432 hisptr->hisnum = 0;
|
|
5433 }
|
|
5434 if (--last < 0)
|
|
5435 last += hislen;
|
|
5436 }
|
|
5437 if (--i < 0)
|
|
5438 i += hislen;
|
|
5439 } while (i != idx);
|
|
5440 if (history[histype][idx].hisstr == NULL)
|
|
5441 hisidx[histype] = -1;
|
|
5442 }
|
|
5443 vim_free(regmatch.regprog);
|
|
5444 return found;
|
|
5445 }
|
|
5446
|
|
5447 /*
|
|
5448 * Remove an indexed entry from a history.
|
|
5449 * "histype" may be one of the HIST_ values.
|
|
5450 */
|
|
5451 int
|
|
5452 del_history_idx(histype, idx)
|
|
5453 int histype;
|
|
5454 int idx;
|
|
5455 {
|
|
5456 int i, j;
|
|
5457
|
|
5458 i = calc_hist_idx(histype, idx);
|
|
5459 if (i < 0)
|
|
5460 return FALSE;
|
|
5461 idx = hisidx[histype];
|
|
5462 vim_free(history[histype][i].hisstr);
|
|
5463
|
|
5464 /* When deleting the last added search string in a mapping, reset
|
|
5465 * last_maptick, so that the last added search string isn't deleted again.
|
|
5466 */
|
|
5467 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx)
|
|
5468 last_maptick = -1;
|
|
5469
|
|
5470 while (i != idx)
|
|
5471 {
|
|
5472 j = (i + 1) % hislen;
|
|
5473 history[histype][i] = history[histype][j];
|
|
5474 i = j;
|
|
5475 }
|
|
5476 history[histype][i].hisstr = NULL;
|
|
5477 history[histype][i].hisnum = 0;
|
|
5478 if (--i < 0)
|
|
5479 i += hislen;
|
|
5480 hisidx[histype] = i;
|
|
5481 return TRUE;
|
|
5482 }
|
|
5483
|
|
5484 #endif /* FEAT_EVAL */
|
|
5485
|
|
5486 #if defined(FEAT_CRYPT) || defined(PROTO)
|
|
5487 /*
|
|
5488 * Very specific function to remove the value in ":set key=val" from the
|
|
5489 * history.
|
|
5490 */
|
|
5491 void
|
|
5492 remove_key_from_history()
|
|
5493 {
|
|
5494 char_u *p;
|
|
5495 int i;
|
|
5496
|
|
5497 i = hisidx[HIST_CMD];
|
|
5498 if (i < 0)
|
|
5499 return;
|
|
5500 p = history[HIST_CMD][i].hisstr;
|
|
5501 if (p != NULL)
|
|
5502 for ( ; *p; ++p)
|
|
5503 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3]))
|
|
5504 {
|
|
5505 p = vim_strchr(p + 3, '=');
|
|
5506 if (p == NULL)
|
|
5507 break;
|
|
5508 ++p;
|
|
5509 for (i = 0; p[i] && !vim_iswhite(p[i]); ++i)
|
|
5510 if (p[i] == '\\' && p[i + 1])
|
|
5511 ++i;
|
|
5512 mch_memmove(p, p + i, STRLEN(p + i) + 1);
|
|
5513 --p;
|
|
5514 }
|
|
5515 }
|
|
5516 #endif
|
|
5517
|
|
5518 #endif /* FEAT_CMDHIST */
|
|
5519
|
|
5520 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO)
|
|
5521 /*
|
|
5522 * Get indices "num1,num2" that specify a range within a list (not a range of
|
|
5523 * text lines in a buffer!) from a string. Used for ":history" and ":clist".
|
|
5524 * Returns OK if parsed successfully, otherwise FAIL.
|
|
5525 */
|
|
5526 int
|
|
5527 get_list_range(str, num1, num2)
|
|
5528 char_u **str;
|
|
5529 int *num1;
|
|
5530 int *num2;
|
|
5531 {
|
|
5532 int len;
|
|
5533 int first = FALSE;
|
|
5534 long num;
|
|
5535
|
|
5536 *str = skipwhite(*str);
|
|
5537 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */
|
|
5538 {
|
|
5539 vim_str2nr(*str, NULL, &len, FALSE, FALSE, &num, NULL);
|
|
5540 *str += len;
|
|
5541 *num1 = (int)num;
|
|
5542 first = TRUE;
|
|
5543 }
|
|
5544 *str = skipwhite(*str);
|
|
5545 if (**str == ',') /* parse "to" part of range */
|
|
5546 {
|
|
5547 *str = skipwhite(*str + 1);
|
|
5548 vim_str2nr(*str, NULL, &len, FALSE, FALSE, &num, NULL);
|
|
5549 if (len > 0)
|
|
5550 {
|
|
5551 *num2 = (int)num;
|
|
5552 *str = skipwhite(*str + len);
|
|
5553 }
|
|
5554 else if (!first) /* no number given at all */
|
|
5555 return FAIL;
|
|
5556 }
|
|
5557 else if (first) /* only one number given */
|
|
5558 *num2 = *num1;
|
|
5559 return OK;
|
|
5560 }
|
|
5561 #endif
|
|
5562
|
|
5563 #if defined(FEAT_CMDHIST) || defined(PROTO)
|
|
5564 /*
|
|
5565 * :history command - print a history
|
|
5566 */
|
|
5567 void
|
|
5568 ex_history(eap)
|
|
5569 exarg_T *eap;
|
|
5570 {
|
|
5571 histentry_T *hist;
|
|
5572 int histype1 = HIST_CMD;
|
|
5573 int histype2 = HIST_CMD;
|
|
5574 int hisidx1 = 1;
|
|
5575 int hisidx2 = -1;
|
|
5576 int idx;
|
|
5577 int i, j, k;
|
|
5578 char_u *end;
|
|
5579 char_u *arg = eap->arg;
|
|
5580
|
|
5581 if (hislen == 0)
|
|
5582 {
|
|
5583 MSG(_("'history' option is zero"));
|
|
5584 return;
|
|
5585 }
|
|
5586
|
|
5587 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ','))
|
|
5588 {
|
|
5589 end = arg;
|
|
5590 while (ASCII_ISALPHA(*end)
|
|
5591 || vim_strchr((char_u *)":=@>/?", *end) != NULL)
|
|
5592 end++;
|
|
5593 i = *end;
|
|
5594 *end = NUL;
|
|
5595 histype1 = get_histtype(arg);
|
|
5596 if (histype1 == -1)
|
|
5597 {
|
|
5598 if (STRICMP(arg, "all") == 0)
|
|
5599 {
|
|
5600 histype1 = 0;
|
|
5601 histype2 = HIST_COUNT-1;
|
|
5602 }
|
|
5603 else
|
|
5604 {
|
|
5605 *end = i;
|
|
5606 EMSG(_(e_trailing));
|
|
5607 return;
|
|
5608 }
|
|
5609 }
|
|
5610 else
|
|
5611 histype2 = histype1;
|
|
5612 *end = i;
|
|
5613 }
|
|
5614 else
|
|
5615 end = arg;
|
|
5616 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL)
|
|
5617 {
|
|
5618 EMSG(_(e_trailing));
|
|
5619 return;
|
|
5620 }
|
|
5621
|
|
5622 for (; !got_int && histype1 <= histype2; ++histype1)
|
|
5623 {
|
|
5624 STRCPY(IObuff, "\n # ");
|
|
5625 STRCAT(STRCAT(IObuff, history_names[histype1]), " history");
|
|
5626 MSG_PUTS_TITLE(IObuff);
|
|
5627 idx = hisidx[histype1];
|
|
5628 hist = history[histype1];
|
|
5629 j = hisidx1;
|
|
5630 k = hisidx2;
|
|
5631 if (j < 0)
|
|
5632 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum;
|
|
5633 if (k < 0)
|
|
5634 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum;
|
|
5635 if (idx >= 0 && j <= k)
|
|
5636 for (i = idx + 1; !got_int; ++i)
|
|
5637 {
|
|
5638 if (i == hislen)
|
|
5639 i = 0;
|
|
5640 if (hist[i].hisstr != NULL
|
|
5641 && hist[i].hisnum >= j && hist[i].hisnum <= k)
|
|
5642 {
|
|
5643 msg_putchar('\n');
|
|
5644 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ',
|
|
5645 hist[i].hisnum);
|
|
5646 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10)
|
|
5647 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff),
|
|
5648 (int)Columns - 10);
|
|
5649 else
|
|
5650 STRCAT(IObuff, hist[i].hisstr);
|
|
5651 msg_outtrans(IObuff);
|
|
5652 out_flush();
|
|
5653 }
|
|
5654 if (i == idx)
|
|
5655 break;
|
|
5656 }
|
|
5657 }
|
|
5658 }
|
|
5659 #endif
|
|
5660
|
|
5661 #if (defined(FEAT_VIMINFO) && defined(FEAT_CMDHIST)) || defined(PROTO)
|
|
5662 static char_u **viminfo_history[HIST_COUNT] = {NULL, NULL, NULL, NULL};
|
|
5663 static int viminfo_hisidx[HIST_COUNT] = {0, 0, 0, 0};
|
|
5664 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0};
|
|
5665 static int viminfo_add_at_front = FALSE;
|
|
5666
|
|
5667 static int hist_type2char __ARGS((int type, int use_question));
|
|
5668
|
|
5669 /*
|
|
5670 * Translate a history type number to the associated character.
|
|
5671 */
|
|
5672 static int
|
|
5673 hist_type2char(type, use_question)
|
|
5674 int type;
|
|
5675 int use_question; /* use '?' instead of '/' */
|
|
5676 {
|
|
5677 if (type == HIST_CMD)
|
|
5678 return ':';
|
|
5679 if (type == HIST_SEARCH)
|
|
5680 {
|
|
5681 if (use_question)
|
|
5682 return '?';
|
|
5683 else
|
|
5684 return '/';
|
|
5685 }
|
|
5686 if (type == HIST_EXPR)
|
|
5687 return '=';
|
|
5688 return '@';
|
|
5689 }
|
|
5690
|
|
5691 /*
|
|
5692 * Prepare for reading the history from the viminfo file.
|
|
5693 * This allocates history arrays to store the read history lines.
|
|
5694 */
|
|
5695 void
|
|
5696 prepare_viminfo_history(asklen)
|
|
5697 int asklen;
|
|
5698 {
|
|
5699 int i;
|
|
5700 int num;
|
|
5701 int type;
|
|
5702 int len;
|
|
5703
|
|
5704 init_history();
|
|
5705 viminfo_add_at_front = (asklen != 0);
|
|
5706 if (asklen > hislen)
|
|
5707 asklen = hislen;
|
|
5708
|
|
5709 for (type = 0; type < HIST_COUNT; ++type)
|
|
5710 {
|
|
5711 /*
|
|
5712 * Count the number of empty spaces in the history list. If there are
|
|
5713 * more spaces available than we request, then fill them up.
|
|
5714 */
|
|
5715 for (i = 0, num = 0; i < hislen; i++)
|
|
5716 if (history[type][i].hisstr == NULL)
|
|
5717 num++;
|
|
5718 len = asklen;
|
|
5719 if (num > len)
|
|
5720 len = num;
|
|
5721 if (len <= 0)
|
|
5722 viminfo_history[type] = NULL;
|
|
5723 else
|
|
5724 viminfo_history[type] =
|
|
5725 (char_u **)lalloc((long_u)(len * sizeof(char_u *)), FALSE);
|
|
5726 if (viminfo_history[type] == NULL)
|
|
5727 len = 0;
|
|
5728 viminfo_hislen[type] = len;
|
|
5729 viminfo_hisidx[type] = 0;
|
|
5730 }
|
|
5731 }
|
|
5732
|
|
5733 /*
|
|
5734 * Accept a line from the viminfo, store it in the history array when it's
|
|
5735 * new.
|
|
5736 */
|
|
5737 int
|
|
5738 read_viminfo_history(virp)
|
|
5739 vir_T *virp;
|
|
5740 {
|
|
5741 int type;
|
|
5742 long_u len;
|
|
5743 char_u *val;
|
|
5744 char_u *p;
|
|
5745
|
|
5746 type = hist_char2type(virp->vir_line[0]);
|
|
5747 if (viminfo_hisidx[type] < viminfo_hislen[type])
|
|
5748 {
|
|
5749 val = viminfo_readstring(virp, 1, TRUE);
|
|
5750 if (val != NULL && *val != NUL)
|
|
5751 {
|
|
5752 if (!in_history(type, val + (type == HIST_SEARCH),
|
|
5753 viminfo_add_at_front))
|
|
5754 {
|
|
5755 /* Need to re-allocate to append the separator byte. */
|
|
5756 len = STRLEN(val);
|
|
5757 p = lalloc(len + 2, TRUE);
|
|
5758 if (p != NULL)
|
|
5759 {
|
|
5760 if (type == HIST_SEARCH)
|
|
5761 {
|
|
5762 /* Search entry: Move the separator from the first
|
|
5763 * column to after the NUL. */
|
|
5764 mch_memmove(p, val + 1, (size_t)len);
|
|
5765 p[len] = (*val == ' ' ? NUL : *val);
|
|
5766 }
|
|
5767 else
|
|
5768 {
|
|
5769 /* Not a search entry: No separator in the viminfo
|
|
5770 * file, add a NUL separator. */
|
|
5771 mch_memmove(p, val, (size_t)len + 1);
|
|
5772 p[len + 1] = NUL;
|
|
5773 }
|
|
5774 viminfo_history[type][viminfo_hisidx[type]++] = p;
|
|
5775 }
|
|
5776 }
|
|
5777 }
|
|
5778 vim_free(val);
|
|
5779 }
|
|
5780 return viminfo_readline(virp);
|
|
5781 }
|
|
5782
|
|
5783 void
|
|
5784 finish_viminfo_history()
|
|
5785 {
|
|
5786 int idx;
|
|
5787 int i;
|
|
5788 int type;
|
|
5789
|
|
5790 for (type = 0; type < HIST_COUNT; ++type)
|
|
5791 {
|
|
5792 if (history[type] == NULL)
|
|
5793 return;
|
|
5794 idx = hisidx[type] + viminfo_hisidx[type];
|
|
5795 if (idx >= hislen)
|
|
5796 idx -= hislen;
|
|
5797 else if (idx < 0)
|
|
5798 idx = hislen - 1;
|
|
5799 if (viminfo_add_at_front)
|
|
5800 hisidx[type] = idx;
|
|
5801 else
|
|
5802 {
|
|
5803 if (hisidx[type] == -1)
|
|
5804 hisidx[type] = hislen - 1;
|
|
5805 do
|
|
5806 {
|
|
5807 if (history[type][idx].hisstr != NULL)
|
|
5808 break;
|
|
5809 if (++idx == hislen)
|
|
5810 idx = 0;
|
|
5811 } while (idx != hisidx[type]);
|
|
5812 if (idx != hisidx[type] && --idx < 0)
|
|
5813 idx = hislen - 1;
|
|
5814 }
|
|
5815 for (i = 0; i < viminfo_hisidx[type]; i++)
|
|
5816 {
|
|
5817 vim_free(history[type][idx].hisstr);
|
|
5818 history[type][idx].hisstr = viminfo_history[type][i];
|
|
5819 if (--idx < 0)
|
|
5820 idx = hislen - 1;
|
|
5821 }
|
|
5822 idx += 1;
|
|
5823 idx %= hislen;
|
|
5824 for (i = 0; i < viminfo_hisidx[type]; i++)
|
|
5825 {
|
|
5826 history[type][idx++].hisnum = ++hisnum[type];
|
|
5827 idx %= hislen;
|
|
5828 }
|
|
5829 vim_free(viminfo_history[type]);
|
|
5830 viminfo_history[type] = NULL;
|
|
5831 }
|
|
5832 }
|
|
5833
|
|
5834 void
|
|
5835 write_viminfo_history(fp)
|
|
5836 FILE *fp;
|
|
5837 {
|
|
5838 int i;
|
|
5839 int type;
|
|
5840 int num_saved;
|
|
5841 char_u *p;
|
|
5842 int c;
|
|
5843
|
|
5844 init_history();
|
|
5845 if (hislen == 0)
|
|
5846 return;
|
|
5847 for (type = 0; type < HIST_COUNT; ++type)
|
|
5848 {
|
|
5849 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE));
|
|
5850 if (num_saved == 0)
|
|
5851 continue;
|
|
5852 if (num_saved < 0) /* Use default */
|
|
5853 num_saved = hislen;
|
|
5854 fprintf(fp, _("\n# %s History (newest to oldest):\n"),
|
|
5855 type == HIST_CMD ? _("Command Line") :
|
|
5856 type == HIST_SEARCH ? _("Search String") :
|
|
5857 type == HIST_EXPR ? _("Expression") :
|
|
5858 _("Input Line"));
|
|
5859 if (num_saved > hislen)
|
|
5860 num_saved = hislen;
|
|
5861 i = hisidx[type];
|
|
5862 if (i >= 0)
|
|
5863 while (num_saved--)
|
|
5864 {
|
|
5865 p = history[type][i].hisstr;
|
|
5866 if (p != NULL)
|
|
5867 {
|
301
|
5868 fputc(hist_type2char(type, TRUE), fp);
|
7
|
5869 /* For the search history: put the separator in the second
|
|
5870 * column; use a space if there isn't one. */
|
|
5871 if (type == HIST_SEARCH)
|
|
5872 {
|
|
5873 c = p[STRLEN(p) + 1];
|
|
5874 putc(c == NUL ? ' ' : c, fp);
|
|
5875 }
|
|
5876 viminfo_writestring(fp, p);
|
|
5877 }
|
|
5878 if (--i < 0)
|
|
5879 i = hislen - 1;
|
|
5880 }
|
|
5881 }
|
|
5882 }
|
|
5883 #endif /* FEAT_VIMINFO */
|
|
5884
|
|
5885 #if defined(FEAT_FKMAP) || defined(PROTO)
|
|
5886 /*
|
|
5887 * Write a character at the current cursor+offset position.
|
|
5888 * It is directly written into the command buffer block.
|
|
5889 */
|
|
5890 void
|
|
5891 cmd_pchar(c, offset)
|
|
5892 int c, offset;
|
|
5893 {
|
|
5894 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0)
|
|
5895 {
|
|
5896 EMSG(_("E198: cmd_pchar beyond the command length"));
|
|
5897 return;
|
|
5898 }
|
|
5899 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c;
|
|
5900 ccline.cmdbuff[ccline.cmdlen] = NUL;
|
|
5901 }
|
|
5902
|
|
5903 int
|
|
5904 cmd_gchar(offset)
|
|
5905 int offset;
|
|
5906 {
|
|
5907 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0)
|
|
5908 {
|
|
5909 /* EMSG(_("cmd_gchar beyond the command length")); */
|
|
5910 return NUL;
|
|
5911 }
|
|
5912 return (int)ccline.cmdbuff[ccline.cmdpos + offset];
|
|
5913 }
|
|
5914 #endif
|
|
5915
|
|
5916 #if defined(FEAT_CMDWIN) || defined(PROTO)
|
|
5917 /*
|
|
5918 * Open a window on the current command line and history. Allow editing in
|
|
5919 * the window. Returns when the window is closed.
|
|
5920 * Returns:
|
|
5921 * CR if the command is to be executed
|
|
5922 * Ctrl_C if it is to be abandoned
|
|
5923 * K_IGNORE if editing continues
|
|
5924 */
|
|
5925 static int
|
|
5926 ex_window()
|
|
5927 {
|
|
5928 struct cmdline_info save_ccline;
|
|
5929 buf_T *old_curbuf = curbuf;
|
|
5930 win_T *old_curwin = curwin;
|
|
5931 buf_T *bp;
|
|
5932 win_T *wp;
|
|
5933 int i;
|
|
5934 linenr_T lnum;
|
|
5935 int histtype;
|
|
5936 garray_T winsizes;
|
|
5937 char_u typestr[2];
|
|
5938 int save_restart_edit = restart_edit;
|
|
5939 int save_State = State;
|
|
5940 int save_exmode = exmode_active;
|
510
|
5941 #ifdef FEAT_RIGHTLEFT
|
|
5942 int save_cmdmsg_rl = cmdmsg_rl;
|
|
5943 #endif
|
7
|
5944
|
|
5945 /* Can't do this recursively. Can't do it when typing a password. */
|
|
5946 if (cmdwin_type != 0
|
|
5947 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
5948 || cmdline_star > 0
|
|
5949 # endif
|
|
5950 )
|
|
5951 {
|
|
5952 beep_flush();
|
|
5953 return K_IGNORE;
|
|
5954 }
|
|
5955
|
|
5956 /* Save current window sizes. */
|
|
5957 win_size_save(&winsizes);
|
|
5958
|
|
5959 # ifdef FEAT_AUTOCMD
|
|
5960 /* Don't execute autocommands while creating the window. */
|
1410
|
5961 block_autocmds();
|
7
|
5962 # endif
|
683
|
5963 /* don't use a new tab page */
|
|
5964 cmdmod.tab = 0;
|
|
5965
|
7
|
5966 /* Create a window for the command-line buffer. */
|
|
5967 if (win_split((int)p_cwh, WSP_BOT) == FAIL)
|
|
5968 {
|
|
5969 beep_flush();
|
1410
|
5970 # ifdef FEAT_AUTOCMD
|
|
5971 unblock_autocmds();
|
|
5972 # endif
|
7
|
5973 return K_IGNORE;
|
|
5974 }
|
|
5975 cmdwin_type = ccline.cmdfirstc;
|
|
5976 if (cmdwin_type == NUL)
|
|
5977 cmdwin_type = '-';
|
|
5978
|
|
5979 /* Create the command-line buffer empty. */
|
|
5980 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE);
|
|
5981 (void)setfname(curbuf, (char_u *)"command-line", NULL, TRUE);
|
|
5982 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
|
|
5983 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
|
|
5984 curbuf->b_p_ma = TRUE;
|
|
5985 # ifdef FEAT_RIGHTLEFT
|
510
|
5986 curwin->w_p_rl = cmdmsg_rl;
|
|
5987 cmdmsg_rl = FALSE;
|
7
|
5988 # endif
|
|
5989 # ifdef FEAT_SCROLLBIND
|
|
5990 curwin->w_p_scb = FALSE;
|
|
5991 # endif
|
|
5992
|
|
5993 # ifdef FEAT_AUTOCMD
|
|
5994 /* Do execute autocommands for setting the filetype (load syntax). */
|
1410
|
5995 unblock_autocmds();
|
7
|
5996 # endif
|
|
5997
|
510
|
5998 /* Showing the prompt may have set need_wait_return, reset it. */
|
|
5999 need_wait_return = FALSE;
|
|
6000
|
7
|
6001 histtype = hist_char2type(ccline.cmdfirstc);
|
|
6002 if (histtype == HIST_CMD || histtype == HIST_DEBUG)
|
|
6003 {
|
|
6004 if (p_wc == TAB)
|
|
6005 {
|
|
6006 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT);
|
|
6007 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL);
|
|
6008 }
|
|
6009 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL);
|
|
6010 }
|
|
6011
|
10
|
6012 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
|
|
6013 * sets 'textwidth' to 78). */
|
|
6014 curbuf->b_p_tw = 0;
|
|
6015
|
7
|
6016 /* Fill the buffer with the history. */
|
|
6017 init_history();
|
|
6018 if (hislen > 0)
|
|
6019 {
|
|
6020 i = hisidx[histtype];
|
|
6021 if (i >= 0)
|
|
6022 {
|
|
6023 lnum = 0;
|
|
6024 do
|
|
6025 {
|
|
6026 if (++i == hislen)
|
|
6027 i = 0;
|
|
6028 if (history[histtype][i].hisstr != NULL)
|
|
6029 ml_append(lnum++, history[histtype][i].hisstr,
|
|
6030 (colnr_T)0, FALSE);
|
|
6031 }
|
|
6032 while (i != hisidx[histtype]);
|
|
6033 }
|
|
6034 }
|
|
6035
|
|
6036 /* Replace the empty last line with the current command-line and put the
|
|
6037 * cursor there. */
|
|
6038 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE);
|
|
6039 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
6040 curwin->w_cursor.col = ccline.cmdpos;
|
510
|
6041 changed_line_abv_curs();
|
|
6042 invalidate_botline();
|
743
|
6043 redraw_later(SOME_VALID);
|
7
|
6044
|
|
6045 /* Save the command line info, can be used recursively. */
|
|
6046 save_ccline = ccline;
|
|
6047 ccline.cmdbuff = NULL;
|
|
6048 ccline.cmdprompt = NULL;
|
|
6049
|
|
6050 /* No Ex mode here! */
|
|
6051 exmode_active = 0;
|
|
6052
|
|
6053 State = NORMAL;
|
|
6054 # ifdef FEAT_MOUSE
|
|
6055 setmouse();
|
|
6056 # endif
|
|
6057
|
|
6058 # ifdef FEAT_AUTOCMD
|
|
6059 /* Trigger CmdwinEnter autocommands. */
|
|
6060 typestr[0] = cmdwin_type;
|
|
6061 typestr[1] = NUL;
|
|
6062 apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, FALSE, curbuf);
|
929
|
6063 if (restart_edit != 0) /* autocmd with ":startinsert" */
|
|
6064 stuffcharReadbuff(K_NOP);
|
7
|
6065 # endif
|
|
6066
|
|
6067 i = RedrawingDisabled;
|
|
6068 RedrawingDisabled = 0;
|
|
6069
|
|
6070 /*
|
|
6071 * Call the main loop until <CR> or CTRL-C is typed.
|
|
6072 */
|
|
6073 cmdwin_result = 0;
|
168
|
6074 main_loop(TRUE, FALSE);
|
7
|
6075
|
|
6076 RedrawingDisabled = i;
|
|
6077
|
|
6078 # ifdef FEAT_AUTOCMD
|
|
6079 /* Trigger CmdwinLeave autocommands. */
|
|
6080 apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, FALSE, curbuf);
|
|
6081 # endif
|
|
6082
|
1214
|
6083 /* Restore the command line info. */
|
7
|
6084 ccline = save_ccline;
|
|
6085 cmdwin_type = 0;
|
|
6086
|
|
6087 exmode_active = save_exmode;
|
|
6088
|
|
6089 /* Safety check: The old window or buffer was deleted: It's a a bug when
|
|
6090 * this happens! */
|
|
6091 if (!win_valid(old_curwin) || !buf_valid(old_curbuf))
|
|
6092 {
|
|
6093 cmdwin_result = Ctrl_C;
|
|
6094 EMSG(_("E199: Active window or buffer deleted"));
|
|
6095 }
|
|
6096 else
|
|
6097 {
|
|
6098 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
|
|
6099 /* autocmds may abort script processing */
|
|
6100 if (aborting() && cmdwin_result != K_IGNORE)
|
|
6101 cmdwin_result = Ctrl_C;
|
|
6102 # endif
|
|
6103 /* Set the new command line from the cmdline buffer. */
|
|
6104 vim_free(ccline.cmdbuff);
|
510
|
6105 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */
|
7
|
6106 {
|
510
|
6107 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!";
|
|
6108
|
|
6109 if (histtype == HIST_CMD)
|
|
6110 {
|
|
6111 /* Execute the command directly. */
|
|
6112 ccline.cmdbuff = vim_strsave((char_u *)p);
|
|
6113 cmdwin_result = CAR;
|
|
6114 }
|
|
6115 else
|
|
6116 {
|
|
6117 /* First need to cancel what we were doing. */
|
|
6118 ccline.cmdbuff = NULL;
|
|
6119 stuffcharReadbuff(':');
|
|
6120 stuffReadbuff((char_u *)p);
|
|
6121 stuffcharReadbuff(CAR);
|
|
6122 }
|
7
|
6123 }
|
|
6124 else if (cmdwin_result == K_XF2) /* :qa typed */
|
|
6125 {
|
|
6126 ccline.cmdbuff = vim_strsave((char_u *)"qa");
|
|
6127 cmdwin_result = CAR;
|
|
6128 }
|
|
6129 else
|
|
6130 ccline.cmdbuff = vim_strsave(ml_get_curline());
|
|
6131 if (ccline.cmdbuff == NULL)
|
|
6132 cmdwin_result = Ctrl_C;
|
|
6133 else
|
|
6134 {
|
|
6135 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
|
|
6136 ccline.cmdbufflen = ccline.cmdlen + 1;
|
|
6137 ccline.cmdpos = curwin->w_cursor.col;
|
|
6138 if (ccline.cmdpos > ccline.cmdlen)
|
|
6139 ccline.cmdpos = ccline.cmdlen;
|
|
6140 if (cmdwin_result == K_IGNORE)
|
|
6141 {
|
|
6142 set_cmdspos_cursor();
|
|
6143 redrawcmd();
|
|
6144 }
|
|
6145 }
|
|
6146
|
|
6147 # ifdef FEAT_AUTOCMD
|
|
6148 /* Don't execute autocommands while deleting the window. */
|
1410
|
6149 block_autocmds();
|
7
|
6150 # endif
|
|
6151 wp = curwin;
|
|
6152 bp = curbuf;
|
|
6153 win_goto(old_curwin);
|
|
6154 win_close(wp, TRUE);
|
|
6155 close_buffer(NULL, bp, DOBUF_WIPE);
|
|
6156
|
|
6157 /* Restore window sizes. */
|
|
6158 win_size_restore(&winsizes);
|
|
6159
|
|
6160 # ifdef FEAT_AUTOCMD
|
1410
|
6161 unblock_autocmds();
|
7
|
6162 # endif
|
|
6163 }
|
|
6164
|
|
6165 ga_clear(&winsizes);
|
|
6166 restart_edit = save_restart_edit;
|
510
|
6167 # ifdef FEAT_RIGHTLEFT
|
|
6168 cmdmsg_rl = save_cmdmsg_rl;
|
|
6169 # endif
|
7
|
6170
|
|
6171 State = save_State;
|
|
6172 # ifdef FEAT_MOUSE
|
|
6173 setmouse();
|
|
6174 # endif
|
|
6175
|
|
6176 return cmdwin_result;
|
|
6177 }
|
|
6178 #endif /* FEAT_CMDWIN */
|
|
6179
|
|
6180 /*
|
|
6181 * Used for commands that either take a simple command string argument, or:
|
|
6182 * cmd << endmarker
|
|
6183 * {script}
|
|
6184 * endmarker
|
|
6185 * Returns a pointer to allocated memory with {script} or NULL.
|
|
6186 */
|
|
6187 char_u *
|
|
6188 script_get(eap, cmd)
|
|
6189 exarg_T *eap;
|
|
6190 char_u *cmd;
|
|
6191 {
|
|
6192 char_u *theline;
|
|
6193 char *end_pattern = NULL;
|
|
6194 char dot[] = ".";
|
|
6195 garray_T ga;
|
|
6196
|
|
6197 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL)
|
|
6198 return NULL;
|
|
6199
|
|
6200 ga_init2(&ga, 1, 0x400);
|
|
6201
|
|
6202 if (cmd[2] != NUL)
|
|
6203 end_pattern = (char *)skipwhite(cmd + 2);
|
|
6204 else
|
|
6205 end_pattern = dot;
|
|
6206
|
|
6207 for (;;)
|
|
6208 {
|
|
6209 theline = eap->getline(
|
|
6210 #ifdef FEAT_EVAL
|
75
|
6211 eap->cstack->cs_looplevel > 0 ? -1 :
|
7
|
6212 #endif
|
|
6213 NUL, eap->cookie, 0);
|
|
6214
|
|
6215 if (theline == NULL || STRCMP(end_pattern, theline) == 0)
|
|
6216 break;
|
|
6217
|
|
6218 ga_concat(&ga, theline);
|
|
6219 ga_append(&ga, '\n');
|
|
6220 vim_free(theline);
|
|
6221 }
|
21
|
6222 ga_append(&ga, NUL);
|
7
|
6223
|
|
6224 return (char_u *)ga.ga_data;
|
|
6225 }
|