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