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