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