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