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