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