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