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