Mercurial > vim
annotate src/ex_getln.c @ 14563:d84e67a12671 v8.1.0295
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
commit https://github.com/vim/vim/commit/264cf5cfaf40e704aea2578e70c15ed9a9d0161e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 18 21:05:31 2018 +0200
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Problem: No 'incsearch' highlighting for :vimgrep and similar commands.
Solution: Parse the :vimgrep command and similar ones to locate the search
pattern. (Hirohito Higashi, closes #3344)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 18 Aug 2018 21:15:05 +0200 |
parents | 2bee637a8edc |
children | 5e038972cafa |
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 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
1718 | 47 /* The current cmdline_info. It is initialized in getcmdline() and after that |
48 * used by other functions. When invoking getcmdline() recursively it needs | |
49 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
50 * TODO: make it local to getcmdline() and pass it around. */ | |
51 static struct cmdline_info ccline; | |
7 | 52 |
53 static int cmd_showtail; /* Only show path tail in lists ? */ | |
54 | |
55 #ifdef FEAT_EVAL | |
56 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
57 #endif | |
58 | |
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
|
59 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
|
60 * 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
|
61 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
|
62 |
7 | 63 #ifdef FEAT_CMDHIST |
64 typedef struct hist_entry | |
65 { | |
66 int hisnum; /* identifying number */ | |
4258 | 67 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 68 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
|
69 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 70 } histentry_T; |
71 | |
72 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
73 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
74 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
75 /* identifying (unique) number of newest history entry */ | |
76 static int hislen = 0; /* actual length of history tables */ | |
77 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
80 static int in_history(int, char_u *, int, int, int); |
7 | 81 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
82 static int calc_hist_idx(int histype, int num); |
7 | 83 # endif |
84 #endif | |
85 | |
86 #ifdef FEAT_RIGHTLEFT | |
87 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
88 #endif | |
89 | |
90 #ifdef FEAT_FKMAP | |
91 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
92 #endif | |
93 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 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
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #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
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 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
|
123 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
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # 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
|
129 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
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #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
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
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 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
274 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
278 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 { |
14538
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
292 char_u *cmd; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
293 cmdmod_T save_cmdmod = cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
294 char_u *p; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
295 int delim; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
296 char_u *end; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
297 char_u *dummy; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
298 exarg_T ea; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
299 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
300 vim_memset(&ea, 0, sizeof(ea)); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
301 ea.line1 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
302 ea.line2 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
303 ea.cmd = ccline.cmdbuff; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
304 ea.addr_type = ADDR_LINES; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
305 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
306 parse_command_modifiers(&ea, &dummy, TRUE); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
307 cmdmod = save_cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
308 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
309 cmd = skip_range(ea.cmd, NULL); |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
310 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v' || *cmd == 'l') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
311 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 ; |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
315 if (*skipwhite(p) != NUL) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
316 { |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
317 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
318 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
319 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
320 || STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
321 || STRNCMP(cmd, "global", p - cmd) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
322 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
14534
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
323 { |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
324 if (*cmd == 's' && cmd[1] == 'm') |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
325 p_magic = TRUE; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
326 else if (*cmd == 's' && cmd[1] == 'n') |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
327 p_magic = FALSE; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
328 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
329 // Check for "global!/". |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
330 if (*cmd == 'g' && *p == '!') |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
331 { |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
332 p++; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
333 if (*skipwhite(p) == NUL) |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
334 return FALSE; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
335 } |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
336 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
337 // For ":sort" skip over flags. |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
338 if (cmd[0] == 's' && cmd[1] == 'o') |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
339 { |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
340 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
341 ++p; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
342 if (*p == NUL) |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
343 return FALSE; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
344 } |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
345 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
346 p = skipwhite(p); |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
347 delim = *p++; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
348 end = skip_regexp(p, delim, p_magic, NULL); |
14534
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
349 } |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
350 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
351 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
352 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
353 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0) |
14556
2bee637a8edc
patch 8.1.0291: 'incsearch' highlighting not used for :sort
Christian Brabandt <cb@256bit.org>
parents:
14548
diff
changeset
|
354 { |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
355 // Check for "!/". |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
356 if (*p == '!') |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
357 { |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
358 p++; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
359 if (*skipwhite(p) == NUL) |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
360 return FALSE; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
361 } |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
362 p = skipwhite(p); |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
363 delim = (vim_isIDc(*p)) ? ' ' : *p++; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
364 end = skip_regexp(p, delim, p_magic, NULL); |
14556
2bee637a8edc
patch 8.1.0291: 'incsearch' highlighting not used for :sort
Christian Brabandt <cb@256bit.org>
parents:
14548
diff
changeset
|
365 } |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
366 else |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
367 { |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
368 end = p; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
369 delim = -1; |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
370 } |
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
371 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
372 if (end > p || *end == delim) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
373 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
374 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
375 |
14563
d84e67a12671
patch 8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Christian Brabandt <cb@256bit.org>
parents:
14556
diff
changeset
|
376 // found a non-empty pattern or // |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
377 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
378 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
379 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
380 // parse the address range |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
381 curwin->w_cursor = is_state->search_start; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
382 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
383 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
384 { |
14530
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
385 // Allow for reverse match. |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
386 if (ea.line2 < ea.line1) |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
387 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
388 search_first_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
389 search_last_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
390 } |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
391 else |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
392 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
393 search_first_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
394 search_last_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
395 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
396 } |
14556
2bee637a8edc
patch 8.1.0291: 'incsearch' highlighting not used for :sort
Christian Brabandt <cb@256bit.org>
parents:
14548
diff
changeset
|
397 else if (cmd[0] == 's' && cmd[1] != 'o') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
398 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
399 // :s defaults to the current line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
400 search_first_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
401 search_last_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
402 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
403 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
404 curwin->w_cursor = save_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
405 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
406 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
407 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
408 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
409 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
410 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
411 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
412 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
414 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
415 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
416 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
430 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
436 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
440 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
441 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
442 redraw_all_later(SOME_VALID); |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
443 p_magic = is_state->magic_save; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
444 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
445 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
446 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
447 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 * Do 'incsearch' highlighting if desired. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 may_do_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
456 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 pos_T end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
461 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
463 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
464 int use_last_pat; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
465 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
466 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
467 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
468 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
470 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
472 // If there is a character waiting, search and redraw later. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
480 if (search_first_line == 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
481 // start at the original cursor position |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
482 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
483 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
484 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
485 // start at the first line in the range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
486 curwin->w_cursor.lnum = search_first_line; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
487 curwin->w_cursor.col = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
488 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
491 // Use the previous pattern for ":s//". |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
492 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
493 use_last_pat = patlen == 0 && skiplen > 0 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
494 && ccline.cmdbuff[skiplen - 1] == next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
495 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
496 // If there is no pattern, don't do anything. |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
497 if (patlen == 0 && !use_last_pat) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
499 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 set_no_hlsearch(TRUE); // turn off previous highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 redraw_all_later(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
503 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
504 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
507 cursor_off(); // so the user knows we're busy |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
509 ++emsg_off; // so it doesn't beep if bad expr |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 // Set the time limit to half a second. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 profile_setlimit(500L, &tm); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 search_flags += SEARCH_KEEP; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
516 if (search_first_line != 0) |
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
517 search_flags += SEARCH_START; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
518 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
519 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
520 ccline.cmdbuff + skiplen, count, search_flags, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
527 ccline.cmdbuff[skiplen + patlen] = next_char; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
530 if (curwin->w_cursor.lnum < search_first_line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
531 || curwin->w_cursor.lnum > search_last_line) |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
532 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
533 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
534 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
535 curwin->w_cursor = is_state->search_start; |
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
536 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
537 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 // if interrupted while searching, behave like it failed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 (void)vpeekc(); // remove <C-C> from input stream |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
545 else if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 // cancelled searching because a char was typed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 highlight_match = TRUE; // highlight position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 highlight_match = FALSE; // remove highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
554 // First restore the old curwin values, so the screen is positioned in the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 // same way as the actual search command. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
556 restore_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
558 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
559 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 pos_T save_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
563 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 set_search_match(&curwin->w_cursor); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 end_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 is_state->match_end = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 curwin->w_cursor = save_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 end_pos = curwin->w_cursor; // shutup gcc 4 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
573 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 // Avoids a flash when typing "foo\|". |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
576 if (!use_last_pat) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
577 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
578 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
579 ccline.cmdbuff[skiplen + patlen] = NUL; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
580 if (empty_pattern(ccline.cmdbuff)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
581 set_no_hlsearch(TRUE); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
582 ccline.cmdbuff[skiplen + patlen] = next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
583 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 // May redraw the status line to show the cursor position. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 if (p_ru && curwin->w_status_height > 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
588 curwin->w_redr_status = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 update_screen(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
595 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
596 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 is_state->did_incsearch = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 * May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 * Returns FAIL when jumping to cmdline_not_changed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 may_adjust_incsearch_highlighting( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
611 int firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
612 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 incsearch_state_T *is_state, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
614 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
616 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 int search_flags = SEARCH_NOOF; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 int i; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
621 int save; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
622 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
623 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
625 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
628 if (firstc == ccline.cmdbuff[skiplen]) |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
629 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 pat = last_search_pattern(); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
631 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
632 patlen = (int)STRLEN(pat); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
633 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 else |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
635 pat = ccline.cmdbuff + skiplen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 if (c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 t = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 if (LT_POS(is_state->match_start, is_state->match_end)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 // Start searching at the end of the match not at the beginning of |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
650 t = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
652 search_flags += SEARCH_KEEP; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
654 save = pat[patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
655 pat[patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 i = searchit(curwin, curbuf, &t, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
657 c == Ctrl_G ? FORWARD : BACKWARD, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
658 pat, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 RE_SEARCH, 0, NULL, NULL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
661 pat[patlen] = save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 is_state->search_start = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 is_state->match_end = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 is_state->match_start = t; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
667 if (c == Ctrl_T && firstc != '?') |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 // Move just before the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 else if (c == Ctrl_G && firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
675 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 // Move just after the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
681 if (LT_POS(t, is_state->search_start) && c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
682 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
684 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
687 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 set_search_match(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 curwin->w_cursor = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
693 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
694 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
695 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
696 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
697 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 update_screen(NOT_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
699 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
700 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
701 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 vim_beep(BO_ERROR); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
705 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 * When CTRL-L typed: add character from the match to the pattern. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
709 * May set "*c" to the added character. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
710 * Return OK when jumping to cmdline_not_changed. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
711 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
712 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
714 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
715 int skiplen, patlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
716 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
717 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
718 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
719 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
720 // Add a character from under the cursor for 'incsearch'. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
721 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
723 curwin->w_cursor = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
724 if (!EQUAL_POS(curwin->w_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
726 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
727 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
728 // If 'ignorecase' and 'smartcase' are set and the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
729 // command line has no uppercase characters, convert |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 // the character to lowercase. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
731 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
732 *c = MB_TOLOWER(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
734 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
735 if (*c == firstc || vim_strchr((char_u *)( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
736 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
737 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
738 // put a backslash before special characters |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
739 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
740 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
741 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
742 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
743 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
744 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
745 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
746 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
747 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
748 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
749 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
750 /* |
7 | 751 * getcmdline() - accept a command line starting with firstc. |
752 * | |
753 * firstc == ':' get ":" command line. | |
754 * firstc == '/' or '?' get search pattern | |
755 * firstc == '=' get expression | |
756 * firstc == '@' get text for input() function | |
757 * firstc == '>' get text for debug mode | |
758 * firstc == NUL get text for :insert command | |
759 * firstc == -1 like NUL, and break on CTRL-C | |
760 * | |
761 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
762 * command line. | |
763 * | |
764 * Careful: getcmdline() can be called recursively! | |
765 * | |
766 * Return pointer to allocated string if there is a commandline, NULL | |
767 * otherwise. | |
768 */ | |
769 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
770 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
771 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
772 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
|
773 int indent) /* indent for inside conditionals */ |
7 | 774 { |
775 int c; | |
776 int i; | |
777 int j; | |
778 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
779 int do_abbr; /* when TRUE check for abbr. */ | |
780 #ifdef FEAT_CMDHIST | |
781 char_u *lookfor = NULL; /* string to match */ | |
782 int hiscnt; /* current history line in use */ | |
783 int histype; /* history type to be used */ | |
784 #endif | |
785 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
786 incsearch_state_T is_state; |
7 | 787 #endif |
788 int did_wild_list = FALSE; /* did wild_list() recently */ | |
789 int wim_index = 0; /* index in wim_flags[] */ | |
790 int res; | |
791 int save_msg_scroll = msg_scroll; | |
792 int save_State = State; /* remember State when called */ | |
793 int some_key_typed = FALSE; /* one of the keys was typed */ | |
794 #ifdef FEAT_MOUSE | |
795 /* mouse drag and release events are ignored, unless they are | |
796 * preceded with a mouse down event */ | |
797 int ignore_drag_release = TRUE; | |
798 #endif | |
799 #ifdef FEAT_EVAL | |
800 int break_ctrl_c = FALSE; | |
801 #endif | |
802 expand_T xpc; | |
803 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
804 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 805 /* Everything that may work recursively should save and restore the |
806 * current command line in save_ccline. That includes update_screen(), a | |
807 * custom status line may invoke ":normal". */ | |
808 struct cmdline_info save_ccline; | |
809 #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
|
810 int cmdline_type; |
7 | 811 |
812 #ifdef FEAT_EVAL | |
813 if (firstc == -1) | |
814 { | |
815 firstc = NUL; | |
816 break_ctrl_c = TRUE; | |
817 } | |
818 #endif | |
819 #ifdef FEAT_RIGHTLEFT | |
820 /* start without Hebrew mapping for a command line */ | |
821 if (firstc == ':' || firstc == '=' || firstc == '>') | |
822 cmd_hkmap = 0; | |
823 #endif | |
824 | |
825 ccline.overstrike = FALSE; /* always start in insert mode */ | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
826 |
7 | 827 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
828 init_incsearch_state(&is_state); |
7 | 829 #endif |
830 | |
831 /* | |
832 * set some variables for redrawcmd() | |
833 */ | |
834 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 835 ccline.cmdindent = (firstc > 0 ? indent : 0); |
836 | |
837 /* alloc initial ccline.cmdbuff */ | |
838 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 839 if (ccline.cmdbuff == NULL) |
840 return NULL; /* out of memory */ | |
841 ccline.cmdlen = ccline.cmdpos = 0; | |
842 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
|
843 sb_text_start_cmdline(); |
7 | 844 |
164 | 845 /* autoindent for :insert and :append */ |
846 if (firstc <= 0) | |
847 { | |
6929 | 848 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 849 ccline.cmdbuff[indent] = NUL; |
850 ccline.cmdpos = indent; | |
851 ccline.cmdspos = indent; | |
852 ccline.cmdlen = indent; | |
853 } | |
854 | |
7 | 855 ExpandInit(&xpc); |
1718 | 856 ccline.xpc = &xpc; |
7 | 857 |
858 #ifdef FEAT_RIGHTLEFT | |
859 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
860 && (firstc == '/' || firstc == '?')) | |
861 cmdmsg_rl = TRUE; | |
862 else | |
863 cmdmsg_rl = FALSE; | |
864 #endif | |
865 | |
866 redir_off = TRUE; /* don't redirect the typed command */ | |
867 if (!cmd_silent) | |
868 { | |
869 i = msg_scrolled; | |
870 msg_scrolled = 0; /* avoid wait_return message */ | |
871 gotocmdline(TRUE); | |
872 msg_scrolled += i; | |
873 redrawcmdprompt(); /* draw prompt or indent */ | |
874 set_cmdspos(); | |
875 } | |
876 xpc.xp_context = EXPAND_NOTHING; | |
877 xpc.xp_backslash = XP_BS_NONE; | |
632 | 878 #ifndef BACKSLASH_IN_FILENAME |
879 xpc.xp_shell = FALSE; | |
880 #endif | |
7 | 881 |
531 | 882 #if defined(FEAT_EVAL) |
883 if (ccline.input_fn) | |
884 { | |
885 xpc.xp_context = ccline.xp_context; | |
886 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 887 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 888 xpc.xp_arg = ccline.xp_arg; |
1322 | 889 # endif |
531 | 890 } |
891 #endif | |
892 | |
7 | 893 /* |
894 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
895 * doing ":@0" when register 0 doesn't contain a CR. | |
896 */ | |
897 msg_scroll = FALSE; | |
898 | |
899 State = CMDLINE; | |
900 | |
901 if (firstc == '/' || firstc == '?' || firstc == '@') | |
902 { | |
903 /* Use ":lmap" mappings for search pattern and input(). */ | |
904 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
905 b_im_ptr = &curbuf->b_p_iminsert; | |
906 else | |
907 b_im_ptr = &curbuf->b_p_imsearch; | |
908 if (*b_im_ptr == B_IMODE_LMAP) | |
909 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
910 #ifdef HAVE_INPUT_METHOD |
7 | 911 im_set_active(*b_im_ptr == B_IMODE_IM); |
912 #endif | |
913 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
914 #ifdef HAVE_INPUT_METHOD |
7 | 915 else if (p_imcmdline) |
916 im_set_active(TRUE); | |
917 #endif | |
918 | |
919 #ifdef FEAT_MOUSE | |
920 setmouse(); | |
921 #endif | |
922 #ifdef CURSOR_SHAPE | |
923 ui_cursor_shape(); /* may show different cursor shape */ | |
924 #endif | |
925 | |
571 | 926 /* When inside an autocommand for writing "exiting" may be set and |
927 * terminal mode set to cooked. Need to set raw mode here then. */ | |
928 settmode(TMODE_RAW); | |
929 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
930 /* 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
|
931 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
|
932 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
|
933 |
7 | 934 #ifdef FEAT_CMDHIST |
935 init_history(); | |
936 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
937 histype = hist_char2type(firstc); | |
938 #endif | |
939 | |
940 #ifdef FEAT_DIGRAPHS | |
1868 | 941 do_digraph(-1); /* init digraph typeahead */ |
7 | 942 #endif |
943 | |
5993 | 944 /* If something above caused an error, reset the flags, we do want to type |
945 * and execute commands. Display may be messed up a bit. */ | |
946 if (did_emsg) | |
947 redrawcmd(); | |
948 did_emsg = FALSE; | |
949 got_int = FALSE; | |
950 | |
7 | 951 /* |
952 * Collect the command string, handling editing keys. | |
953 */ | |
954 for (;;) | |
955 { | |
972 | 956 redir_off = TRUE; /* Don't redirect the typed command. |
957 Repeated, because a ":redir" inside | |
958 completion may switch it on. */ | |
7 | 959 #ifdef USE_ON_FLY_SCROLL |
960 dont_scroll = FALSE; /* allow scrolling here */ | |
961 #endif | |
962 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
963 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
964 did_emsg = FALSE; /* There can't really be a reason why an error |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
965 that occurs while typing a command should |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
966 cause the command not to be executed. */ |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
967 |
7 | 968 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 969 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
970 /* Get a character. Ignore K_IGNORE and K_NOP, they should not do |
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
971 * anything, such as stop completion. */ |
1472 | 972 do |
973 { | |
974 c = safe_vgetc(); | |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
975 } while (c == K_IGNORE || c == K_NOP); |
1472 | 976 |
7 | 977 if (KeyTyped) |
978 { | |
979 some_key_typed = TRUE; | |
980 #ifdef FEAT_RIGHTLEFT | |
981 if (cmd_hkmap) | |
982 c = hkmap(c); | |
983 # ifdef FEAT_FKMAP | |
984 if (cmd_fkmap) | |
985 c = cmdl_fkmap(c); | |
986 # endif | |
987 if (cmdmsg_rl && !KeyStuffed) | |
988 { | |
989 /* Invert horizontal movements and operations. Only when | |
990 * typed by the user directly, not when the result of a | |
991 * mapping. */ | |
992 switch (c) | |
993 { | |
994 case K_RIGHT: c = K_LEFT; break; | |
995 case K_S_RIGHT: c = K_S_LEFT; break; | |
996 case K_C_RIGHT: c = K_C_LEFT; break; | |
997 case K_LEFT: c = K_RIGHT; break; | |
998 case K_S_LEFT: c = K_S_RIGHT; break; | |
999 case K_C_LEFT: c = K_C_RIGHT; break; | |
1000 } | |
1001 } | |
1002 #endif | |
1003 } | |
1004 | |
1005 /* | |
1006 * Ignore got_int when CTRL-C was typed here. | |
1007 * Don't ignore it in :global, we really need to break then, e.g., for | |
1008 * ":g/pat/normal /pat" (without the <CR>). | |
1009 * Don't ignore it for the input() function. | |
1010 */ | |
1011 if ((c == Ctrl_C | |
1012 #ifdef UNIX | |
1013 || c == intr_char | |
1014 #endif | |
1015 ) | |
1016 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1017 && firstc != '@' | |
1018 #endif | |
1019 #ifdef FEAT_EVAL | |
1020 && !break_ctrl_c | |
1021 #endif | |
1022 && !global_busy) | |
1023 got_int = FALSE; | |
1024 | |
1025 #ifdef FEAT_CMDHIST | |
1026 /* free old command line when finished moving around in the history | |
1027 * list */ | |
1028 if (lookfor != NULL | |
180 | 1029 && c != K_S_DOWN && c != K_S_UP |
230 | 1030 && c != K_DOWN && c != K_UP |
7 | 1031 && c != K_PAGEDOWN && c != K_PAGEUP |
1032 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1033 && c != K_LEFT && c != K_RIGHT |
7 | 1034 && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1035 VIM_CLEAR(lookfor); |
7 | 1036 #endif |
1037 | |
1038 /* | |
1718 | 1039 * When there are matching completions to select <S-Tab> works like |
1040 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1041 */ |
1718 | 1042 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1043 c = Ctrl_P; |
1044 | |
1045 #ifdef FEAT_WILDMENU | |
1046 /* Special translations for 'wildmenu' */ | |
1047 if (did_wild_list && p_wmnu) | |
1048 { | |
230 | 1049 if (c == K_LEFT) |
7 | 1050 c = Ctrl_P; |
230 | 1051 else if (c == K_RIGHT) |
7 | 1052 c = Ctrl_N; |
1053 } | |
1054 /* Hitting CR after "emenu Name.": complete submenu */ | |
1055 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1056 && ccline.cmdpos > 1 | |
1057 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1058 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1059 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1060 c = K_DOWN; | |
1061 #endif | |
1062 | |
1063 /* free expanded names when finished walking through matches */ | |
1064 if (xpc.xp_numfiles != -1 | |
1065 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1066 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1067 && c != Ctrl_L) | |
1068 { | |
1069 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1070 did_wild_list = FALSE; | |
1071 #ifdef FEAT_WILDMENU | |
230 | 1072 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1073 #endif |
1074 xpc.xp_context = EXPAND_NOTHING; | |
1075 wim_index = 0; | |
1076 #ifdef FEAT_WILDMENU | |
1077 if (p_wmnu && wild_menu_showing != 0) | |
1078 { | |
1079 int skt = KeyTyped; | |
532 | 1080 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1081 |
1082 if (ccline.input_fn) | |
1083 RedrawingDisabled = 0; | |
7 | 1084 |
1085 if (wild_menu_showing == WM_SCROLLED) | |
1086 { | |
1087 /* Entered command line, move it up */ | |
1088 cmdline_row--; | |
1089 redrawcmd(); | |
1090 } | |
1091 else if (save_p_ls != -1) | |
1092 { | |
1093 /* restore 'laststatus' and 'winminheight' */ | |
1094 p_ls = save_p_ls; | |
1095 p_wmh = save_p_wmh; | |
1096 last_status(FALSE); | |
195 | 1097 save_cmdline(&save_ccline); |
7 | 1098 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1099 restore_cmdline(&save_ccline); |
7 | 1100 redrawcmd(); |
1101 save_p_ls = -1; | |
1102 } | |
1103 else | |
1104 { | |
1105 win_redraw_last_status(topframe); | |
1106 redraw_statuslines(); | |
1107 } | |
532 | 1108 KeyTyped = skt; |
1109 wild_menu_showing = 0; | |
531 | 1110 if (ccline.input_fn) |
1111 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1112 } |
1113 #endif | |
1114 } | |
1115 | |
1116 #ifdef FEAT_WILDMENU | |
1117 /* Special translations for 'wildmenu' */ | |
1118 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1119 { | |
1120 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1121 if (c == K_DOWN && ccline.cmdpos > 0 |
1122 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1123 c = p_wc; |
230 | 1124 else if (c == K_UP) |
7 | 1125 { |
1126 /* Hitting <Up>: Remove one submenu name in front of the | |
1127 * cursor */ | |
1128 int found = FALSE; | |
1129 | |
1130 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1131 i = 0; | |
1132 while (--j > 0) | |
1133 { | |
1134 /* check for start of menu name */ | |
1135 if (ccline.cmdbuff[j] == ' ' | |
1136 && ccline.cmdbuff[j - 1] != '\\') | |
1137 { | |
1138 i = j + 1; | |
1139 break; | |
1140 } | |
1141 /* check for start of submenu name */ | |
1142 if (ccline.cmdbuff[j] == '.' | |
1143 && ccline.cmdbuff[j - 1] != '\\') | |
1144 { | |
1145 if (found) | |
1146 { | |
1147 i = j + 1; | |
1148 break; | |
1149 } | |
1150 else | |
1151 found = TRUE; | |
1152 } | |
1153 } | |
1154 if (i > 0) | |
1155 cmdline_del(i); | |
1156 c = p_wc; | |
1157 xpc.xp_context = EXPAND_NOTHING; | |
1158 } | |
1159 } | |
714 | 1160 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1161 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1162 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1163 { |
1164 char_u upseg[5]; | |
1165 | |
1166 upseg[0] = PATHSEP; | |
1167 upseg[1] = '.'; | |
1168 upseg[2] = '.'; | |
1169 upseg[3] = PATHSEP; | |
1170 upseg[4] = NUL; | |
1171 | |
1318 | 1172 if (c == K_DOWN |
1173 && ccline.cmdpos > 0 | |
1174 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1175 && (ccline.cmdpos < 3 | |
1176 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1177 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1178 { | |
1179 /* go down a directory */ | |
1180 c = p_wc; | |
1181 } | |
230 | 1182 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1183 { |
1184 /* If in a direct ancestor, strip off one ../ to go down */ | |
1185 int found = FALSE; | |
1186 | |
1187 j = ccline.cmdpos; | |
1188 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1189 while (--j > i) | |
1190 { | |
39 | 1191 #ifdef FEAT_MBYTE |
1192 if (has_mbyte) | |
1193 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1194 #endif | |
7 | 1195 if (vim_ispathsep(ccline.cmdbuff[j])) |
1196 { | |
1197 found = TRUE; | |
1198 break; | |
1199 } | |
1200 } | |
1201 if (found | |
1202 && ccline.cmdbuff[j - 1] == '.' | |
1203 && ccline.cmdbuff[j - 2] == '.' | |
1204 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1205 { | |
1206 cmdline_del(j - 2); | |
1207 c = p_wc; | |
1208 } | |
1209 } | |
230 | 1210 else if (c == K_UP) |
7 | 1211 { |
1212 /* go up a directory */ | |
1213 int found = FALSE; | |
1214 | |
1215 j = ccline.cmdpos - 1; | |
1216 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1217 while (--j > i) | |
1218 { | |
1219 #ifdef FEAT_MBYTE | |
1220 if (has_mbyte) | |
1221 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1222 #endif | |
1223 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1224 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1225 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1226 ccline.cmdbuff[j + 1]) == NULL |
7 | 1227 #endif |
1228 ) | |
1229 { | |
1230 if (found) | |
1231 { | |
1232 i = j + 1; | |
1233 break; | |
1234 } | |
1235 else | |
1236 found = TRUE; | |
1237 } | |
1238 } | |
1239 | |
1240 if (!found) | |
1241 j = i; | |
1242 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1243 j += 4; | |
1244 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1245 && j == i) | |
1246 j += 3; | |
1247 else | |
1248 j = 0; | |
1249 if (j > 0) | |
1250 { | |
1251 /* TODO this is only for DOS/UNIX systems - need to put in | |
1252 * machine-specific stuff here and in upseg init */ | |
1253 cmdline_del(j); | |
1254 put_on_cmdline(upseg + 1, 3, FALSE); | |
1255 } | |
1256 else if (ccline.cmdpos > i) | |
1257 cmdline_del(i); | |
3204 | 1258 |
1259 /* Now complete in the new directory. Set KeyTyped in case the | |
1260 * Up key came from a mapping. */ | |
7 | 1261 c = p_wc; |
3204 | 1262 KeyTyped = TRUE; |
7 | 1263 } |
1264 } | |
1265 | |
1266 #endif /* FEAT_WILDMENU */ | |
1267 | |
1268 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1269 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1270 if (c == Ctrl_BSL) | |
1271 { | |
1272 ++no_mapping; | |
1273 ++allow_keys; | |
1389 | 1274 c = plain_vgetc(); |
7 | 1275 --no_mapping; |
1276 --allow_keys; | |
3859 | 1277 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1278 * is in a mapping. */ | |
1279 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1280 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1281 { |
1282 vungetc(c); | |
1283 c = Ctrl_BSL; | |
1284 } | |
1285 #ifdef FEAT_EVAL | |
1286 else if (c == 'e') | |
1287 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1288 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1289 int len; |
7 | 1290 |
1291 /* | |
1292 * Replace the command line with the result of an expression. | |
625 | 1293 * Need to save and restore the current command line, to be |
1294 * able to enter a new one... | |
7 | 1295 */ |
1296 if (ccline.cmdpos == ccline.cmdlen) | |
1297 new_cmdpos = 99999; /* keep it at the end */ | |
1298 else | |
1299 new_cmdpos = ccline.cmdpos; | |
95 | 1300 |
1301 save_cmdline(&save_ccline); | |
7 | 1302 c = get_expr_register(); |
95 | 1303 restore_cmdline(&save_ccline); |
7 | 1304 if (c == '=') |
1305 { | |
634 | 1306 /* Need to save and restore ccline. And set "textlock" |
632 | 1307 * to avoid nasty things like going to another buffer when |
1308 * evaluating an expression. */ | |
95 | 1309 save_cmdline(&save_ccline); |
634 | 1310 ++textlock; |
7 | 1311 p = get_expr_line(); |
634 | 1312 --textlock; |
95 | 1313 restore_cmdline(&save_ccline); |
2617 | 1314 |
1315 if (p != NULL) | |
7 | 1316 { |
2617 | 1317 len = (int)STRLEN(p); |
1318 if (realloc_cmdbuff(len + 1) == OK) | |
1319 { | |
1320 ccline.cmdlen = len; | |
1321 STRCPY(ccline.cmdbuff, p); | |
1322 vim_free(p); | |
1323 | |
1324 /* Restore the cursor or use the position set with | |
1325 * set_cmdline_pos(). */ | |
1326 if (new_cmdpos > ccline.cmdlen) | |
1327 ccline.cmdpos = ccline.cmdlen; | |
1328 else | |
1329 ccline.cmdpos = new_cmdpos; | |
1330 | |
1331 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1332 redrawcmd(); | |
1333 goto cmdline_changed; | |
1334 } | |
7 | 1335 } |
1336 } | |
1337 beep_flush(); | |
2636 | 1338 got_int = FALSE; /* don't abandon the command line */ |
1339 did_emsg = FALSE; | |
1340 emsg_on_display = FALSE; | |
1341 redrawcmd(); | |
1342 goto cmdline_not_changed; | |
7 | 1343 } |
1344 #endif | |
1345 else | |
1346 { | |
1347 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1348 restart_edit = 'a'; | |
1349 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1350 in history */ | |
1351 goto returncmd; /* back to Normal mode */ | |
1352 } | |
1353 } | |
1354 | |
1355 #ifdef FEAT_CMDWIN | |
1356 if (c == cedit_key || c == K_CMDWIN) | |
1357 { | |
6211 | 1358 if (ex_normal_busy == 0 && got_int == FALSE) |
1359 { | |
1360 /* | |
1361 * Open a window to edit the command line (and history). | |
1362 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1363 c = open_cmdwin(); |
6211 | 1364 some_key_typed = TRUE; |
1365 } | |
7 | 1366 } |
1367 # ifdef FEAT_DIGRAPHS | |
1368 else | |
1369 # endif | |
1370 #endif | |
1371 #ifdef FEAT_DIGRAPHS | |
1372 c = do_digraph(c); | |
1373 #endif | |
1374 | |
1375 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1376 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1377 { | |
168 | 1378 /* In Ex mode a backslash escapes a newline. */ |
1379 if (exmode_active | |
1380 && c != ESC | |
1318 | 1381 && ccline.cmdpos == ccline.cmdlen |
168 | 1382 && ccline.cmdpos > 0 |
1383 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1384 { | |
1385 if (c == K_KENTER) | |
1386 c = '\n'; | |
1387 } | |
1388 else | |
7 | 1389 { |
168 | 1390 gotesc = FALSE; /* Might have typed ESC previously, don't |
1391 truncate the cmdline now. */ | |
1392 if (ccheck_abbr(c + ABBR_OFF)) | |
1393 goto cmdline_changed; | |
1394 if (!cmd_silent) | |
1395 { | |
1396 windgoto(msg_row, 0); | |
1397 out_flush(); | |
1398 } | |
1399 break; | |
7 | 1400 } |
1401 } | |
1402 | |
1403 /* | |
1404 * Completion for 'wildchar' or 'wildcharm' key. | |
1405 * - hitting <ESC> twice means: abandon command line. | |
1406 * - wildcard expansion is only done when the 'wildchar' key is really | |
1407 * typed, not when it comes from a macro | |
1408 */ | |
1409 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1410 { | |
1411 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1412 { | |
1413 /* if 'wildmode' contains "list" may still need to list */ | |
1414 if (xpc.xp_numfiles > 1 | |
1415 && !did_wild_list | |
1416 && (wim_flags[wim_index] & WIM_LIST)) | |
1417 { | |
1418 (void)showmatches(&xpc, FALSE); | |
1419 redrawcmd(); | |
1420 did_wild_list = TRUE; | |
1421 } | |
1422 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1423 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1424 firstc != '@'); | |
7 | 1425 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1426 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1427 firstc != '@'); | |
7 | 1428 else |
1429 res = OK; /* don't insert 'wildchar' now */ | |
1430 } | |
1431 else /* typed p_wc first time */ | |
1432 { | |
1433 wim_index = 0; | |
1434 j = ccline.cmdpos; | |
1435 /* if 'wildmode' first contains "longest", get longest | |
1436 * common part */ | |
1437 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1438 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1439 firstc != '@'); | |
7 | 1440 else |
3961 | 1441 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1442 firstc != '@'); | |
7 | 1443 |
1444 /* if interrupted while completing, behave like it failed */ | |
1445 if (got_int) | |
1446 { | |
1447 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1448 got_int = FALSE; /* don't abandon the command line */ | |
1449 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1450 #ifdef FEAT_WILDMENU | |
1451 xpc.xp_context = EXPAND_NOTHING; | |
1452 #endif | |
1453 goto cmdline_changed; | |
1454 } | |
1455 | |
1456 /* when more than one match, and 'wildmode' first contains | |
1457 * "list", or no change and 'wildmode' contains "longest,list", | |
1458 * list all matches */ | |
1459 if (res == OK && xpc.xp_numfiles > 1) | |
1460 { | |
1461 /* a "longest" that didn't do anything is skipped (but not | |
1462 * "list:longest") */ | |
1463 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1464 wim_index = 1; | |
1465 if ((wim_flags[wim_index] & WIM_LIST) | |
1466 #ifdef FEAT_WILDMENU | |
1467 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1468 #endif | |
1469 ) | |
1470 { | |
1471 if (!(wim_flags[0] & WIM_LONGEST)) | |
1472 { | |
1473 #ifdef FEAT_WILDMENU | |
1474 int p_wmnu_save = p_wmnu; | |
1475 p_wmnu = 0; | |
1476 #endif | |
3961 | 1477 /* remove match */ |
1478 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1479 #ifdef FEAT_WILDMENU |
1480 p_wmnu = p_wmnu_save; | |
1481 #endif | |
1482 } | |
1483 #ifdef FEAT_WILDMENU | |
1484 (void)showmatches(&xpc, p_wmnu | |
1485 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1486 #else | |
1487 (void)showmatches(&xpc, FALSE); | |
1488 #endif | |
1489 redrawcmd(); | |
1490 did_wild_list = TRUE; | |
1491 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1492 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1493 firstc != '@'); | |
7 | 1494 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1495 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1496 firstc != '@'); | |
7 | 1497 } |
1498 else | |
6949 | 1499 vim_beep(BO_WILD); |
7 | 1500 } |
1501 #ifdef FEAT_WILDMENU | |
1502 else if (xpc.xp_numfiles == -1) | |
1503 xpc.xp_context = EXPAND_NOTHING; | |
1504 #endif | |
1505 } | |
1506 if (wim_index < 3) | |
1507 ++wim_index; | |
1508 if (c == ESC) | |
1509 gotesc = TRUE; | |
1510 if (res == OK) | |
1511 goto cmdline_changed; | |
1512 } | |
1513 | |
1514 gotesc = FALSE; | |
1515 | |
1516 /* <S-Tab> goes to last match, in a clumsy way */ | |
1517 if (c == K_S_TAB && KeyTyped) | |
1518 { | |
3961 | 1519 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1520 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1521 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1522 goto cmdline_changed; |
1523 } | |
1524 | |
1525 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1526 c = NL; | |
1527 | |
1528 do_abbr = TRUE; /* default: check for abbreviation */ | |
1529 | |
1530 /* | |
1531 * Big switch for a typed command line character. | |
1532 */ | |
1533 switch (c) | |
1534 { | |
1535 case K_BS: | |
1536 case Ctrl_H: | |
1537 case K_DEL: | |
1538 case K_KDEL: | |
1539 case Ctrl_W: | |
1540 #ifdef FEAT_FKMAP | |
1541 if (cmd_fkmap && c == K_BS) | |
1542 c = K_DEL; | |
1543 #endif | |
1544 if (c == K_KDEL) | |
1545 c = K_DEL; | |
1546 | |
1547 /* | |
1548 * delete current character is the same as backspace on next | |
1549 * character, except at end of line | |
1550 */ | |
1551 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1552 ++ccline.cmdpos; | |
1553 #ifdef FEAT_MBYTE | |
1554 if (has_mbyte && c == K_DEL) | |
1555 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1556 ccline.cmdbuff + ccline.cmdpos); | |
1557 #endif | |
1558 if (ccline.cmdpos > 0) | |
1559 { | |
1560 char_u *p; | |
1561 | |
1562 j = ccline.cmdpos; | |
1563 p = ccline.cmdbuff + j; | |
1564 #ifdef FEAT_MBYTE | |
1565 if (has_mbyte) | |
1566 { | |
1567 p = mb_prevptr(ccline.cmdbuff, p); | |
1568 if (c == Ctrl_W) | |
1569 { | |
1570 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1571 p = mb_prevptr(ccline.cmdbuff, p); | |
1572 i = mb_get_class(p); | |
1573 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1574 p = mb_prevptr(ccline.cmdbuff, p); | |
1575 if (mb_get_class(p) != i) | |
474 | 1576 p += (*mb_ptr2len)(p); |
7 | 1577 } |
1578 } | |
1579 else | |
1580 #endif | |
1581 if (c == Ctrl_W) | |
1582 { | |
1583 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1584 --p; | |
1585 i = vim_iswordc(p[-1]); | |
1586 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1587 && vim_iswordc(p[-1]) == i) | |
1588 --p; | |
1589 } | |
1590 else | |
1591 --p; | |
1592 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1593 ccline.cmdlen -= j - ccline.cmdpos; | |
1594 i = ccline.cmdpos; | |
1595 while (i < ccline.cmdlen) | |
1596 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1597 | |
1598 /* Truncate at the end, required for multi-byte chars. */ | |
1599 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1600 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1601 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1602 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1603 is_state.search_start = is_state.save_cursor; |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1604 /* 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
|
1605 * won't be restored at the wrong position */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1606 is_state.old_viewstate = is_state.init_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1607 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1608 #endif |
7 | 1609 redrawcmd(); |
1610 } | |
1611 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1612 && ccline.cmdprompt == NULL && indent == 0) | |
1613 { | |
1614 /* In ex and debug mode it doesn't make sense to return. */ | |
1615 if (exmode_active | |
1616 #ifdef FEAT_EVAL | |
1617 || ccline.cmdfirstc == '>' | |
1618 #endif | |
1619 ) | |
1620 goto cmdline_not_changed; | |
1621 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1622 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1623 if (!cmd_silent) |
1624 { | |
1625 #ifdef FEAT_RIGHTLEFT | |
1626 if (cmdmsg_rl) | |
1627 msg_col = Columns; | |
1628 else | |
1629 #endif | |
1630 msg_col = 0; | |
1631 msg_putchar(' '); /* delete ':' */ | |
1632 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1633 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1634 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1635 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1636 #endif |
7 | 1637 redraw_cmdline = TRUE; |
1638 goto returncmd; /* back to cmd mode */ | |
1639 } | |
1640 goto cmdline_changed; | |
1641 | |
1642 case K_INS: | |
1643 case K_KINS: | |
1644 #ifdef FEAT_FKMAP | |
1645 /* if Farsi mode set, we are in reverse insert mode - | |
1646 Do not change the mode */ | |
1647 if (cmd_fkmap) | |
1648 beep_flush(); | |
1649 else | |
1650 #endif | |
1651 ccline.overstrike = !ccline.overstrike; | |
1652 #ifdef CURSOR_SHAPE | |
1653 ui_cursor_shape(); /* may show different cursor shape */ | |
1654 #endif | |
1655 goto cmdline_not_changed; | |
1656 | |
1657 case Ctrl_HAT: | |
782 | 1658 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1659 { |
1660 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1661 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1662 #ifdef HAVE_INPUT_METHOD |
7 | 1663 im_set_active(FALSE); /* Disable input method */ |
1664 #endif | |
1665 if (b_im_ptr != NULL) | |
1666 { | |
1667 if (State & LANGMAP) | |
1668 *b_im_ptr = B_IMODE_LMAP; | |
1669 else | |
1670 *b_im_ptr = B_IMODE_NONE; | |
1671 } | |
1672 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1673 #ifdef HAVE_INPUT_METHOD |
7 | 1674 else |
1675 { | |
1676 /* There are no ":lmap" mappings, toggle IM. When | |
1677 * 'imdisable' is set don't try getting the status, it's | |
1678 * always off. */ | |
1679 if ((p_imdisable && b_im_ptr != NULL) | |
1680 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1681 { | |
1682 im_set_active(FALSE); /* Disable input method */ | |
1683 if (b_im_ptr != NULL) | |
1684 *b_im_ptr = B_IMODE_NONE; | |
1685 } | |
1686 else | |
1687 { | |
1688 im_set_active(TRUE); /* Enable input method */ | |
1689 if (b_im_ptr != NULL) | |
1690 *b_im_ptr = B_IMODE_IM; | |
1691 } | |
1692 } | |
1693 #endif | |
1694 if (b_im_ptr != NULL) | |
1695 { | |
1696 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1697 set_iminsert_global(); | |
1698 else | |
1699 set_imsearch_global(); | |
1700 } | |
1701 #ifdef CURSOR_SHAPE | |
1702 ui_cursor_shape(); /* may show different cursor shape */ | |
1703 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1704 #if defined(FEAT_KEYMAP) |
7 | 1705 /* Show/unshow value of 'keymap' in status lines later. */ |
1706 status_redraw_curbuf(); | |
1707 #endif | |
1708 goto cmdline_not_changed; | |
1709 | |
1710 /* case '@': only in very old vi */ | |
1711 case Ctrl_U: | |
1712 /* delete all characters left of the cursor */ | |
1713 j = ccline.cmdpos; | |
1714 ccline.cmdlen -= j; | |
1715 i = ccline.cmdpos = 0; | |
1716 while (i < ccline.cmdlen) | |
1717 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1718 /* Truncate at the end, required for multi-byte chars. */ | |
1719 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1720 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1721 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1722 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1723 #endif |
7 | 1724 redrawcmd(); |
1725 goto cmdline_changed; | |
1726 | |
1727 #ifdef FEAT_CLIPBOARD | |
1728 case Ctrl_Y: | |
1729 /* Copy the modeless selection, if there is one. */ | |
1730 if (clip_star.state != SELECT_CLEARED) | |
1731 { | |
1732 if (clip_star.state == SELECT_DONE) | |
1733 clip_copy_modeless_selection(TRUE); | |
1734 goto cmdline_not_changed; | |
1735 } | |
1736 break; | |
1737 #endif | |
1738 | |
1739 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1740 case Ctrl_C: | |
571 | 1741 /* In exmode it doesn't make sense to return. Except when |
161 | 1742 * ":normal" runs out of characters. */ |
1743 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1744 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1745 goto cmdline_not_changed; |
1746 | |
1747 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1748 putting it in history */ | |
1749 goto returncmd; /* back to cmd mode */ | |
1750 | |
1751 case Ctrl_R: /* insert register */ | |
1752 #ifdef USE_ON_FLY_SCROLL | |
1753 dont_scroll = TRUE; /* disallow scrolling here */ | |
1754 #endif | |
1755 putcmdline('"', TRUE); | |
1756 ++no_mapping; | |
1389 | 1757 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1758 if (i == Ctrl_O) |
1759 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1760 if (i == Ctrl_R) | |
1389 | 1761 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
|
1762 extra_char = NUL; |
7 | 1763 --no_mapping; |
1764 #ifdef FEAT_EVAL | |
1765 /* | |
1766 * Insert the result of an expression. | |
1767 * Need to save the current command line, to be able to enter | |
1768 * a new one... | |
1769 */ | |
1770 new_cmdpos = -1; | |
1771 if (c == '=') | |
1772 { | |
1773 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1774 { | |
1775 beep_flush(); | |
1776 c = ESC; | |
1777 } | |
1778 else | |
1779 { | |
95 | 1780 save_cmdline(&save_ccline); |
7 | 1781 c = get_expr_register(); |
95 | 1782 restore_cmdline(&save_ccline); |
7 | 1783 } |
1784 } | |
1785 #endif | |
1786 if (c != ESC) /* use ESC to cancel inserting register */ | |
1787 { | |
1015 | 1788 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1789 |
613 | 1790 #ifdef FEAT_EVAL |
606 | 1791 /* When there was a serious error abort getting the |
1792 * command line. */ | |
1793 if (aborting()) | |
1794 { | |
1795 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1796 putting it in history */ | |
1797 goto returncmd; /* back to cmd mode */ | |
1798 } | |
613 | 1799 #endif |
7 | 1800 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1801 #ifdef FEAT_EVAL | |
1802 if (new_cmdpos >= 0) | |
1803 { | |
1804 /* set_cmdline_pos() was used */ | |
1805 if (new_cmdpos > ccline.cmdlen) | |
1806 ccline.cmdpos = ccline.cmdlen; | |
1807 else | |
1808 ccline.cmdpos = new_cmdpos; | |
1809 } | |
1810 #endif | |
1811 } | |
1812 redrawcmd(); | |
1813 goto cmdline_changed; | |
1814 | |
1815 case Ctrl_D: | |
1816 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1817 break; /* Use ^D as normal char instead */ | |
1818 | |
1819 redrawcmd(); | |
1820 continue; /* don't do incremental search now */ | |
1821 | |
1822 case K_RIGHT: | |
1823 case K_S_RIGHT: | |
1824 case K_C_RIGHT: | |
1825 do | |
1826 { | |
1827 if (ccline.cmdpos >= ccline.cmdlen) | |
1828 break; | |
1829 i = cmdline_charsize(ccline.cmdpos); | |
1830 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1831 break; | |
1832 ccline.cmdspos += i; | |
1833 #ifdef FEAT_MBYTE | |
1834 if (has_mbyte) | |
474 | 1835 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1836 + ccline.cmdpos); |
1837 else | |
1838 #endif | |
1839 ++ccline.cmdpos; | |
1840 } | |
180 | 1841 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1842 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1843 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1844 #ifdef FEAT_MBYTE | |
1845 if (has_mbyte) | |
1846 set_cmdspos_cursor(); | |
1847 #endif | |
1848 goto cmdline_not_changed; | |
1849 | |
1850 case K_LEFT: | |
1851 case K_S_LEFT: | |
1852 case K_C_LEFT: | |
1456 | 1853 if (ccline.cmdpos == 0) |
1854 goto cmdline_not_changed; | |
7 | 1855 do |
1856 { | |
1857 --ccline.cmdpos; | |
1858 #ifdef FEAT_MBYTE | |
1859 if (has_mbyte) /* move to first byte of char */ | |
1860 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1861 ccline.cmdbuff + ccline.cmdpos); | |
1862 #endif | |
1863 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1864 } | |
1456 | 1865 while (ccline.cmdpos > 0 |
1866 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1867 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1868 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1869 #ifdef FEAT_MBYTE | |
1870 if (has_mbyte) | |
1871 set_cmdspos_cursor(); | |
1872 #endif | |
1873 goto cmdline_not_changed; | |
1874 | |
1875 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
|
1876 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1877 goto cmdline_not_changed; |
7 | 1878 |
625 | 1879 #ifdef FEAT_GUI_W32 |
1880 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1881 * cancelled. */ | |
1882 case K_F4: | |
1883 if (mod_mask == MOD_MASK_ALT) | |
1884 { | |
1885 redrawcmd(); /* somehow the cmdline is cleared */ | |
1886 goto cmdline_not_changed; | |
1887 } | |
1888 break; | |
1889 #endif | |
1890 | |
7 | 1891 #ifdef FEAT_MOUSE |
1892 case K_MIDDLEDRAG: | |
1893 case K_MIDDLERELEASE: | |
1894 goto cmdline_not_changed; /* Ignore mouse */ | |
1895 | |
1896 case K_MIDDLEMOUSE: | |
1897 # ifdef FEAT_GUI | |
1898 /* When GUI is active, also paste when 'mouse' is empty */ | |
1899 if (!gui.in_use) | |
1900 # endif | |
1901 if (!mouse_has(MOUSE_COMMAND)) | |
1902 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1903 # ifdef FEAT_CLIPBOARD |
7 | 1904 if (clip_star.available) |
1015 | 1905 cmdline_paste('*', TRUE, TRUE); |
7 | 1906 else |
692 | 1907 # endif |
1015 | 1908 cmdline_paste(0, TRUE, TRUE); |
7 | 1909 redrawcmd(); |
1910 goto cmdline_changed; | |
1911 | |
692 | 1912 # ifdef FEAT_DND |
7 | 1913 case K_DROP: |
1015 | 1914 cmdline_paste('~', TRUE, FALSE); |
7 | 1915 redrawcmd(); |
1916 goto cmdline_changed; | |
692 | 1917 # endif |
7 | 1918 |
1919 case K_LEFTDRAG: | |
1920 case K_LEFTRELEASE: | |
1921 case K_RIGHTDRAG: | |
1922 case K_RIGHTRELEASE: | |
1923 /* Ignore drag and release events when the button-down wasn't | |
1924 * seen before. */ | |
1925 if (ignore_drag_release) | |
1926 goto cmdline_not_changed; | |
1927 /* FALLTHROUGH */ | |
1928 case K_LEFTMOUSE: | |
1929 case K_RIGHTMOUSE: | |
1930 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1931 ignore_drag_release = TRUE; | |
1932 else | |
1933 ignore_drag_release = FALSE; | |
1934 # ifdef FEAT_GUI | |
1935 /* When GUI is active, also move when 'mouse' is empty */ | |
1936 if (!gui.in_use) | |
1937 # endif | |
1938 if (!mouse_has(MOUSE_COMMAND)) | |
1939 goto cmdline_not_changed; /* Ignore mouse */ | |
1940 # ifdef FEAT_CLIPBOARD | |
1941 if (mouse_row < cmdline_row && clip_star.available) | |
1942 { | |
1943 int button, is_click, is_drag; | |
1944 | |
1945 /* | |
1946 * Handle modeless selection. | |
1947 */ | |
1948 button = get_mouse_button(KEY2TERMCAP1(c), | |
1949 &is_click, &is_drag); | |
1950 if (mouse_model_popup() && button == MOUSE_LEFT | |
1951 && (mod_mask & MOD_MASK_SHIFT)) | |
1952 { | |
1953 /* Translate shift-left to right button. */ | |
1954 button = MOUSE_RIGHT; | |
1955 mod_mask &= ~MOD_MASK_SHIFT; | |
1956 } | |
1957 clip_modeless(button, is_click, is_drag); | |
1958 goto cmdline_not_changed; | |
1959 } | |
1960 # endif | |
1961 | |
1962 set_cmdspos(); | |
1963 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1964 ++ccline.cmdpos) | |
1965 { | |
1966 i = cmdline_charsize(ccline.cmdpos); | |
1967 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1968 && mouse_col < ccline.cmdspos % Columns + i) | |
1969 break; | |
692 | 1970 # ifdef FEAT_MBYTE |
7 | 1971 if (has_mbyte) |
1972 { | |
1973 /* Count ">" for double-wide char that doesn't fit. */ | |
1974 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1975 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1976 + ccline.cmdpos) - 1; |
1977 } | |
692 | 1978 # endif |
7 | 1979 ccline.cmdspos += i; |
1980 } | |
1981 goto cmdline_not_changed; | |
1982 | |
1983 /* Mouse scroll wheel: ignored here */ | |
1984 case K_MOUSEDOWN: | |
1985 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1986 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1987 case K_MOUSERIGHT: |
7 | 1988 /* Alternate buttons ignored here */ |
1989 case K_X1MOUSE: | |
1990 case K_X1DRAG: | |
1991 case K_X1RELEASE: | |
1992 case K_X2MOUSE: | |
1993 case K_X2DRAG: | |
1994 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1995 case K_MOUSEMOVE: |
7 | 1996 goto cmdline_not_changed; |
1997 | |
1998 #endif /* FEAT_MOUSE */ | |
1999 | |
2000 #ifdef FEAT_GUI | |
2001 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2002 case K_LEFTRELEASE_NM: | |
2003 goto cmdline_not_changed; | |
2004 | |
2005 case K_VER_SCROLLBAR: | |
540 | 2006 if (msg_scrolled == 0) |
7 | 2007 { |
2008 gui_do_scroll(); | |
2009 redrawcmd(); | |
2010 } | |
2011 goto cmdline_not_changed; | |
2012 | |
2013 case K_HOR_SCROLLBAR: | |
540 | 2014 if (msg_scrolled == 0) |
7 | 2015 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2016 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2017 redrawcmd(); |
2018 } | |
2019 goto cmdline_not_changed; | |
2020 #endif | |
692 | 2021 #ifdef FEAT_GUI_TABLINE |
2022 case K_TABLINE: | |
2023 case K_TABMENU: | |
2024 /* Don't want to change any tabs here. Make sure the same tab | |
2025 * is still selected. */ | |
2026 if (gui_use_tabline()) | |
2027 gui_mch_set_curtab(tabpage_index(curtab)); | |
2028 goto cmdline_not_changed; | |
2029 #endif | |
2030 | |
7 | 2031 case K_SELECT: /* end of Select mode mapping - ignore */ |
2032 goto cmdline_not_changed; | |
2033 | |
2034 case Ctrl_B: /* begin of command line */ | |
2035 case K_HOME: | |
2036 case K_KHOME: | |
2037 case K_S_HOME: | |
2038 case K_C_HOME: | |
2039 ccline.cmdpos = 0; | |
2040 set_cmdspos(); | |
2041 goto cmdline_not_changed; | |
2042 | |
2043 case Ctrl_E: /* end of command line */ | |
2044 case K_END: | |
2045 case K_KEND: | |
2046 case K_S_END: | |
2047 case K_C_END: | |
2048 ccline.cmdpos = ccline.cmdlen; | |
2049 set_cmdspos_cursor(); | |
2050 goto cmdline_not_changed; | |
2051 | |
2052 case Ctrl_A: /* all matches */ | |
3961 | 2053 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2054 break; |
2055 goto cmdline_changed; | |
2056 | |
772 | 2057 case Ctrl_L: |
2058 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2059 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2060 goto cmdline_not_changed; |
2061 #endif | |
2062 | |
2063 /* completion: longest common part */ | |
3961 | 2064 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2065 break; |
2066 goto cmdline_changed; | |
2067 | |
2068 case Ctrl_N: /* next match */ | |
2069 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2070 if (xpc.xp_numfiles > 0) |
7 | 2071 { |
3961 | 2072 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2073 0, firstc != '@') == FAIL) | |
7 | 2074 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2075 goto cmdline_not_changed; |
7 | 2076 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2077 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2078 /* FALLTHROUGH */ |
7 | 2079 case K_UP: |
2080 case K_DOWN: | |
2081 case K_S_UP: | |
2082 case K_S_DOWN: | |
2083 case K_PAGEUP: | |
2084 case K_KPAGEUP: | |
2085 case K_PAGEDOWN: | |
2086 case K_KPAGEDOWN: | |
2087 if (hislen == 0 || firstc == NUL) /* no history */ | |
2088 goto cmdline_not_changed; | |
2089 | |
2090 i = hiscnt; | |
2091 | |
2092 /* save current command string so it can be restored later */ | |
2093 if (lookfor == NULL) | |
2094 { | |
2095 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2096 goto cmdline_not_changed; | |
2097 lookfor[ccline.cmdpos] = NUL; | |
2098 } | |
2099 | |
2100 j = (int)STRLEN(lookfor); | |
2101 for (;;) | |
2102 { | |
2103 /* one step backwards */ | |
230 | 2104 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2105 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2106 { |
2107 if (hiscnt == hislen) /* first time */ | |
2108 hiscnt = hisidx[histype]; | |
2109 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2110 hiscnt = hislen - 1; | |
2111 else if (hiscnt != hisidx[histype] + 1) | |
2112 --hiscnt; | |
2113 else /* at top of list */ | |
2114 { | |
2115 hiscnt = i; | |
2116 break; | |
2117 } | |
2118 } | |
2119 else /* one step forwards */ | |
2120 { | |
2121 /* on last entry, clear the line */ | |
2122 if (hiscnt == hisidx[histype]) | |
2123 { | |
2124 hiscnt = hislen; | |
2125 break; | |
2126 } | |
2127 | |
2128 /* not on a history line, nothing to do */ | |
2129 if (hiscnt == hislen) | |
2130 break; | |
2131 if (hiscnt == hislen - 1) /* wrap around */ | |
2132 hiscnt = 0; | |
2133 else | |
2134 ++hiscnt; | |
2135 } | |
2136 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2137 { | |
2138 hiscnt = i; | |
2139 break; | |
2140 } | |
230 | 2141 if ((c != K_UP && c != K_DOWN) |
180 | 2142 || hiscnt == i |
7 | 2143 || STRNCMP(history[histype][hiscnt].hisstr, |
2144 lookfor, (size_t)j) == 0) | |
2145 break; | |
2146 } | |
2147 | |
2148 if (hiscnt != i) /* jumped to other entry */ | |
2149 { | |
2150 char_u *p; | |
2151 int len; | |
2152 int old_firstc; | |
2153 | |
2154 vim_free(ccline.cmdbuff); | |
1718 | 2155 xpc.xp_context = EXPAND_NOTHING; |
7 | 2156 if (hiscnt == hislen) |
2157 p = lookfor; /* back to the old one */ | |
2158 else | |
2159 p = history[histype][hiscnt].hisstr; | |
2160 | |
2161 if (histype == HIST_SEARCH | |
2162 && p != lookfor | |
2163 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2164 { | |
2165 /* Correct for the separator character used when | |
2166 * adding the history entry vs the one used now. | |
2167 * First loop: count length. | |
2168 * Second loop: copy the characters. */ | |
2169 for (i = 0; i <= 1; ++i) | |
2170 { | |
2171 len = 0; | |
2172 for (j = 0; p[j] != NUL; ++j) | |
2173 { | |
2174 /* Replace old sep with new sep, unless it is | |
2175 * escaped. */ | |
2176 if (p[j] == old_firstc | |
2177 && (j == 0 || p[j - 1] != '\\')) | |
2178 { | |
2179 if (i > 0) | |
2180 ccline.cmdbuff[len] = firstc; | |
2181 } | |
2182 else | |
2183 { | |
2184 /* Escape new sep, unless it is already | |
2185 * escaped. */ | |
2186 if (p[j] == firstc | |
2187 && (j == 0 || p[j - 1] != '\\')) | |
2188 { | |
2189 if (i > 0) | |
2190 ccline.cmdbuff[len] = '\\'; | |
2191 ++len; | |
2192 } | |
2193 if (i > 0) | |
2194 ccline.cmdbuff[len] = p[j]; | |
2195 } | |
2196 ++len; | |
2197 } | |
2198 if (i == 0) | |
2199 { | |
2200 alloc_cmdbuff(len); | |
2201 if (ccline.cmdbuff == NULL) | |
2202 goto returncmd; | |
2203 } | |
2204 } | |
2205 ccline.cmdbuff[len] = NUL; | |
2206 } | |
2207 else | |
2208 { | |
2209 alloc_cmdbuff((int)STRLEN(p)); | |
2210 if (ccline.cmdbuff == NULL) | |
2211 goto returncmd; | |
2212 STRCPY(ccline.cmdbuff, p); | |
2213 } | |
2214 | |
2215 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2216 redrawcmd(); | |
2217 goto cmdline_changed; | |
2218 } | |
2219 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2220 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2221 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2222 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2223 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2224 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2225 case Ctrl_T: /* previous match */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2226 if (may_adjust_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2227 firstc, count, &is_state, c) == FAIL) |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2228 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2229 break; |
7 | 2230 #endif |
2231 | |
2232 case Ctrl_V: | |
2233 case Ctrl_Q: | |
2234 #ifdef FEAT_MOUSE | |
2235 ignore_drag_release = TRUE; | |
2236 #endif | |
2237 putcmdline('^', TRUE); | |
2238 c = get_literal(); /* get next (two) character(s) */ | |
2239 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
|
2240 extra_char = NUL; |
7 | 2241 #ifdef FEAT_MBYTE |
2242 /* may need to remove ^ when composing char was typed */ | |
2243 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2244 { | |
2245 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2246 msg_putchar(' '); | |
2247 cursorcmd(); | |
2248 } | |
2249 #endif | |
2250 break; | |
2251 | |
2252 #ifdef FEAT_DIGRAPHS | |
2253 case Ctrl_K: | |
2254 #ifdef FEAT_MOUSE | |
2255 ignore_drag_release = TRUE; | |
2256 #endif | |
2257 putcmdline('?', TRUE); | |
2258 #ifdef USE_ON_FLY_SCROLL | |
2259 dont_scroll = TRUE; /* disallow scrolling here */ | |
2260 #endif | |
2261 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
|
2262 extra_char = NUL; |
7 | 2263 if (c != NUL) |
2264 break; | |
2265 | |
2266 redrawcmd(); | |
2267 goto cmdline_not_changed; | |
2268 #endif /* FEAT_DIGRAPHS */ | |
2269 | |
2270 #ifdef FEAT_RIGHTLEFT | |
2271 case Ctrl__: /* CTRL-_: switch language mode */ | |
2272 if (!p_ari) | |
2273 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2274 # ifdef FEAT_FKMAP |
7 | 2275 if (p_altkeymap) |
2276 { | |
2277 cmd_fkmap = !cmd_fkmap; | |
2278 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2279 ccline.overstrike = FALSE; | |
2280 } | |
2281 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2282 # endif |
7 | 2283 cmd_hkmap = !cmd_hkmap; |
2284 goto cmdline_not_changed; | |
2285 #endif | |
2286 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2287 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
|
2288 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
|
2289 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
|
2290 |
7 | 2291 default: |
2292 #ifdef UNIX | |
2293 if (c == intr_char) | |
2294 { | |
2295 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2296 putting it in history */ | |
2297 goto returncmd; /* back to Normal mode */ | |
2298 } | |
2299 #endif | |
2300 /* | |
2301 * Normal character with no special meaning. Just set mod_mask | |
2302 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2303 * the string <S-Space>. This should only happen after ^V. | |
2304 */ | |
2305 if (!IS_SPECIAL(c)) | |
2306 mod_mask = 0x0; | |
2307 break; | |
2308 } | |
2309 /* | |
2310 * End of switch on command line character. | |
2311 * We come here if we have a normal character. | |
2312 */ | |
2313 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2314 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2315 #ifdef FEAT_MBYTE |
2316 /* Add ABBR_OFF for characters above 0x100, this is | |
2317 * what check_abbr() expects. */ | |
2318 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2319 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2320 c) || c == Ctrl_RSB)) |
7 | 2321 goto cmdline_changed; |
2322 | |
2323 /* | |
2324 * put the character in the command line | |
2325 */ | |
2326 if (IS_SPECIAL(c) || mod_mask != 0) | |
2327 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2328 else | |
2329 { | |
2330 #ifdef FEAT_MBYTE | |
2331 if (has_mbyte) | |
2332 { | |
2333 j = (*mb_char2bytes)(c, IObuff); | |
2334 IObuff[j] = NUL; /* exclude composing chars */ | |
2335 put_on_cmdline(IObuff, j, TRUE); | |
2336 } | |
2337 else | |
2338 #endif | |
2339 { | |
2340 IObuff[0] = c; | |
2341 put_on_cmdline(IObuff, 1, TRUE); | |
2342 } | |
2343 } | |
2344 goto cmdline_changed; | |
2345 | |
2346 /* | |
2347 * This part implements incremental searches for "/" and "?" | |
2348 * Jump to cmdline_not_changed when a character has been read but the command | |
2349 * line did not change. Then we only search and redraw if something changed in | |
2350 * the past. | |
2351 * Jump to cmdline_changed when the command line did change. | |
2352 * (Sorry for the goto's, I know it is ugly). | |
2353 */ | |
2354 cmdline_not_changed: | |
2355 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2356 if (!is_state.incsearch_postponed) |
7 | 2357 continue; |
2358 #endif | |
2359 | |
2360 cmdline_changed: | |
13142
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2361 /* Trigger CmdlineChanged autocommands. */ |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2362 trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2363 |
7 | 2364 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2365 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2366 #endif |
2367 | |
2368 #ifdef FEAT_RIGHTLEFT | |
2369 if (cmdmsg_rl | |
2370 # ifdef FEAT_ARABIC | |
534 | 2371 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2372 # endif |
2373 ) | |
2374 /* Always redraw the whole command line to fix shaping and | |
3374 | 2375 * right-left typing. Not efficient, but it works. |
2376 * Do it only when there are no characters left to read | |
2377 * to avoid useless intermediate redraws. */ | |
2378 if (vpeekc() == NUL) | |
2379 redrawcmd(); | |
7 | 2380 #endif |
2381 } | |
2382 | |
2383 returncmd: | |
2384 | |
2385 #ifdef FEAT_RIGHTLEFT | |
2386 cmdmsg_rl = FALSE; | |
2387 #endif | |
2388 | |
2389 #ifdef FEAT_FKMAP | |
2390 cmd_fkmap = 0; | |
2391 #endif | |
2392 | |
2393 ExpandCleanup(&xpc); | |
1718 | 2394 ccline.xpc = NULL; |
7 | 2395 |
2396 #ifdef FEAT_SEARCH_EXTRA | |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
2397 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2398 #endif |
2399 | |
2400 if (ccline.cmdbuff != NULL) | |
2401 { | |
2402 /* | |
2403 * Put line in history buffer (":" and "=" only when it was typed). | |
2404 */ | |
2405 #ifdef FEAT_CMDHIST | |
2406 if (ccline.cmdlen && firstc != NUL | |
2407 && (some_key_typed || histype == HIST_SEARCH)) | |
2408 { | |
2409 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2410 histype == HIST_SEARCH ? firstc : NUL); | |
2411 if (firstc == ':') | |
2412 { | |
2413 vim_free(new_last_cmdline); | |
2414 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2415 } | |
2416 } | |
2417 #endif | |
2418 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2419 if (gotesc) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2420 abandon_cmdline(); |
7 | 2421 } |
2422 | |
2423 /* | |
2424 * If the screen was shifted up, redraw the whole screen (later). | |
2425 * If the line is too long, clear it, so ruler and shown command do | |
2426 * not get printed in the middle of it. | |
2427 */ | |
2428 msg_check(); | |
2429 msg_scroll = save_msg_scroll; | |
2430 redir_off = FALSE; | |
2431 | |
2432 /* When the command line was typed, no need for a wait-return prompt. */ | |
2433 if (some_key_typed) | |
2434 need_wait_return = FALSE; | |
2435 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2436 /* 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
|
2437 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
|
2438 |
7 | 2439 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2440 #ifdef HAVE_INPUT_METHOD |
7 | 2441 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2442 im_save_status(b_im_ptr); | |
2443 im_set_active(FALSE); | |
2444 #endif | |
2445 #ifdef FEAT_MOUSE | |
2446 setmouse(); | |
2447 #endif | |
2448 #ifdef CURSOR_SHAPE | |
2449 ui_cursor_shape(); /* may show different cursor shape */ | |
2450 #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
|
2451 sb_text_end_cmdline(); |
7 | 2452 |
95 | 2453 { |
2454 char_u *p = ccline.cmdbuff; | |
2455 | |
2456 /* Make ccline empty, getcmdline() may try to use it. */ | |
2457 ccline.cmdbuff = NULL; | |
2458 return p; | |
2459 } | |
7 | 2460 } |
2461 | |
2462 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2463 /* | |
2464 * Get a command line with a prompt. | |
2465 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2466 * f_input() when evaluating an expression from CTRL-R =). | |
2467 * Returns the command line in allocated memory, or NULL. | |
2468 */ | |
2469 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2470 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2471 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2472 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2473 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2474 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2475 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2476 { |
2477 char_u *s; | |
2478 struct cmdline_info save_ccline; | |
2479 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
|
2480 int msg_silent_save = msg_silent; |
7 | 2481 |
95 | 2482 save_cmdline(&save_ccline); |
7 | 2483 ccline.cmdprompt = prompt; |
2484 ccline.cmdattr = attr; | |
531 | 2485 # ifdef FEAT_EVAL |
2486 ccline.xp_context = xp_context; | |
2487 ccline.xp_arg = xp_arg; | |
2488 ccline.input_fn = (firstc == '@'); | |
2489 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2490 msg_silent = 0; |
7 | 2491 s = getcmdline(firstc, 1L, 0); |
95 | 2492 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2493 msg_silent = msg_silent_save; |
3020 | 2494 /* Restore msg_col, the prompt from input() may have changed it. |
2495 * But only if called recursively and the commandline is therefore being | |
2496 * restored to an old one; if not, the input() prompt stays on the screen, | |
2497 * so we need its modified msg_col left intact. */ | |
2498 if (ccline.cmdbuff != NULL) | |
2499 msg_col = msg_col_save; | |
7 | 2500 |
2501 return s; | |
2502 } | |
2503 #endif | |
2504 | |
632 | 2505 /* |
634 | 2506 * Return TRUE when the text must not be changed and we can't switch to |
2507 * another window or buffer. Used when editing the command line, evaluating | |
2508 * 'balloonexpr', etc. | |
632 | 2509 */ |
2510 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2511 text_locked(void) |
632 | 2512 { |
2513 #ifdef FEAT_CMDWIN | |
2514 if (cmdwin_type != 0) | |
2515 return TRUE; | |
2516 #endif | |
634 | 2517 return textlock != 0; |
632 | 2518 } |
2519 | |
2520 /* | |
2521 * Give an error message for a command that isn't allowed while the cmdline | |
2522 * window is open or editing the cmdline in another way. | |
2523 */ | |
2524 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2525 text_locked_msg(void) |
632 | 2526 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2527 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2528 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2529 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2530 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2531 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2532 { |
632 | 2533 #ifdef FEAT_CMDWIN |
2534 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2535 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2536 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2537 return e_secure; |
632 | 2538 } |
2539 | |
819 | 2540 /* |
1834 | 2541 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2542 * and give an error message. | |
819 | 2543 */ |
2544 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2545 curbuf_locked(void) |
819 | 2546 { |
2547 if (curbuf_lock > 0) | |
2548 { | |
2549 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2550 return TRUE; | |
2551 } | |
1834 | 2552 return allbuf_locked(); |
2553 } | |
2554 | |
2555 /* | |
2556 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2557 * message. | |
2558 */ | |
2559 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2560 allbuf_locked(void) |
1834 | 2561 { |
2562 if (allbuf_lock > 0) | |
2563 { | |
2564 EMSG(_("E811: Not allowed to change buffer information now")); | |
2565 return TRUE; | |
2566 } | |
819 | 2567 return FALSE; |
2568 } | |
2569 | |
7 | 2570 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2571 cmdline_charsize(int idx) |
7 | 2572 { |
2573 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2574 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2575 return 1; | |
2576 #endif | |
2577 return ptr2cells(ccline.cmdbuff + idx); | |
2578 } | |
2579 | |
2580 /* | |
2581 * Compute the offset of the cursor on the command line for the prompt and | |
2582 * indent. | |
2583 */ | |
2584 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2585 set_cmdspos(void) |
7 | 2586 { |
531 | 2587 if (ccline.cmdfirstc != NUL) |
7 | 2588 ccline.cmdspos = 1 + ccline.cmdindent; |
2589 else | |
2590 ccline.cmdspos = 0 + ccline.cmdindent; | |
2591 } | |
2592 | |
2593 /* | |
2594 * Compute the screen position for the cursor on the command line. | |
2595 */ | |
2596 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2597 set_cmdspos_cursor(void) |
7 | 2598 { |
2599 int i, m, c; | |
2600 | |
2601 set_cmdspos(); | |
2602 if (KeyTyped) | |
534 | 2603 { |
7 | 2604 m = Columns * Rows; |
534 | 2605 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2606 m = MAXCOL; | |
2607 } | |
7 | 2608 else |
2609 m = MAXCOL; | |
2610 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2611 { | |
2612 c = cmdline_charsize(i); | |
2613 #ifdef FEAT_MBYTE | |
2614 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2615 if (has_mbyte) | |
2616 correct_cmdspos(i, c); | |
2617 #endif | |
1612 | 2618 /* If the cmdline doesn't fit, show cursor on last visible char. |
2619 * Don't move the cursor itself, so we can still append. */ | |
7 | 2620 if ((ccline.cmdspos += c) >= m) |
2621 { | |
2622 ccline.cmdspos -= c; | |
2623 break; | |
2624 } | |
2625 #ifdef FEAT_MBYTE | |
2626 if (has_mbyte) | |
474 | 2627 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2628 #endif |
2629 } | |
2630 } | |
2631 | |
2632 #ifdef FEAT_MBYTE | |
2633 /* | |
2634 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2635 * character that doesn't fit, so that a ">" must be displayed. | |
2636 */ | |
2637 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2638 correct_cmdspos(int idx, int cells) |
7 | 2639 { |
474 | 2640 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2641 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2642 && ccline.cmdspos % Columns + cells > Columns) | |
2643 ccline.cmdspos++; | |
2644 } | |
2645 #endif | |
2646 | |
2647 /* | |
2648 * Get an Ex command line for the ":" command. | |
2649 */ | |
2650 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2651 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2652 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2653 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2654 int indent) /* indent for inside conditionals */ |
7 | 2655 { |
2656 /* When executing a register, remove ':' that's in front of each line. */ | |
2657 if (exec_from_reg && vpeekc() == ':') | |
2658 (void)vgetc(); | |
2659 return getcmdline(c, 1L, indent); | |
2660 } | |
2661 | |
2662 /* | |
2663 * Get an Ex command line for Ex mode. | |
2664 * In Ex mode we only use the OS supplied line editing features and no | |
2665 * mappings or abbreviations. | |
168 | 2666 * Returns a string in allocated memory or NULL. |
7 | 2667 */ |
2668 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2669 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2670 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2671 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2672 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2673 int indent) /* indent for inside conditionals */ |
7 | 2674 { |
168 | 2675 garray_T line_ga; |
2676 char_u *pend; | |
2677 int startcol = 0; | |
1329 | 2678 int c1 = 0; |
168 | 2679 int escaped = FALSE; /* CTRL-V typed */ |
2680 int vcol = 0; | |
2681 char_u *p; | |
1329 | 2682 int prev_char; |
5966 | 2683 int len; |
7 | 2684 |
2685 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2686 * confuses the system function that computes tabstops. */ | |
2687 cursor_on(); | |
2688 | |
2689 /* always start in column 0; write a newline if necessary */ | |
2690 compute_cmdrow(); | |
168 | 2691 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2692 msg_putchar('\n'); |
168 | 2693 if (promptc == ':') |
7 | 2694 { |
164 | 2695 /* indent that is only displayed, not in the line itself */ |
168 | 2696 if (p_prompt) |
2697 msg_putchar(':'); | |
7 | 2698 while (indent-- > 0) |
2699 msg_putchar(' '); | |
2700 startcol = msg_col; | |
2701 } | |
2702 | |
2703 ga_init2(&line_ga, 1, 30); | |
2704 | |
164 | 2705 /* autoindent for :insert and :append is in the line itself */ |
168 | 2706 if (promptc <= 0) |
164 | 2707 { |
2708 vcol = indent; | |
2709 while (indent >= 8) | |
2710 { | |
2711 ga_append(&line_ga, TAB); | |
2712 msg_puts((char_u *)" "); | |
2713 indent -= 8; | |
2714 } | |
2715 while (indent-- > 0) | |
2716 { | |
2717 ga_append(&line_ga, ' '); | |
2718 msg_putchar(' '); | |
2719 } | |
2720 } | |
168 | 2721 ++no_mapping; |
2722 ++allow_keys; | |
164 | 2723 |
7 | 2724 /* |
2725 * Get the line, one character at a time. | |
2726 */ | |
2727 got_int = FALSE; | |
168 | 2728 while (!got_int) |
7 | 2729 { |
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
|
2730 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
|
2731 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
|
2732 |
7 | 2733 if (ga_grow(&line_ga, 40) == FAIL) |
2734 break; | |
2735 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2736 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2737 * 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
|
2738 */ |
1329 | 2739 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
|
2740 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2741 /* 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
|
2742 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
|
2743 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
|
2744 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2745 c1 = vgetc(); |
7 | 2746 |
2747 /* | |
168 | 2748 * Handle line editing. |
2749 * Previously this was left to the system, putting the terminal in | |
2750 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2751 */ |
168 | 2752 if (got_int) |
2753 { | |
2754 msg_putchar('\n'); | |
2755 break; | |
2756 } | |
2757 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2758 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
|
2759 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2760 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
|
2761 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
|
2762 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2763 |
168 | 2764 if (!escaped) |
7 | 2765 { |
168 | 2766 /* CR typed means "enter", which is NL */ |
2767 if (c1 == '\r') | |
2768 c1 = '\n'; | |
2769 | |
2770 if (c1 == BS || c1 == K_BS | |
2771 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2772 { |
168 | 2773 if (line_ga.ga_len > 0) |
2774 { | |
5966 | 2775 #ifdef FEAT_MBYTE |
2776 if (has_mbyte) | |
2777 { | |
2778 p = (char_u *)line_ga.ga_data; | |
2779 p[line_ga.ga_len] = NUL; | |
2780 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2781 line_ga.ga_len -= len; | |
2782 } | |
2783 else | |
2784 #endif | |
2785 --line_ga.ga_len; | |
168 | 2786 goto redraw; |
2787 } | |
2788 continue; | |
7 | 2789 } |
2790 | |
168 | 2791 if (c1 == Ctrl_U) |
7 | 2792 { |
168 | 2793 msg_col = startcol; |
2794 msg_clr_eos(); | |
2795 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
|
2796 goto redraw; |
168 | 2797 } |
2798 | |
2799 if (c1 == Ctrl_T) | |
2800 { | |
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
|
2801 sw = get_sw_value(curbuf); |
168 | 2802 p = (char_u *)line_ga.ga_data; |
2803 p[line_ga.ga_len] = NUL; | |
5995 | 2804 indent = get_indent_str(p, 8, FALSE); |
3740 | 2805 indent += sw - indent % sw; |
168 | 2806 add_indent: |
5995 | 2807 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2808 { |
7009 | 2809 (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
|
2810 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
|
2811 s = skipwhite(p); |
168 | 2812 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2813 *s = ' '; | |
2814 ++line_ga.ga_len; | |
7 | 2815 } |
168 | 2816 redraw: |
2817 /* redraw the line */ | |
2818 msg_col = startcol; | |
2819 vcol = 0; | |
5966 | 2820 p = (char_u *)line_ga.ga_data; |
2821 p[line_ga.ga_len] = NUL; | |
2822 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2823 { |
168 | 2824 if (*p == TAB) |
7 | 2825 { |
168 | 2826 do |
7 | 2827 { |
168 | 2828 msg_putchar(' '); |
2829 } while (++vcol % 8); | |
5966 | 2830 ++p; |
7 | 2831 } |
168 | 2832 else |
164 | 2833 { |
5966 | 2834 len = MB_PTR2LEN(p); |
2835 msg_outtrans_len(p, len); | |
2836 vcol += ptr2cells(p); | |
2837 p += len; | |
7 | 2838 } |
2839 } | |
168 | 2840 msg_clr_eos(); |
1329 | 2841 windgoto(msg_row, msg_col); |
168 | 2842 continue; |
2843 } | |
2844 | |
2845 if (c1 == Ctrl_D) | |
2846 { | |
2847 /* Delete one shiftwidth. */ | |
2848 p = (char_u *)line_ga.ga_data; | |
2849 if (prev_char == '0' || prev_char == '^') | |
7 | 2850 { |
168 | 2851 if (prev_char == '^') |
2852 ex_keep_indent = TRUE; | |
2853 indent = 0; | |
2854 p[--line_ga.ga_len] = NUL; | |
7 | 2855 } |
2856 else | |
2857 { | |
168 | 2858 p[line_ga.ga_len] = NUL; |
5995 | 2859 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
|
2860 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
|
2861 { |
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
|
2862 --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
|
2863 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
|
2864 } |
168 | 2865 } |
5995 | 2866 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2867 { |
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
|
2868 s = skipwhite(p); |
168 | 2869 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2870 --line_ga.ga_len; | |
7 | 2871 } |
168 | 2872 goto add_indent; |
2873 } | |
2874 | |
2875 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2876 { | |
2877 escaped = TRUE; | |
2878 continue; | |
7 | 2879 } |
168 | 2880 |
2881 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2882 if (IS_SPECIAL(c1)) | |
2883 continue; | |
7 | 2884 } |
168 | 2885 |
2886 if (IS_SPECIAL(c1)) | |
2887 c1 = '?'; | |
5966 | 2888 #ifdef FEAT_MBYTE |
2889 if (has_mbyte) | |
2890 len = (*mb_char2bytes)(c1, | |
2891 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2892 else | |
2893 #endif | |
2894 { | |
2895 len = 1; | |
2896 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2897 } | |
168 | 2898 if (c1 == '\n') |
2899 msg_putchar('\n'); | |
2900 else if (c1 == TAB) | |
2901 { | |
2902 /* Don't use chartabsize(), 'ts' can be different */ | |
2903 do | |
2904 { | |
2905 msg_putchar(' '); | |
2906 } while (++vcol % 8); | |
2907 } | |
7 | 2908 else |
2909 { | |
168 | 2910 msg_outtrans_len( |
5966 | 2911 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2912 vcol += char2cells(c1); |
7 | 2913 } |
5966 | 2914 line_ga.ga_len += len; |
168 | 2915 escaped = FALSE; |
2916 | |
2917 windgoto(msg_row, msg_col); | |
164 | 2918 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2919 |
2590 | 2920 /* We are done when a NL is entered, but not when it comes after an |
2921 * odd number of backslashes, that results in a NUL. */ | |
2922 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2923 { |
2590 | 2924 int bcount = 0; |
2925 | |
2926 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2927 ++bcount; | |
2928 | |
2929 if (bcount > 0) | |
2930 { | |
2931 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2932 * "\NL", etc. */ | |
2933 line_ga.ga_len -= (bcount + 1) / 2; | |
2934 pend -= (bcount + 1) / 2; | |
2935 pend[-1] = '\n'; | |
2936 } | |
2937 | |
2938 if ((bcount & 1) == 0) | |
2939 { | |
2940 --line_ga.ga_len; | |
2941 --pend; | |
2942 *pend = NUL; | |
2943 break; | |
2944 } | |
7 | 2945 } |
2946 } | |
2947 | |
168 | 2948 --no_mapping; |
2949 --allow_keys; | |
2950 | |
7 | 2951 /* make following messages go to the next line */ |
2952 msg_didout = FALSE; | |
2953 msg_col = 0; | |
2954 if (msg_row < Rows - 1) | |
2955 ++msg_row; | |
2956 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2957 | |
2958 if (got_int) | |
2959 ga_clear(&line_ga); | |
2960 | |
2961 return (char_u *)line_ga.ga_data; | |
2962 } | |
2963 | |
502 | 2964 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2965 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2966 /* |
2967 * Return TRUE if ccline.overstrike is on. | |
2968 */ | |
2969 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2970 cmdline_overstrike(void) |
7 | 2971 { |
2972 return ccline.overstrike; | |
2973 } | |
2974 | |
2975 /* | |
2976 * Return TRUE if the cursor is at the end of the cmdline. | |
2977 */ | |
2978 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2979 cmdline_at_end(void) |
7 | 2980 { |
2981 return (ccline.cmdpos >= ccline.cmdlen); | |
2982 } | |
2983 #endif | |
2984 | |
574 | 2985 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2986 /* |
2987 * Return the virtual column number at the current cursor position. | |
2988 * This is used by the IM code to obtain the start of the preedit string. | |
2989 */ | |
2990 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2991 cmdline_getvcol_cursor(void) |
7 | 2992 { |
2993 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2994 return MAXCOL; | |
2995 | |
2996 # ifdef FEAT_MBYTE | |
2997 if (has_mbyte) | |
2998 { | |
2999 colnr_T col; | |
3000 int i = 0; | |
3001 | |
3002 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3003 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3004 |
3005 return col; | |
3006 } | |
3007 else | |
3008 # endif | |
3009 return ccline.cmdpos; | |
3010 } | |
3011 #endif | |
3012 | |
3013 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3014 /* | |
3015 * If part of the command line is an IM preedit string, redraw it with | |
3016 * IM feedback attributes. The cursor position is restored after drawing. | |
3017 */ | |
3018 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3019 redrawcmd_preedit(void) |
7 | 3020 { |
3021 if ((State & CMDLINE) | |
3022 && xic != NULL | |
976 | 3023 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3024 && !p_imdisable |
3025 && im_is_preediting()) | |
3026 { | |
3027 int cmdpos = 0; | |
3028 int cmdspos; | |
3029 int old_row; | |
3030 int old_col; | |
3031 colnr_T col; | |
3032 | |
3033 old_row = msg_row; | |
3034 old_col = msg_col; | |
531 | 3035 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3036 |
3037 # ifdef FEAT_MBYTE | |
3038 if (has_mbyte) | |
3039 { | |
3040 for (col = 0; col < preedit_start_col | |
3041 && cmdpos < ccline.cmdlen; ++col) | |
3042 { | |
3043 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3044 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3045 } |
3046 } | |
3047 else | |
3048 # endif | |
3049 { | |
3050 cmdspos += preedit_start_col; | |
3051 cmdpos += preedit_start_col; | |
3052 } | |
3053 | |
3054 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3055 msg_col = cmdspos % (int)Columns; | |
3056 if (msg_row >= Rows) | |
3057 msg_row = Rows - 1; | |
3058 | |
3059 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3060 { | |
3061 int char_len; | |
3062 int char_attr; | |
3063 | |
3064 char_attr = im_get_feedback_attr(col); | |
3065 if (char_attr < 0) | |
3066 break; /* end of preedit string */ | |
3067 | |
3068 # ifdef FEAT_MBYTE | |
3069 if (has_mbyte) | |
474 | 3070 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3071 else |
3072 # endif | |
3073 char_len = 1; | |
3074 | |
3075 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3076 cmdpos += char_len; | |
3077 } | |
3078 | |
3079 msg_row = old_row; | |
3080 msg_col = old_col; | |
3081 } | |
3082 } | |
3083 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3084 | |
3085 /* | |
3086 * Allocate a new command line buffer. | |
3087 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3088 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3089 */ | |
3090 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3091 alloc_cmdbuff(int len) |
7 | 3092 { |
3093 /* | |
3094 * give some extra space to avoid having to allocate all the time | |
3095 */ | |
3096 if (len < 80) | |
3097 len = 100; | |
3098 else | |
3099 len += 20; | |
3100 | |
3101 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3102 ccline.cmdbufflen = len; | |
3103 } | |
3104 | |
3105 /* | |
3106 * Re-allocate the command line to length len + something extra. | |
3107 * return FAIL for failure, OK otherwise | |
3108 */ | |
3109 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3110 realloc_cmdbuff(int len) |
7 | 3111 { |
3112 char_u *p; | |
3113 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3114 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3115 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
|
3116 |
7 | 3117 p = ccline.cmdbuff; |
3118 alloc_cmdbuff(len); /* will get some more */ | |
3119 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3120 { | |
3121 ccline.cmdbuff = p; /* keep the old one */ | |
3122 return FAIL; | |
3123 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3124 /* 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
|
3125 * 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
|
3126 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
|
3127 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3128 vim_free(p); |
1718 | 3129 |
3130 if (ccline.xpc != NULL | |
3131 && ccline.xpc->xp_pattern != NULL | |
3132 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3133 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3134 { | |
1754 | 3135 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3136 |
3137 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3138 * to point into the newly allocated memory. */ | |
3139 if (i >= 0 && i <= ccline.cmdlen) | |
3140 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3141 } | |
3142 | |
7 | 3143 return OK; |
3144 } | |
3145 | |
359 | 3146 #if defined(FEAT_ARABIC) || defined(PROTO) |
3147 static char_u *arshape_buf = NULL; | |
3148 | |
3149 # if defined(EXITFREE) || defined(PROTO) | |
3150 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3151 free_cmdline_buf(void) |
359 | 3152 { |
3153 vim_free(arshape_buf); | |
3154 } | |
3155 # endif | |
3156 #endif | |
3157 | |
7 | 3158 /* |
3159 * Draw part of the cmdline at the current cursor position. But draw stars | |
3160 * when cmdline_star is TRUE. | |
3161 */ | |
3162 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3163 draw_cmdline(int start, int len) |
7 | 3164 { |
3165 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3166 int i; | |
3167 | |
3168 if (cmdline_star > 0) | |
3169 for (i = 0; i < len; ++i) | |
3170 { | |
3171 msg_putchar('*'); | |
3172 # ifdef FEAT_MBYTE | |
3173 if (has_mbyte) | |
474 | 3174 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3175 # endif |
3176 } | |
3177 else | |
3178 #endif | |
3179 #ifdef FEAT_ARABIC | |
3180 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3181 { | |
3182 static int buflen = 0; | |
3183 char_u *p; | |
3184 int j; | |
3185 int newlen = 0; | |
3186 int mb_l; | |
719 | 3187 int pc, pc1 = 0; |
7 | 3188 int prev_c = 0; |
3189 int prev_c1 = 0; | |
714 | 3190 int u8c; |
3191 int u8cc[MAX_MCO]; | |
7 | 3192 int nc = 0; |
3193 | |
3194 /* | |
3195 * Do arabic shaping into a temporary buffer. This is very | |
3196 * inefficient! | |
3197 */ | |
507 | 3198 if (len * 2 + 2 > buflen) |
7 | 3199 { |
3200 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3201 * alloc()/free() calls. */ | |
359 | 3202 vim_free(arshape_buf); |
507 | 3203 buflen = len * 2 + 2; |
359 | 3204 arshape_buf = alloc(buflen); |
3205 if (arshape_buf == NULL) | |
7 | 3206 return; /* out of memory */ |
3207 } | |
3208 | |
507 | 3209 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3210 { | |
3211 /* Prepend a space to draw the leading composing char on. */ | |
3212 arshape_buf[0] = ' '; | |
3213 newlen = 1; | |
3214 } | |
3215 | |
7 | 3216 for (j = start; j < start + len; j += mb_l) |
3217 { | |
3218 p = ccline.cmdbuff + j; | |
714 | 3219 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3220 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3221 if (ARABIC_CHAR(u8c)) |
3222 { | |
3223 /* Do Arabic shaping. */ | |
3224 if (cmdmsg_rl) | |
3225 { | |
3226 /* displaying from right to left */ | |
3227 pc = prev_c; | |
3228 pc1 = prev_c1; | |
714 | 3229 prev_c1 = u8cc[0]; |
7 | 3230 if (j + mb_l >= start + len) |
3231 nc = NUL; | |
3232 else | |
3233 nc = utf_ptr2char(p + mb_l); | |
3234 } | |
3235 else | |
3236 { | |
3237 /* displaying from left to right */ | |
3238 if (j + mb_l >= start + len) | |
3239 pc = NUL; | |
3240 else | |
714 | 3241 { |
3242 int pcc[MAX_MCO]; | |
3243 | |
3244 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3245 start + len - j - mb_l); |
714 | 3246 pc1 = pcc[0]; |
3247 } | |
7 | 3248 nc = prev_c; |
3249 } | |
3250 prev_c = u8c; | |
3251 | |
714 | 3252 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3253 |
359 | 3254 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3255 if (u8cc[0] != 0) |
7 | 3256 { |
714 | 3257 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3258 if (u8cc[1] != 0) | |
3259 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3260 arshape_buf + newlen); |
7 | 3261 } |
3262 } | |
3263 else | |
3264 { | |
3265 prev_c = u8c; | |
359 | 3266 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3267 newlen += mb_l; |
3268 } | |
3269 } | |
3270 | |
359 | 3271 msg_outtrans_len(arshape_buf, newlen); |
7 | 3272 } |
3273 else | |
3274 #endif | |
3275 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3276 } | |
3277 | |
3278 /* | |
3279 * Put a character on the command line. Shifts the following text to the | |
3280 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3281 * "c" must be printable (fit in one display cell)! | |
3282 */ | |
3283 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3284 putcmdline(int c, int shift) |
7 | 3285 { |
3286 if (cmd_silent) | |
3287 return; | |
3288 msg_no_more = TRUE; | |
3289 msg_putchar(c); | |
3290 if (shift) | |
3291 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3292 msg_no_more = FALSE; | |
3293 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3294 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3295 extra_char_shift = shift; |
7 | 3296 } |
3297 | |
3298 /* | |
3299 * Undo a putcmdline(c, FALSE). | |
3300 */ | |
3301 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3302 unputcmdline(void) |
7 | 3303 { |
3304 if (cmd_silent) | |
3305 return; | |
3306 msg_no_more = TRUE; | |
3307 if (ccline.cmdlen == ccline.cmdpos) | |
3308 msg_putchar(' '); | |
3558 | 3309 #ifdef FEAT_MBYTE |
3310 else if (has_mbyte) | |
3311 draw_cmdline(ccline.cmdpos, | |
3312 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3313 #endif | |
7 | 3314 else |
3315 draw_cmdline(ccline.cmdpos, 1); | |
3316 msg_no_more = FALSE; | |
3317 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3318 extra_char = NUL; |
7 | 3319 } |
3320 | |
3321 /* | |
3322 * Put the given string, of the given length, onto the command line. | |
3323 * If len is -1, then STRLEN() is used to calculate the length. | |
3324 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3325 * part will be redrawn, otherwise it will not. If this function is called | |
3326 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3327 * called afterwards. | |
3328 */ | |
3329 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3330 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3331 { |
3332 int retval; | |
3333 int i; | |
3334 int m; | |
3335 int c; | |
3336 | |
3337 if (len < 0) | |
3338 len = (int)STRLEN(str); | |
3339 | |
3340 /* Check if ccline.cmdbuff needs to be longer */ | |
3341 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
|
3342 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3343 else |
3344 retval = OK; | |
3345 if (retval == OK) | |
3346 { | |
3347 if (!ccline.overstrike) | |
3348 { | |
3349 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3350 ccline.cmdbuff + ccline.cmdpos, | |
3351 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3352 ccline.cmdlen += len; | |
3353 } | |
3354 else | |
3355 { | |
3356 #ifdef FEAT_MBYTE | |
3357 if (has_mbyte) | |
3358 { | |
3359 /* Count nr of characters in the new string. */ | |
3360 m = 0; | |
474 | 3361 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3362 ++m; |
3363 /* Count nr of bytes in cmdline that are overwritten by these | |
3364 * characters. */ | |
3365 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3366 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3367 --m; |
3368 if (i < ccline.cmdlen) | |
3369 { | |
3370 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3371 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3372 ccline.cmdlen += ccline.cmdpos + len - i; | |
3373 } | |
3374 else | |
3375 ccline.cmdlen = ccline.cmdpos + len; | |
3376 } | |
3377 else | |
3378 #endif | |
3379 if (ccline.cmdpos + len > ccline.cmdlen) | |
3380 ccline.cmdlen = ccline.cmdpos + len; | |
3381 } | |
3382 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3383 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3384 | |
3385 #ifdef FEAT_MBYTE | |
3386 if (enc_utf8) | |
3387 { | |
3388 /* When the inserted text starts with a composing character, | |
3389 * backup to the character before it. There could be two of them. | |
3390 */ | |
3391 i = 0; | |
3392 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3393 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3394 { | |
3395 i = (*mb_head_off)(ccline.cmdbuff, | |
3396 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3397 ccline.cmdpos -= i; | |
3398 len += i; | |
3399 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3400 } | |
3401 # ifdef FEAT_ARABIC | |
3402 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3403 { | |
3404 /* Check the previous character for Arabic combining pair. */ | |
3405 i = (*mb_head_off)(ccline.cmdbuff, | |
3406 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3407 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3408 + ccline.cmdpos - i), c)) | |
3409 { | |
3410 ccline.cmdpos -= i; | |
3411 len += i; | |
3412 } | |
3413 else | |
3414 i = 0; | |
3415 } | |
3416 # endif | |
3417 if (i != 0) | |
3418 { | |
3419 /* Also backup the cursor position. */ | |
3420 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3421 ccline.cmdspos -= i; | |
3422 msg_col -= i; | |
3423 if (msg_col < 0) | |
3424 { | |
3425 msg_col += Columns; | |
3426 --msg_row; | |
3427 } | |
3428 } | |
3429 } | |
3430 #endif | |
3431 | |
3432 if (redraw && !cmd_silent) | |
3433 { | |
3434 msg_no_more = TRUE; | |
3435 i = cmdline_row; | |
3114 | 3436 cursorcmd(); |
7 | 3437 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3438 /* Avoid clearing the rest of the line too often. */ | |
3439 if (cmdline_row != i || ccline.overstrike) | |
3440 msg_clr_eos(); | |
3441 msg_no_more = FALSE; | |
3442 } | |
3443 #ifdef FEAT_FKMAP | |
3444 /* | |
3445 * If we are in Farsi command mode, the character input must be in | |
3446 * Insert mode. So do not advance the cmdpos. | |
3447 */ | |
3448 if (!cmd_fkmap) | |
3449 #endif | |
3450 { | |
3451 if (KeyTyped) | |
534 | 3452 { |
7 | 3453 m = Columns * Rows; |
534 | 3454 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3455 m = MAXCOL; | |
3456 } | |
7 | 3457 else |
3458 m = MAXCOL; | |
3459 for (i = 0; i < len; ++i) | |
3460 { | |
3461 c = cmdline_charsize(ccline.cmdpos); | |
3462 #ifdef FEAT_MBYTE | |
3463 /* count ">" for a double-wide char that doesn't fit. */ | |
3464 if (has_mbyte) | |
3465 correct_cmdspos(ccline.cmdpos, c); | |
3466 #endif | |
1612 | 3467 /* Stop cursor at the end of the screen, but do increment the |
3468 * insert position, so that entering a very long command | |
3469 * works, even though you can't see it. */ | |
3470 if (ccline.cmdspos + c < m) | |
3471 ccline.cmdspos += c; | |
7 | 3472 #ifdef FEAT_MBYTE |
3473 if (has_mbyte) | |
3474 { | |
474 | 3475 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3476 if (c > len - i - 1) |
3477 c = len - i - 1; | |
3478 ccline.cmdpos += c; | |
3479 i += c; | |
3480 } | |
3481 #endif | |
3482 ++ccline.cmdpos; | |
3483 } | |
3484 } | |
3485 } | |
3486 if (redraw) | |
3487 msg_check(); | |
3488 return retval; | |
3489 } | |
3490 | |
95 | 3491 static struct cmdline_info prev_ccline; |
3492 static int prev_ccline_used = FALSE; | |
3493 | |
3494 /* | |
3495 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3496 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3497 * available globally in prev_ccline. | |
3498 */ | |
3499 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3500 save_cmdline(struct cmdline_info *ccp) |
95 | 3501 { |
3502 if (!prev_ccline_used) | |
3503 { | |
3504 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3505 prev_ccline_used = TRUE; | |
3506 } | |
3507 *ccp = prev_ccline; | |
3508 prev_ccline = ccline; | |
3509 ccline.cmdbuff = NULL; | |
3510 ccline.cmdprompt = NULL; | |
1718 | 3511 ccline.xpc = NULL; |
95 | 3512 } |
3513 | |
3514 /* | |
1214 | 3515 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3516 */ |
3517 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3518 restore_cmdline(struct cmdline_info *ccp) |
95 | 3519 { |
3520 ccline = prev_ccline; | |
3521 prev_ccline = *ccp; | |
3522 } | |
3523 | |
849 | 3524 #if defined(FEAT_EVAL) || defined(PROTO) |
3525 /* | |
3526 * Save the command line into allocated memory. Returns a pointer to be | |
3527 * passed to restore_cmdline_alloc() later. | |
3528 * Returns NULL when failed. | |
3529 */ | |
3530 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3531 save_cmdline_alloc(void) |
849 | 3532 { |
3533 struct cmdline_info *p; | |
3534 | |
3535 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3536 if (p != NULL) | |
3537 save_cmdline(p); | |
3538 return (char_u *)p; | |
3539 } | |
3540 | |
3541 /* | |
3542 * Restore the command line from the return value of save_cmdline_alloc(). | |
3543 */ | |
3544 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3545 restore_cmdline_alloc(char_u *p) |
849 | 3546 { |
3547 if (p != NULL) | |
3548 { | |
3549 restore_cmdline((struct cmdline_info *)p); | |
3550 vim_free(p); | |
3551 } | |
3552 } | |
3553 #endif | |
3554 | |
15 | 3555 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3556 * 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
|
3557 * Used by CTRL-R command in command-line mode. |
15 | 3558 * insert_reg() can't be used here, because special characters from the |
3559 * register contents will be interpreted as commands. | |
3560 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3561 * Return FAIL for failure, OK otherwise. |
15 | 3562 */ |
3563 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3564 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3565 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3566 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
|
3567 int remcr) /* remove trailing CR */ |
15 | 3568 { |
3569 long i; | |
3570 char_u *arg; | |
772 | 3571 char_u *p; |
15 | 3572 int allocated; |
3573 struct cmdline_info save_ccline; | |
3574 | |
3575 /* check for valid regname; also accept special characters for CTRL-R in | |
3576 * the command line */ | |
3577 if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3578 && regname != Ctrl_A && regname != Ctrl_L |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3579 && !valid_yank_reg(regname, FALSE)) |
15 | 3580 return FAIL; |
3581 | |
3582 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3583 * CTRL-C to break the loop. */ | |
3584 line_breakcheck(); | |
3585 if (got_int) | |
3586 return FAIL; | |
3587 | |
3588 #ifdef FEAT_CLIPBOARD | |
3589 regname = may_get_selection(regname); | |
3590 #endif | |
3591 | |
634 | 3592 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3593 * things like going to another buffer when evaluating an expression. */ |
95 | 3594 save_cmdline(&save_ccline); |
634 | 3595 ++textlock; |
15 | 3596 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3597 --textlock; |
95 | 3598 restore_cmdline(&save_ccline); |
15 | 3599 |
3600 if (i) | |
3601 { | |
3602 /* Got the value of a special register in "arg". */ | |
3603 if (arg == NULL) | |
3604 return FAIL; | |
772 | 3605 |
3606 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3607 * part of the word. */ | |
3608 p = arg; | |
3609 if (p_is && regname == Ctrl_W) | |
3610 { | |
3611 char_u *w; | |
3612 int len; | |
3613 | |
3614 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3615 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3616 { |
3617 #ifdef FEAT_MBYTE | |
3618 if (has_mbyte) | |
3619 { | |
3620 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3621 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3622 break; | |
3623 w -= len; | |
3624 } | |
3625 else | |
3626 #endif | |
3627 { | |
3628 if (!vim_iswordc(w[-1])) | |
3629 break; | |
3630 --w; | |
3631 } | |
3632 } | |
2937 | 3633 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3634 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3635 p += len; | |
3636 } | |
3637 | |
3638 cmdline_paste_str(p, literally); | |
15 | 3639 if (allocated) |
3640 vim_free(arg); | |
3641 return OK; | |
3642 } | |
3643 | |
1015 | 3644 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3645 } |
3646 | |
3647 /* | |
3648 * Put a string on the command line. | |
3649 * When "literally" is TRUE, insert literally. | |
3650 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3651 * line. | |
3652 */ | |
3653 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3654 cmdline_paste_str(char_u *s, int literally) |
15 | 3655 { |
3656 int c, cv; | |
3657 | |
3658 if (literally) | |
3659 put_on_cmdline(s, -1, TRUE); | |
3660 else | |
3661 while (*s != NUL) | |
3662 { | |
3663 cv = *s; | |
3664 if (cv == Ctrl_V && s[1]) | |
3665 ++s; | |
3666 #ifdef FEAT_MBYTE | |
3667 if (has_mbyte) | |
1606 | 3668 c = mb_cptr2char_adv(&s); |
15 | 3669 else |
3670 #endif | |
3671 c = *s++; | |
3628 | 3672 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3673 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3674 #ifdef UNIX |
3675 || c == intr_char | |
3676 #endif | |
3677 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3678 stuffcharReadbuff(Ctrl_V); | |
3679 stuffcharReadbuff(c); | |
3680 } | |
3681 } | |
3682 | |
7 | 3683 #ifdef FEAT_WILDMENU |
3684 /* | |
3685 * Delete characters on the command line, from "from" to the current | |
3686 * position. | |
3687 */ | |
3688 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3689 cmdline_del(int from) |
7 | 3690 { |
3691 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3692 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3693 ccline.cmdlen -= ccline.cmdpos - from; | |
3694 ccline.cmdpos = from; | |
3695 } | |
3696 #endif | |
3697 | |
3698 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3699 * 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
|
3700 * 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
|
3701 * overwritten. |
7 | 3702 */ |
3703 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3704 redrawcmdline(void) |
7 | 3705 { |
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
|
3706 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
|
3707 } |
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
|
3708 |
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
|
3709 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
|
3710 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
|
3711 { |
7 | 3712 if (cmd_silent) |
3713 return; | |
3714 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
|
3715 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
|
3716 compute_cmdrow(); |
7 | 3717 redrawcmd(); |
3718 cursorcmd(); | |
3719 } | |
3720 | |
3721 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3722 redrawcmdprompt(void) |
7 | 3723 { |
3724 int i; | |
3725 | |
3726 if (cmd_silent) | |
3727 return; | |
531 | 3728 if (ccline.cmdfirstc != NUL) |
7 | 3729 msg_putchar(ccline.cmdfirstc); |
3730 if (ccline.cmdprompt != NULL) | |
3731 { | |
3732 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3733 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3734 /* do the reverse of set_cmdspos() */ | |
531 | 3735 if (ccline.cmdfirstc != NUL) |
7 | 3736 --ccline.cmdindent; |
3737 } | |
3738 else | |
3739 for (i = ccline.cmdindent; i > 0; --i) | |
3740 msg_putchar(' '); | |
3741 } | |
3742 | |
3743 /* | |
3744 * Redraw what is currently on the command line. | |
3745 */ | |
3746 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3747 redrawcmd(void) |
7 | 3748 { |
3749 if (cmd_silent) | |
3750 return; | |
3751 | |
683 | 3752 /* when 'incsearch' is set there may be no command line while redrawing */ |
3753 if (ccline.cmdbuff == NULL) | |
3754 { | |
3755 windgoto(cmdline_row, 0); | |
3756 msg_clr_eos(); | |
3757 return; | |
3758 } | |
3759 | |
7 | 3760 msg_start(); |
3761 redrawcmdprompt(); | |
3762 | |
3763 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3764 msg_no_more = TRUE; | |
3765 draw_cmdline(0, ccline.cmdlen); | |
3766 msg_clr_eos(); | |
3767 msg_no_more = FALSE; | |
3768 | |
3769 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
|
3770 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
|
3771 putcmdline(extra_char, extra_char_shift); |
7 | 3772 |
3773 /* | |
3774 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3775 * in cmdline mode we can reset them now. | |
3776 */ | |
3777 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3778 | |
3779 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3780 * in cmdline mode */ | |
3781 skip_redraw = FALSE; | |
3782 } | |
3783 | |
3784 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3785 compute_cmdrow(void) |
7 | 3786 { |
540 | 3787 if (exmode_active || msg_scrolled != 0) |
7 | 3788 cmdline_row = Rows - 1; |
3789 else | |
3790 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
|
3791 + lastwin->w_status_height; |
7 | 3792 } |
3793 | |
3794 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3795 cursorcmd(void) |
7 | 3796 { |
3797 if (cmd_silent) | |
3798 return; | |
3799 | |
3800 #ifdef FEAT_RIGHTLEFT | |
3801 if (cmdmsg_rl) | |
3802 { | |
3803 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3804 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3805 if (msg_row <= 0) | |
3806 msg_row = Rows - 1; | |
3807 } | |
3808 else | |
3809 #endif | |
3810 { | |
3811 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3812 msg_col = ccline.cmdspos % (int)Columns; | |
3813 if (msg_row >= Rows) | |
3814 msg_row = Rows - 1; | |
3815 } | |
3816 | |
3817 windgoto(msg_row, msg_col); | |
3818 #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
|
3819 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
|
3820 redrawcmd_preedit(); |
7 | 3821 #endif |
3822 #ifdef MCH_CURSOR_SHAPE | |
3823 mch_update_cursor(); | |
3824 #endif | |
3825 } | |
3826 | |
3827 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3828 gotocmdline(int clr) |
7 | 3829 { |
3830 msg_start(); | |
3831 #ifdef FEAT_RIGHTLEFT | |
3832 if (cmdmsg_rl) | |
3833 msg_col = Columns - 1; | |
3834 else | |
3835 #endif | |
3836 msg_col = 0; /* always start in column 0 */ | |
3837 if (clr) /* clear the bottom line(s) */ | |
3838 msg_clr_eos(); /* will reset clear_cmdline */ | |
3839 windgoto(cmdline_row, 0); | |
3840 } | |
3841 | |
3842 /* | |
3843 * Check the word in front of the cursor for an abbreviation. | |
3844 * Called when the non-id character "c" has been entered. | |
3845 * When an abbreviation is recognized it is removed from the text with | |
3846 * backspaces and the replacement string is inserted, followed by "c". | |
3847 */ | |
3848 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3849 ccheck_abbr(int c) |
7 | 3850 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3851 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3852 |
7 | 3853 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3854 return FALSE; | |
3855 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3856 /* Do not consider '<,'> be part of the mapping, skip leading whitespace. |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3857 * Actually accepts any mark. */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3858 while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3859 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3860 if (ccline.cmdlen - spos > 5 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3861 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3862 && ccline.cmdbuff[spos + 2] == ',' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3863 && ccline.cmdbuff[spos + 3] == '\'') |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3864 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3865 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3866 /* check abbreviation from the beginning of the commandline */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3867 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3868 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3869 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3870 } |
3871 | |
3164 | 3872 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3873 static int | |
3874 #ifdef __BORLANDC__ | |
3875 _RTLENTRYF | |
3876 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3877 sort_func_compare(const void *s1, const void *s2) |
3164 | 3878 { |
3879 char_u *p1 = *(char_u **)s1; | |
3880 char_u *p2 = *(char_u **)s2; | |
3881 | |
3882 if (*p1 != '<' && *p2 == '<') return -1; | |
3883 if (*p1 == '<' && *p2 != '<') return 1; | |
3884 return STRCMP(p1, p2); | |
3885 } | |
3886 #endif | |
3887 | |
7 | 3888 /* |
3889 * Return FAIL if this is not an appropriate context in which to do | |
3890 * completion of anything, return OK if it is (even if there are no matches). | |
3891 * For the caller, this means that the character is just passed through like a | |
3892 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3893 */ | |
3894 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3895 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3896 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3897 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3898 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3899 int escape) /* if TRUE, escape the returned matches */ |
7 | 3900 { |
3901 int i, j; | |
3902 char_u *p1; | |
3903 char_u *p2; | |
3904 int difflen; | |
3905 int v; | |
3906 | |
3907 if (xp->xp_numfiles == -1) | |
3908 { | |
3909 set_expand_context(xp); | |
3910 cmd_showtail = expand_showtail(xp); | |
3911 } | |
3912 | |
3913 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3914 { | |
3915 beep_flush(); | |
3916 return OK; /* Something illegal on command line */ | |
3917 } | |
3918 if (xp->xp_context == EXPAND_NOTHING) | |
3919 { | |
3920 /* Caller can use the character as a normal char instead */ | |
3921 return FAIL; | |
3922 } | |
3923 | |
3924 MSG_PUTS("..."); /* show that we are busy */ | |
3925 out_flush(); | |
3926 | |
3927 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3928 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3929 |
3930 if (type == WILD_NEXT || type == WILD_PREV) | |
3931 { | |
3932 /* | |
3933 * Get next/previous match for a previous expanded pattern. | |
3934 */ | |
3935 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3936 } | |
3937 else | |
3938 { | |
3939 /* | |
3940 * Translate string into pattern and expand it. | |
3941 */ | |
1965 | 3942 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3943 xp->xp_context)) == NULL) | |
7 | 3944 p2 = NULL; |
3945 else | |
3946 { | |
2652 | 3947 int use_options = options | |
3961 | 3948 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3949 if (escape) | |
3950 use_options |= WILD_ESCAPE; | |
2652 | 3951 |
3952 if (p_wic) | |
3953 use_options += WILD_ICASE; | |
1965 | 3954 p2 = ExpandOne(xp, p1, |
3955 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3956 use_options, type); |
7 | 3957 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3958 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3959 if (p2 != NULL && type == WILD_LONGEST) |
3960 { | |
1965 | 3961 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3962 if (ccline.cmdbuff[i + j] == '*' |
3963 || ccline.cmdbuff[i + j] == '?') | |
3964 break; | |
3965 if ((int)STRLEN(p2) < j) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
3966 VIM_CLEAR(p2); |
7 | 3967 } |
3968 } | |
3969 } | |
3970 | |
3971 if (p2 != NULL && !got_int) | |
3972 { | |
1965 | 3973 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
|
3974 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3975 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3976 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3977 xp->xp_pattern = ccline.cmdbuff + i; |
3978 } | |
3979 else | |
3980 v = OK; | |
3981 if (v == OK) | |
3982 { | |
323 | 3983 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3984 &ccline.cmdbuff[ccline.cmdpos], | |
3985 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3986 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3987 ccline.cmdlen += difflen; |
3988 ccline.cmdpos += difflen; | |
3989 } | |
3990 } | |
3991 vim_free(p2); | |
3992 | |
3993 redrawcmd(); | |
33 | 3994 cursorcmd(); |
7 | 3995 |
3996 /* When expanding a ":map" command and no matches are found, assume that | |
3997 * the key is supposed to be inserted literally */ | |
3998 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3999 return FAIL; | |
4000 | |
4001 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4002 beep_flush(); | |
4003 else if (xp->xp_numfiles == 1) | |
4004 /* free expanded pattern */ | |
4005 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4006 | |
4007 return OK; | |
4008 } | |
4009 | |
4010 /* | |
4011 * Do wildcard expansion on the string 'str'. | |
4012 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4013 * Return a pointer to allocated memory containing the new string. |
7 | 4014 * Return NULL for failure. |
4015 * | |
1412 | 4016 * "orig" is the originally expanded string, copied to allocated memory. It |
4017 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4018 * WILD_PREV "orig" should be NULL. | |
4019 * | |
838 | 4020 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4021 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4022 * |
4023 * mode = WILD_FREE: just free previously expanded matches | |
4024 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4025 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4026 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4027 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4028 * mode = WILD_ALL: return all matches concatenated | |
4029 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4030 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4031 * |
4032 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4033 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4034 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4035 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4036 * options = WILD_ADD_SLASH: add a slash after directory names | |
4037 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4038 * options = WILD_SILENT: don't print warning messages | |
4039 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4040 * options = WILD_ICASE: ignore case for files |
7 | 4041 * |
4042 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4043 */ | |
4044 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4045 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4046 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4047 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4048 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
|
4049 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4050 int mode) |
7 | 4051 { |
4052 char_u *ss = NULL; | |
4053 static int findex; | |
4054 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4055 int orig_saved = FALSE; |
7 | 4056 int i; |
4057 long_u len; | |
4058 int non_suf_match; /* number without matching suffix */ | |
4059 | |
4060 /* | |
4061 * first handle the case of using an old match | |
4062 */ | |
4063 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4064 { | |
4065 if (xp->xp_numfiles > 0) | |
4066 { | |
4067 if (mode == WILD_PREV) | |
4068 { | |
4069 if (findex == -1) | |
4070 findex = xp->xp_numfiles; | |
4071 --findex; | |
4072 } | |
4073 else /* mode == WILD_NEXT */ | |
4074 ++findex; | |
4075 | |
4076 /* | |
4077 * When wrapping around, return the original string, set findex to | |
4078 * -1. | |
4079 */ | |
4080 if (findex < 0) | |
4081 { | |
4082 if (orig_save == NULL) | |
4083 findex = xp->xp_numfiles - 1; | |
4084 else | |
4085 findex = -1; | |
4086 } | |
4087 if (findex >= xp->xp_numfiles) | |
4088 { | |
4089 if (orig_save == NULL) | |
4090 findex = 0; | |
4091 else | |
4092 findex = -1; | |
4093 } | |
4094 #ifdef FEAT_WILDMENU | |
4095 if (p_wmnu) | |
4096 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4097 findex, cmd_showtail); | |
4098 #endif | |
4099 if (findex == -1) | |
4100 return vim_strsave(orig_save); | |
4101 return vim_strsave(xp->xp_files[findex]); | |
4102 } | |
4103 else | |
4104 return NULL; | |
4105 } | |
4106 | |
1412 | 4107 /* free old names */ |
7 | 4108 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4109 { | |
4110 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4111 xp->xp_numfiles = -1; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
4112 VIM_CLEAR(orig_save); |
7 | 4113 } |
4114 findex = 0; | |
4115 | |
4116 if (mode == WILD_FREE) /* only release file name */ | |
4117 return NULL; | |
4118 | |
4119 if (xp->xp_numfiles == -1) | |
4120 { | |
4121 vim_free(orig_save); | |
4122 orig_save = orig; | |
1432 | 4123 orig_saved = TRUE; |
7 | 4124 |
4125 /* | |
4126 * Do the expansion. | |
4127 */ | |
4128 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4129 options) == FAIL) | |
4130 { | |
4131 #ifdef FNAME_ILLEGAL | |
4132 /* Illegal file name has been silently skipped. But when there | |
4133 * are wildcards, the real problem is that there was no match, | |
4134 * causing the pattern to be added, which has illegal characters. | |
4135 */ | |
4136 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4137 EMSG2(_(e_nomatch2), str); | |
4138 #endif | |
4139 } | |
4140 else if (xp->xp_numfiles == 0) | |
4141 { | |
4142 if (!(options & WILD_SILENT)) | |
4143 EMSG2(_(e_nomatch2), str); | |
4144 } | |
4145 else | |
4146 { | |
4147 /* Escape the matches for use on the command line. */ | |
4148 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4149 | |
4150 /* | |
4151 * Check for matching suffixes in file names. | |
4152 */ | |
3398 | 4153 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4154 && mode != WILD_LONGEST) | |
7 | 4155 { |
4156 if (xp->xp_numfiles) | |
4157 non_suf_match = xp->xp_numfiles; | |
4158 else | |
4159 non_suf_match = 1; | |
4160 if ((xp->xp_context == EXPAND_FILES | |
4161 || xp->xp_context == EXPAND_DIRECTORIES) | |
4162 && xp->xp_numfiles > 1) | |
4163 { | |
4164 /* | |
4165 * More than one match; check suffix. | |
4166 * The files will have been sorted on matching suffix in | |
4167 * expand_wildcards, only need to check the first two. | |
4168 */ | |
4169 non_suf_match = 0; | |
4170 for (i = 0; i < 2; ++i) | |
4171 if (match_suffix(xp->xp_files[i])) | |
4172 ++non_suf_match; | |
4173 } | |
4174 if (non_suf_match != 1) | |
4175 { | |
4176 /* Can we ever get here unless it's while expanding | |
4177 * interactively? If not, we can get rid of this all | |
4178 * together. Don't really want to wait for this message | |
4179 * (and possibly have to hit return to continue!). | |
4180 */ | |
4181 if (!(options & WILD_SILENT)) | |
4182 EMSG(_(e_toomany)); | |
4183 else if (!(options & WILD_NO_BEEP)) | |
4184 beep_flush(); | |
4185 } | |
4186 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4187 ss = vim_strsave(xp->xp_files[0]); | |
4188 } | |
4189 } | |
4190 } | |
4191 | |
4192 /* Find longest common part */ | |
4193 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4194 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4195 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4196 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4197 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4198 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4199 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4200 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4201 if (has_mbyte) |
7 | 4202 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4203 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
|
4204 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
|
4205 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4206 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4207 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4208 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
|
4209 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
|
4210 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4211 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4212 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4213 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
|
4214 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4215 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4216 ci = xp->xp_files[i][len]; |
4242 | 4217 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4218 || xp->xp_context == EXPAND_FILES |
714 | 4219 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4220 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4221 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4222 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4223 break; |
4224 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4225 else if (c0 != ci) |
7 | 4226 break; |
4227 } | |
4228 if (i < xp->xp_numfiles) | |
4229 { | |
4230 if (!(options & WILD_NO_BEEP)) | |
6949 | 4231 vim_beep(BO_WILD); |
7 | 4232 break; |
4233 } | |
4234 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4235 |
7 | 4236 ss = alloc((unsigned)len + 1); |
4237 if (ss) | |
419 | 4238 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4239 findex = -1; /* next p_wc gets first one */ |
4240 } | |
4241 | |
4242 /* Concatenate all matching names */ | |
4243 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4244 { | |
4245 len = 0; | |
4246 for (i = 0; i < xp->xp_numfiles; ++i) | |
4247 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4248 ss = lalloc(len, TRUE); | |
4249 if (ss != NULL) | |
4250 { | |
4251 *ss = NUL; | |
4252 for (i = 0; i < xp->xp_numfiles; ++i) | |
4253 { | |
4254 STRCAT(ss, xp->xp_files[i]); | |
4255 if (i != xp->xp_numfiles - 1) | |
4256 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4257 } | |
4258 } | |
4259 } | |
4260 | |
4261 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4262 ExpandCleanup(xp); | |
4263 | |
1412 | 4264 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4265 if (!orig_saved) |
1412 | 4266 vim_free(orig); |
4267 | |
7 | 4268 return ss; |
4269 } | |
4270 | |
4271 /* | |
4272 * Prepare an expand structure for use. | |
4273 */ | |
4274 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4275 ExpandInit(expand_T *xp) |
7 | 4276 { |
1718 | 4277 xp->xp_pattern = NULL; |
1965 | 4278 xp->xp_pattern_len = 0; |
7 | 4279 xp->xp_backslash = XP_BS_NONE; |
632 | 4280 #ifndef BACKSLASH_IN_FILENAME |
4281 xp->xp_shell = FALSE; | |
4282 #endif | |
7 | 4283 xp->xp_numfiles = -1; |
4284 xp->xp_files = NULL; | |
632 | 4285 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4286 xp->xp_arg = NULL; | |
4287 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4288 xp->xp_line = NULL; |
7 | 4289 } |
4290 | |
4291 /* | |
4292 * Cleanup an expand structure after use. | |
4293 */ | |
4294 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4295 ExpandCleanup(expand_T *xp) |
7 | 4296 { |
4297 if (xp->xp_numfiles >= 0) | |
4298 { | |
4299 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4300 xp->xp_numfiles = -1; | |
4301 } | |
4302 } | |
4303 | |
4304 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4305 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4306 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4307 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4308 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4309 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4310 int options) |
7 | 4311 { |
4312 int i; | |
4313 char_u *p; | |
4314 | |
4315 /* | |
4316 * May change home directory back to "~" | |
4317 */ | |
4318 if (options & WILD_HOME_REPLACE) | |
4319 tilde_replace(str, numfiles, files); | |
4320 | |
4321 if (options & WILD_ESCAPE) | |
4322 { | |
4323 if (xp->xp_context == EXPAND_FILES | |
2778 | 4324 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4325 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4326 || xp->xp_context == EXPAND_BUFFERS |
4327 || xp->xp_context == EXPAND_DIRECTORIES) | |
4328 { | |
4329 /* | |
4330 * Insert a backslash into a file name before a space, \, %, # | |
4331 * and wildmatch characters, except '~'. | |
4332 */ | |
4333 for (i = 0; i < numfiles; ++i) | |
4334 { | |
4335 /* for ":set path=" we need to escape spaces twice */ | |
4336 if (xp->xp_backslash == XP_BS_THREE) | |
4337 { | |
4338 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4339 if (p != NULL) | |
4340 { | |
4341 vim_free(files[i]); | |
4342 files[i] = p; | |
719 | 4343 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4344 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4345 if (p != NULL) | |
4346 { | |
4347 vim_free(files[i]); | |
4348 files[i] = p; | |
4349 } | |
4350 #endif | |
4351 } | |
4352 } | |
1589 | 4353 #ifdef BACKSLASH_IN_FILENAME |
4354 p = vim_strsave_fnameescape(files[i], FALSE); | |
4355 #else | |
1586 | 4356 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4357 #endif |
7 | 4358 if (p != NULL) |
4359 { | |
4360 vim_free(files[i]); | |
4361 files[i] = p; | |
4362 } | |
4363 | |
4364 /* If 'str' starts with "\~", replace "~" at start of | |
4365 * files[i] with "\~". */ | |
4366 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4367 escape_fname(&files[i]); |
7 | 4368 } |
4369 xp->xp_backslash = XP_BS_NONE; | |
435 | 4370 |
4371 /* If the first file starts with a '+' escape it. Otherwise it | |
4372 * could be seen as "+cmd". */ | |
4373 if (*files[0] == '+') | |
4374 escape_fname(&files[0]); | |
7 | 4375 } |
4376 else if (xp->xp_context == EXPAND_TAGS) | |
4377 { | |
4378 /* | |
4379 * Insert a backslash before characters in a tag name that | |
4380 * would terminate the ":tag" command. | |
4381 */ | |
4382 for (i = 0; i < numfiles; ++i) | |
4383 { | |
4384 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4385 if (p != NULL) | |
4386 { | |
4387 vim_free(files[i]); | |
4388 files[i] = p; | |
4389 } | |
4390 } | |
4391 } | |
4392 } | |
4393 } | |
4394 | |
4395 /* | |
1586 | 4396 * Escape special characters in "fname" for when used as a file name argument |
4397 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4398 * Returns the result in allocated memory. | |
4399 */ | |
4400 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4401 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4402 { |
1685 | 4403 char_u *p; |
1586 | 4404 #ifdef BACKSLASH_IN_FILENAME |
4405 char_u buf[20]; | |
4406 int j = 0; | |
4407 | |
5481 | 4408 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4409 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4410 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4411 buf[j++] = *p; |
4412 buf[j] = NUL; | |
1700 | 4413 p = vim_strsave_escaped(fname, buf); |
1586 | 4414 #else |
1685 | 4415 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4416 if (shell && csh_like_shell() && p != NULL) | |
4417 { | |
4418 char_u *s; | |
4419 | |
4420 /* For csh and similar shells need to put two backslashes before '!'. | |
4421 * One is taken by Vim, one by the shell. */ | |
4422 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4423 vim_free(p); | |
4424 p = s; | |
4425 } | |
1700 | 4426 #endif |
4427 | |
4428 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4429 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4430 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4431 escape_fname(&p); |
4432 | |
1685 | 4433 return p; |
1586 | 4434 } |
4435 | |
4436 /* | |
435 | 4437 * Put a backslash before the file name in "pp", which is in allocated memory. |
4438 */ | |
4439 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4440 escape_fname(char_u **pp) |
435 | 4441 { |
4442 char_u *p; | |
4443 | |
4444 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4445 if (p != NULL) | |
4446 { | |
4447 p[0] = '\\'; | |
4448 STRCPY(p + 1, *pp); | |
4449 vim_free(*pp); | |
4450 *pp = p; | |
4451 } | |
4452 } | |
4453 | |
4454 /* | |
7 | 4455 * For each file name in files[num_files]: |
4456 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4457 */ | |
4458 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4459 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4460 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4461 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4462 char_u **files) |
7 | 4463 { |
4464 int i; | |
4465 char_u *p; | |
4466 | |
4467 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4468 { | |
4469 for (i = 0; i < num_files; ++i) | |
4470 { | |
4471 p = home_replace_save(NULL, files[i]); | |
4472 if (p != NULL) | |
4473 { | |
4474 vim_free(files[i]); | |
4475 files[i] = p; | |
4476 } | |
4477 } | |
4478 } | |
4479 } | |
4480 | |
4481 /* | |
4482 * Show all matches for completion on the command line. | |
4483 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4484 * be inserted like a normal character. | |
4485 */ | |
4486 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4487 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4488 { |
4489 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4490 int num_files; | |
4491 char_u **files_found; | |
4492 int i, j, k; | |
4493 int maxlen; | |
4494 int lines; | |
4495 int columns; | |
4496 char_u *p; | |
4497 int lastlen; | |
4498 int attr; | |
4499 int showtail; | |
4500 | |
4501 if (xp->xp_numfiles == -1) | |
4502 { | |
4503 set_expand_context(xp); | |
4504 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4505 &num_files, &files_found); | |
4506 showtail = expand_showtail(xp); | |
4507 if (i != EXPAND_OK) | |
4508 return i; | |
4509 | |
4510 } | |
4511 else | |
4512 { | |
4513 num_files = xp->xp_numfiles; | |
4514 files_found = xp->xp_files; | |
4515 showtail = cmd_showtail; | |
4516 } | |
4517 | |
4518 #ifdef FEAT_WILDMENU | |
4519 if (!wildmenu) | |
4520 { | |
4521 #endif | |
4522 msg_didany = FALSE; /* lines_left will be set */ | |
4523 msg_start(); /* prepare for paging */ | |
4524 msg_putchar('\n'); | |
4525 out_flush(); | |
4526 cmdline_row = msg_row; | |
4527 msg_didany = FALSE; /* lines_left will be set again */ | |
4528 msg_start(); /* prepare for paging */ | |
4529 #ifdef FEAT_WILDMENU | |
4530 } | |
4531 #endif | |
4532 | |
4533 if (got_int) | |
4534 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4535 #ifdef FEAT_WILDMENU | |
4536 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
|
4537 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4538 #endif |
4539 else | |
4540 { | |
4541 /* find the length of the longest file name */ | |
4542 maxlen = 0; | |
4543 for (i = 0; i < num_files; ++i) | |
4544 { | |
4545 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4546 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4547 || xp->xp_context == EXPAND_BUFFERS)) |
4548 { | |
4549 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4550 j = vim_strsize(NameBuff); | |
4551 } | |
4552 else | |
4553 j = vim_strsize(L_SHOWFILE(i)); | |
4554 if (j > maxlen) | |
4555 maxlen = j; | |
4556 } | |
4557 | |
4558 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4559 lines = num_files; | |
4560 else | |
4561 { | |
4562 /* compute the number of columns and lines for the listing */ | |
4563 maxlen += 2; /* two spaces between file names */ | |
4564 columns = ((int)Columns + 2) / maxlen; | |
4565 if (columns < 1) | |
4566 columns = 1; | |
4567 lines = (num_files + columns - 1) / columns; | |
4568 } | |
4569 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4570 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4571 |
4572 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4573 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4574 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4575 msg_clr_eos(); |
4576 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
|
4577 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4578 } |
4579 | |
4580 /* list the files line by line */ | |
4581 for (i = 0; i < lines; ++i) | |
4582 { | |
4583 lastlen = 999; | |
4584 for (k = i; k < num_files; k += lines) | |
4585 { | |
4586 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4587 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4588 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4589 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4590 msg_advance(maxlen + 1); | |
4591 msg_puts(p); | |
4592 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
|
4593 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4594 break; |
4595 } | |
4596 for (j = maxlen - lastlen; --j >= 0; ) | |
4597 msg_putchar(' '); | |
4598 if (xp->xp_context == EXPAND_FILES | |
714 | 4599 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4600 || xp->xp_context == EXPAND_BUFFERS) |
4601 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4602 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4603 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4604 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4605 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4606 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4607 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4608 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4609 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4610 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4611 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
|
4612 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4613 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4614 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4615 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4616 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4617 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4618 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4619 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4620 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4621 j = mch_isdir(files_found[k]); |
7 | 4622 if (showtail) |
4623 p = L_SHOWFILE(k); | |
4624 else | |
4625 { | |
4626 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4627 TRUE); | |
4628 p = NameBuff; | |
4629 } | |
4630 } | |
4631 else | |
4632 { | |
4633 j = FALSE; | |
4634 p = L_SHOWFILE(k); | |
4635 } | |
4636 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4637 } | |
4638 if (msg_col > 0) /* when not wrapped around */ | |
4639 { | |
4640 msg_clr_eos(); | |
4641 msg_putchar('\n'); | |
4642 } | |
4643 out_flush(); /* show one line at a time */ | |
4644 if (got_int) | |
4645 { | |
4646 got_int = FALSE; | |
4647 break; | |
4648 } | |
4649 } | |
4650 | |
4651 /* | |
4652 * we redraw the command below the lines that we have just listed | |
4653 * This is a bit tricky, but it saves a lot of screen updating. | |
4654 */ | |
4655 cmdline_row = msg_row; /* will put it back later */ | |
4656 } | |
4657 | |
4658 if (xp->xp_numfiles == -1) | |
4659 FreeWild(num_files, files_found); | |
4660 | |
4661 return EXPAND_OK; | |
4662 } | |
4663 | |
4664 /* | |
4665 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4666 * Find tail of file name path, but ignore trailing "/". | |
4667 */ | |
4668 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4669 sm_gettail(char_u *s) |
7 | 4670 { |
4671 char_u *p; | |
4672 char_u *t = s; | |
4673 int had_sep = FALSE; | |
4674 | |
4675 for (p = s; *p != NUL; ) | |
4676 { | |
4677 if (vim_ispathsep(*p) | |
4678 #ifdef BACKSLASH_IN_FILENAME | |
4679 && !rem_backslash(p) | |
4680 #endif | |
4681 ) | |
4682 had_sep = TRUE; | |
4683 else if (had_sep) | |
4684 { | |
4685 t = p; | |
4686 had_sep = FALSE; | |
4687 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4688 MB_PTR_ADV(p); |
7 | 4689 } |
4690 return t; | |
4691 } | |
4692 | |
4693 /* | |
4694 * Return TRUE if we only need to show the tail of completion matches. | |
4695 * When not completing file names or there is a wildcard in the path FALSE is | |
4696 * returned. | |
4697 */ | |
4698 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4699 expand_showtail(expand_T *xp) |
7 | 4700 { |
4701 char_u *s; | |
4702 char_u *end; | |
4703 | |
4704 /* When not completing file names a "/" may mean something different. */ | |
714 | 4705 if (xp->xp_context != EXPAND_FILES |
4706 && xp->xp_context != EXPAND_SHELLCMD | |
4707 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4708 return FALSE; |
4709 | |
4710 end = gettail(xp->xp_pattern); | |
4711 if (end == xp->xp_pattern) /* there is no path separator */ | |
4712 return FALSE; | |
4713 | |
4714 for (s = xp->xp_pattern; s < end; s++) | |
4715 { | |
4716 /* Skip escaped wildcards. Only when the backslash is not a path | |
4717 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4718 if (rem_backslash(s)) | |
4719 ++s; | |
4720 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4721 return FALSE; | |
4722 } | |
4723 return TRUE; | |
4724 } | |
4725 | |
4726 /* | |
4727 * Prepare a string for expansion. | |
4728 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4729 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4730 * When expanding other names: The string will be used with regcomp(). Copy |
4731 * the name into allocated memory and prepend "^". | |
4732 */ | |
4733 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4734 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4735 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4736 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4737 int context) /* EXPAND_FILES etc. */ |
7 | 4738 { |
4739 char_u *retval; | |
4740 int i, j; | |
4741 int new_len; | |
4742 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4743 int ends_in_star; |
7 | 4744 |
714 | 4745 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4746 && context != EXPAND_FILES_IN_PATH |
714 | 4747 && context != EXPAND_SHELLCMD |
4748 && context != EXPAND_DIRECTORIES) | |
7 | 4749 { |
4750 /* | |
4751 * Matching will be done internally (on something other than files). | |
4752 * So we convert the file-matching-type wildcards into our kind for | |
4753 * use with vim_regcomp(). First work out how long it will be: | |
4754 */ | |
4755 | |
4756 /* For help tags the translation is done in find_help_tags(). | |
4757 * For a tag pattern starting with "/" no translation is needed. */ | |
4758 if (context == EXPAND_HELP | |
4759 || context == EXPAND_COLORS | |
4760 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4761 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4762 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4763 || 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
|
4764 || ((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
|
4765 || 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
|
4766 && fname[0] == '/')) |
7 | 4767 retval = vim_strnsave(fname, len); |
4768 else | |
4769 { | |
4770 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4771 for (i = 0; i < len; i++) | |
4772 { | |
4773 if (fname[i] == '*' || fname[i] == '~') | |
4774 new_len++; /* '*' needs to be replaced by ".*" | |
4775 '~' needs to be replaced by "\~" */ | |
4776 | |
4777 /* Buffer names are like file names. "." should be literal */ | |
4778 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4779 new_len++; /* "." becomes "\." */ | |
4780 | |
4781 /* Custom expansion takes care of special things, match | |
4782 * backslashes literally (perhaps also for other types?) */ | |
634 | 4783 if ((context == EXPAND_USER_DEFINED |
4784 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4785 new_len++; /* '\' becomes "\\" */ |
4786 } | |
4787 retval = alloc(new_len); | |
4788 if (retval != NULL) | |
4789 { | |
4790 retval[0] = '^'; | |
4791 j = 1; | |
4792 for (i = 0; i < len; i++, j++) | |
4793 { | |
4794 /* Skip backslash. But why? At least keep it for custom | |
4795 * expansion. */ | |
4796 if (context != EXPAND_USER_DEFINED | |
407 | 4797 && context != EXPAND_USER_LIST |
4798 && fname[i] == '\\' | |
4799 && ++i == len) | |
7 | 4800 break; |
4801 | |
4802 switch (fname[i]) | |
4803 { | |
4804 case '*': retval[j++] = '.'; | |
4805 break; | |
4806 case '~': retval[j++] = '\\'; | |
4807 break; | |
4808 case '?': retval[j] = '.'; | |
4809 continue; | |
4810 case '.': if (context == EXPAND_BUFFERS) | |
4811 retval[j++] = '\\'; | |
4812 break; | |
407 | 4813 case '\\': if (context == EXPAND_USER_DEFINED |
4814 || context == EXPAND_USER_LIST) | |
7 | 4815 retval[j++] = '\\'; |
4816 break; | |
4817 } | |
4818 retval[j] = fname[i]; | |
4819 } | |
4820 retval[j] = NUL; | |
4821 } | |
4822 } | |
4823 } | |
4824 else | |
4825 { | |
4826 retval = alloc(len + 4); | |
4827 if (retval != NULL) | |
4828 { | |
419 | 4829 vim_strncpy(retval, fname, len); |
7 | 4830 |
4831 /* | |
831 | 4832 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4833 * * would become **, which walks the whole tree. | |
7 | 4834 * ~ would be at the start of the file name, but not the tail. |
4835 * $ could be anywhere in the tail. | |
4836 * ` could be anywhere in the file name. | |
1484 | 4837 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4838 */ |
4839 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4840 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
|
4841 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4842 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4843 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4844 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4845 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4846 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4847 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4848 #endif |
7 | 4849 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4850 && !ends_in_star |
7 | 4851 && vim_strchr(tail, '$') == NULL |
4852 && vim_strchr(retval, '`') == NULL) | |
4853 retval[len++] = '*'; | |
1484 | 4854 else if (len > 0 && retval[len - 1] == '$') |
4855 --len; | |
7 | 4856 retval[len] = NUL; |
4857 } | |
4858 } | |
4859 return retval; | |
4860 } | |
4861 | |
4862 /* | |
4863 * Must parse the command line so far to work out what context we are in. | |
4864 * Completion can then be done based on that context. | |
4865 * This routine sets the variables: | |
4866 * xp->xp_pattern The start of the pattern to be expanded within | |
4867 * the command line (ends at the cursor). | |
4868 * xp->xp_context The type of thing to expand. Will be one of: | |
4869 * | |
4870 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4871 * the command line, like an unknown command. Caller | |
4872 * should beep. | |
4873 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4874 * a normal char, rather than for completion. eg | |
4875 * :s/^I/ | |
4876 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4877 * it. | |
4878 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4879 * EXPAND_FILES After command with XFILE set, or after setting | |
4880 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4881 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4882 * when we know only directories are of interest. eg | |
4883 * :set dir=^I | |
714 | 4884 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4885 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4886 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4887 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4888 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4889 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4890 * EXPAND_EVENTS Complete event names | |
4891 * EXPAND_SYNTAX Complete :syntax command arguments | |
4892 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4893 * EXPAND_AUGROUP Complete autocommand group names | |
4894 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4895 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4896 * eg :unmap a^I , :cunab x^I | |
4897 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4898 * eg :call sub^I | |
4899 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4900 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4901 * names in expressions, eg :while s^I | |
4902 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4903 * EXPAND_USER Complete user names |
7 | 4904 */ |
4905 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4906 set_expand_context(expand_T *xp) |
7 | 4907 { |
168 | 4908 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4909 if (ccline.cmdfirstc != ':' |
4910 #ifdef FEAT_EVAL | |
168 | 4911 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4912 && !ccline.input_fn |
7 | 4913 #endif |
4914 ) | |
4915 { | |
4916 xp->xp_context = EXPAND_NOTHING; | |
4917 return; | |
4918 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4919 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4920 } |
4921 | |
4922 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4923 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4924 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4925 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
|
4926 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
|
4927 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4928 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4929 { |
4930 int old_char = NUL; | |
4931 char_u *nextcomm; | |
4932 | |
4933 /* | |
4934 * Avoid a UMR warning from Purify, only save the character if it has been | |
4935 * written before. | |
4936 */ | |
4937 if (col < len) | |
4938 old_char = str[col]; | |
4939 str[col] = NUL; | |
4940 nextcomm = str; | |
168 | 4941 |
4942 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4943 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4944 { |
4945 # ifdef FEAT_CMDL_COMPL | |
168 | 4946 /* pass CMD_SIZE because there is no real command */ |
4947 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4948 # endif |
4949 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4950 else if (use_ccline && ccline.input_fn) |
531 | 4951 { |
4952 xp->xp_context = ccline.xp_context; | |
4953 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4954 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4955 xp->xp_arg = ccline.xp_arg; |
1322 | 4956 # endif |
531 | 4957 } |
168 | 4958 else |
4959 #endif | |
4960 while (nextcomm != NULL) | |
4961 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4962 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4963 /* 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
|
4964 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4965 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4966 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4967 |
7 | 4968 str[col] = old_char; |
4969 } | |
4970 | |
4971 /* | |
4972 * Expand the command line "str" from context "xp". | |
4973 * "xp" must have been set by set_cmd_context(). | |
4974 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4975 * starts. | |
4976 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4977 * cursor. | |
4978 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4979 * key that triggered expansion literally. | |
4980 * Returns EXPAND_OK otherwise. | |
4981 */ | |
4982 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4983 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4984 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4985 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
|
4986 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4987 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4988 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4989 { |
4990 char_u *file_str = NULL; | |
2652 | 4991 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4992 |
4993 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4994 { | |
4995 beep_flush(); | |
4996 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4997 } | |
4998 if (xp->xp_context == EXPAND_NOTHING) | |
4999 { | |
5000 /* Caller can use the character as a normal char instead */ | |
5001 return EXPAND_NOTHING; | |
5002 } | |
5003 | |
5004 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5005 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5006 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5007 if (file_str == NULL) |
5008 return EXPAND_UNSUCCESSFUL; | |
5009 | |
2652 | 5010 if (p_wic) |
5011 options += WILD_ICASE; | |
5012 | |
7 | 5013 /* find all files that match the description */ |
2652 | 5014 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5015 { |
5016 *matchcount = 0; | |
5017 *matches = NULL; | |
5018 } | |
5019 vim_free(file_str); | |
5020 | |
5021 return EXPAND_OK; | |
5022 } | |
5023 | |
5024 #ifdef FEAT_MULTI_LANG | |
5025 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5026 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5027 * 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
|
5028 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5029 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5030 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5031 |
5032 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5033 cleanup_help_tags(int num_file, char_u **file) |
7 | 5034 { |
5035 int i, j; | |
5036 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5037 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5038 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5039 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5040 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
|
5041 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5042 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5043 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5044 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5045 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5046 *p = NUL; |
7 | 5047 |
5048 for (i = 0; i < num_file; ++i) | |
5049 { | |
5050 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
|
5051 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5052 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5053 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5054 { |
5055 /* Sorting on priority means the same item in another language may | |
5056 * be anywhere. Search all items for a match up to the "@en". */ | |
5057 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
|
5058 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
|
5059 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5060 break; |
5061 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5062 /* item only exists with @en, remove it */ |
7 | 5063 file[i][len] = NUL; |
5064 } | |
5065 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5066 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5067 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5068 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
|
5069 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5070 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5071 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5072 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5073 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
|
5074 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5075 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5076 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5077 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5078 } |
7 | 5079 } |
5080 #endif | |
5081 | |
5082 /* | |
5083 * Do the expansion based on xp->xp_context and "pat". | |
5084 */ | |
5085 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5086 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5087 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5088 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5089 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5090 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5091 int options) /* EW_ flags */ |
7 | 5092 { |
5093 #ifdef FEAT_CMDL_COMPL | |
5094 regmatch_T regmatch; | |
5095 #endif | |
5096 int ret; | |
5097 int flags; | |
5098 | |
5099 flags = EW_DIR; /* include directories */ | |
5100 if (options & WILD_LIST_NOTFOUND) | |
5101 flags |= EW_NOTFOUND; | |
5102 if (options & WILD_ADD_SLASH) | |
5103 flags |= EW_ADDSLASH; | |
5104 if (options & WILD_KEEP_ALL) | |
5105 flags |= EW_KEEPALL; | |
5106 if (options & WILD_SILENT) | |
5107 flags |= EW_SILENT; | |
6659 | 5108 if (options & WILD_ALLLINKS) |
5109 flags |= EW_ALLLINKS; | |
7 | 5110 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5111 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5112 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5113 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5114 { |
5115 /* | |
5116 * Expand file or directory names. | |
5117 */ | |
5118 int free_pat = FALSE; | |
5119 int i; | |
5120 | |
5121 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5122 * space */ | |
5123 if (xp->xp_backslash != XP_BS_NONE) | |
5124 { | |
5125 free_pat = TRUE; | |
5126 pat = vim_strsave(pat); | |
5127 for (i = 0; pat[i]; ++i) | |
5128 if (pat[i] == '\\') | |
5129 { | |
5130 if (xp->xp_backslash == XP_BS_THREE | |
5131 && pat[i + 1] == '\\' | |
5132 && pat[i + 2] == '\\' | |
5133 && pat[i + 3] == ' ') | |
1621 | 5134 STRMOVE(pat + i, pat + i + 3); |
7 | 5135 if (xp->xp_backslash == XP_BS_ONE |
5136 && pat[i + 1] == ' ') | |
1621 | 5137 STRMOVE(pat + i, pat + i + 1); |
7 | 5138 } |
5139 } | |
5140 | |
5141 if (xp->xp_context == EXPAND_FILES) | |
5142 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5143 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
|
5144 flags |= (EW_FILE | EW_PATH); |
7 | 5145 else |
5146 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5147 if (options & WILD_ICASE) |
5148 flags |= EW_ICASE; | |
5149 | |
2016 | 5150 /* Expand wildcards, supporting %:h and the like. */ |
5151 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5152 if (free_pat) |
5153 vim_free(pat); | |
5154 return ret; | |
5155 } | |
5156 | |
5157 *file = (char_u **)""; | |
5158 *num_file = 0; | |
5159 if (xp->xp_context == EXPAND_HELP) | |
5160 { | |
1696 | 5161 /* With an empty argument we would get all the help tags, which is |
5162 * very slow. Get matches for "help" instead. */ | |
5163 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5164 num_file, file, FALSE) == OK) | |
7 | 5165 { |
5166 #ifdef FEAT_MULTI_LANG | |
5167 cleanup_help_tags(*num_file, *file); | |
5168 #endif | |
5169 return OK; | |
5170 } | |
5171 return FAIL; | |
5172 } | |
5173 | |
5174 #ifndef FEAT_CMDL_COMPL | |
5175 return FAIL; | |
5176 #else | |
716 | 5177 if (xp->xp_context == EXPAND_SHELLCMD) |
5178 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5179 if (xp->xp_context == EXPAND_OLD_SETTING) |
5180 return ExpandOldSetting(num_file, file); | |
5181 if (xp->xp_context == EXPAND_BUFFERS) | |
5182 return ExpandBufnames(pat, num_file, file, options); | |
5183 if (xp->xp_context == EXPAND_TAGS | |
5184 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5185 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5186 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5187 { |
5188 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5189 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
|
5190 directories); |
2929 | 5191 } |
7 | 5192 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5193 { |
3106 | 5194 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5195 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5196 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5197 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5198 { |
5199 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5200 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5201 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5202 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5203 { |
5204 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
|
5205 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5206 } |
407 | 5207 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5208 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5209 return ExpandUserList(xp, num_file, file); |
407 | 5210 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5211 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5212 return ExpandPackAddDir(pat, num_file, file); |
7 | 5213 |
5214 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5215 if (regmatch.regprog == NULL) | |
5216 return FAIL; | |
5217 | |
5218 /* set ignore-case according to p_ic, p_scs and pat */ | |
5219 regmatch.rm_ic = ignorecase(pat); | |
5220 | |
5221 if (xp->xp_context == EXPAND_SETTINGS | |
5222 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5223 ret = ExpandSettings(xp, ®match, num_file, file); | |
5224 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5225 ret = ExpandMappings(®match, num_file, file); | |
5226 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5227 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5228 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5229 # endif | |
5230 else | |
5231 { | |
5232 static struct expgen | |
5233 { | |
5234 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5235 char_u *((*func)(expand_T *, int)); |
7 | 5236 int ic; |
2849 | 5237 int escaped; |
7 | 5238 } tab[] = |
5239 { | |
2849 | 5240 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5241 {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
|
5242 {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
|
5243 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5244 #ifdef FEAT_CMDHIST |
5245 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5246 #endif | |
7 | 5247 #ifdef FEAT_USR_CMDS |
2849 | 5248 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5249 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5250 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5251 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5252 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5253 #endif |
5254 #ifdef FEAT_EVAL | |
2849 | 5255 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5256 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5257 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5258 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5259 #endif |
5260 #ifdef FEAT_MENU | |
2849 | 5261 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5262 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5263 #endif |
5264 #ifdef FEAT_SYN_HL | |
2849 | 5265 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5266 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5267 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5268 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5269 #endif |
2849 | 5270 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5271 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5272 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5273 #ifdef FEAT_CSCOPE |
2849 | 5274 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5275 #endif |
1868 | 5276 #ifdef FEAT_SIGNS |
2849 | 5277 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5278 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5279 #ifdef FEAT_PROFILE |
2849 | 5280 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5281 #endif |
7 | 5282 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5283 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5284 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5285 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5286 #endif | |
5287 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5288 {EXPAND_USER, get_users, TRUE, FALSE}, |
13551
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5289 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5290 }; |
5291 int i; | |
5292 | |
5293 /* | |
5294 * Find a context in the table and call the ExpandGeneric() with the | |
5295 * right function to do the expansion. | |
5296 */ | |
5297 ret = FAIL; | |
1880 | 5298 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5299 if (xp->xp_context == tab[i].context) |
5300 { | |
5301 if (tab[i].ic) | |
5302 regmatch.rm_ic = TRUE; | |
2849 | 5303 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5304 tab[i].func, tab[i].escaped); |
7 | 5305 break; |
5306 } | |
5307 } | |
5308 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5309 vim_regfree(regmatch.regprog); |
7 | 5310 |
5311 return ret; | |
5312 #endif /* FEAT_CMDL_COMPL */ | |
5313 } | |
5314 | |
5315 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5316 /* | |
5317 * Expand a list of names. | |
5318 * | |
5319 * Generic function for command line completion. It calls a function to | |
5320 * obtain strings, one by one. The strings are matched against a regexp | |
5321 * program. Matching strings are copied into an array, which is returned. | |
5322 * | |
5323 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5324 */ | |
5325 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5326 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5327 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5328 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5329 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5330 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5331 char_u *((*func)(expand_T *, int)), |
7 | 5332 /* 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
|
5333 int escaped) |
7 | 5334 { |
5335 int i; | |
5336 int count = 0; | |
480 | 5337 int round; |
7 | 5338 char_u *str; |
5339 | |
5340 /* do this loop twice: | |
480 | 5341 * round == 0: count the number of matching names |
5342 * round == 1: copy the matching names into allocated memory | |
7 | 5343 */ |
480 | 5344 for (round = 0; round <= 1; ++round) |
7 | 5345 { |
5346 for (i = 0; ; ++i) | |
5347 { | |
5348 str = (*func)(xp, i); | |
5349 if (str == NULL) /* end of list */ | |
5350 break; | |
5351 if (*str == NUL) /* skip empty strings */ | |
5352 continue; | |
5353 | |
5354 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5355 { | |
480 | 5356 if (round) |
7 | 5357 { |
2849 | 5358 if (escaped) |
5359 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5360 else | |
5361 str = vim_strsave(str); | |
7 | 5362 (*file)[count] = str; |
5363 #ifdef FEAT_MENU | |
5364 if (func == get_menu_names && str != NULL) | |
5365 { | |
5366 /* test for separator added by get_menu_names() */ | |
5367 str += STRLEN(str) - 1; | |
5368 if (*str == '\001') | |
5369 *str = '.'; | |
5370 } | |
5371 #endif | |
5372 } | |
5373 ++count; | |
5374 } | |
5375 } | |
480 | 5376 if (round == 0) |
7 | 5377 { |
5378 if (count == 0) | |
5379 return OK; | |
5380 *num_file = count; | |
5381 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5382 if (*file == NULL) | |
5383 { | |
5384 *file = (char_u **)""; | |
5385 return FAIL; | |
5386 } | |
5387 count = 0; | |
5388 } | |
5389 } | |
480 | 5390 |
828 | 5391 /* Sort the results. Keep menu's in the specified order. */ |
5392 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5393 { |
5394 if (xp->xp_context == EXPAND_EXPRESSION | |
5395 || xp->xp_context == EXPAND_FUNCTIONS | |
5396 || xp->xp_context == EXPAND_USER_FUNC) | |
5397 /* <SNR> functions should be sorted to the end. */ | |
5398 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5399 sort_func_compare); | |
5400 else | |
5401 sort_strings(*file, *num_file); | |
5402 } | |
480 | 5403 |
1322 | 5404 #ifdef FEAT_CMDL_COMPL |
5405 /* Reset the variables used for special highlight names expansion, so that | |
5406 * they don't show up when getting normal highlight names by ID. */ | |
5407 reset_expand_highlight(); | |
5408 #endif | |
5409 | |
7 | 5410 return OK; |
5411 } | |
5412 | |
716 | 5413 /* |
5414 * Complete a shell command. | |
5415 * Returns FAIL or OK; | |
5416 */ | |
5417 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5418 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5419 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
|
5420 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
|
5421 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
|
5422 int flagsarg) /* EW_ flags */ |
716 | 5423 { |
5424 char_u *pat; | |
5425 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5426 char_u *path = NULL; |
716 | 5427 int mustfree = FALSE; |
5428 garray_T ga; | |
5429 char_u *buf = alloc(MAXPATHL); | |
5430 size_t l; | |
5431 char_u *s, *e; | |
5432 int flags = flagsarg; | |
5433 int ret; | |
6695 | 5434 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5435 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5436 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5437 hash_T hash; |
716 | 5438 |
5439 if (buf == NULL) | |
5440 return FAIL; | |
5441 | |
5442 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5443 * space */ | |
5444 pat = vim_strsave(filepat); | |
5445 for (i = 0; pat[i]; ++i) | |
5446 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5447 STRMOVE(pat + i, pat + i + 1); |
716 | 5448 |
6695 | 5449 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5450 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5451 if (pat[0] == '.' && (vim_ispathsep(pat[1]) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5452 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5453 path = (char_u *)"."; |
5454 else | |
2630 | 5455 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5456 /* For an absolute name we don't use $PATH. */ |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5457 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5458 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5459 if (path == NULL) |
5460 path = (char_u *)""; | |
5461 } | |
716 | 5462 |
5463 /* | |
5464 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5465 * collect them in "ga". When "." is not in $PATH also expand for the |
5466 * current directory, to find "subdir/cmd". | |
716 | 5467 */ |
5468 ga_init2(&ga, (int)sizeof(char *), 10); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5469 hash_init(&found_ht); |
6695 | 5470 for (s = path; ; s = e) |
716 | 5471 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5472 #if defined(MSWIN) |
716 | 5473 e = vim_strchr(s, ';'); |
5474 #else | |
5475 e = vim_strchr(s, ':'); | |
5476 #endif | |
5477 if (e == NULL) | |
5478 e = s + STRLEN(s); | |
5479 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5480 if (*s == NUL) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5481 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5482 if (did_curdir) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5483 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5484 // Find directories in the current directory, path is empty. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5485 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5486 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5487 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5488 else if (STRNCMP(s, ".", (int)(e - s)) == 0) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5489 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5490 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5491 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5492 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5493 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5494 // Do not match directories inside a $PATH item. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5495 flags &= ~EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5496 |
716 | 5497 l = e - s; |
5498 if (l > MAXPATHL - 5) | |
5499 break; | |
5500 vim_strncpy(buf, s, l); | |
5501 add_pathsep(buf); | |
5502 l = STRLEN(buf); | |
5503 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5504 | |
5505 /* Expand matches in one directory of $PATH. */ | |
5506 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5507 if (ret == OK) | |
5508 { | |
5509 if (ga_grow(&ga, *num_file) == FAIL) | |
5510 FreeWild(*num_file, *file); | |
5511 else | |
5512 { | |
5513 for (i = 0; i < *num_file; ++i) | |
5514 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5515 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5516 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5517 if (STRLEN(name) > l) |
716 | 5518 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5519 // Check if this name was already found. |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5520 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5521 hi = hash_lookup(&found_ht, name + l, hash); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5522 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5523 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5524 // Remove the path that was prepended. |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5525 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5526 ((char_u **)ga.ga_data)[ga.ga_len++] = name; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5527 hash_add_item(&found_ht, hi, name, hash); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5528 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5529 } |
716 | 5530 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5531 vim_free(name); |
716 | 5532 } |
5533 vim_free(*file); | |
5534 } | |
5535 } | |
5536 if (*e != NUL) | |
5537 ++e; | |
5538 } | |
5539 *file = ga.ga_data; | |
5540 *num_file = ga.ga_len; | |
5541 | |
5542 vim_free(buf); | |
5543 vim_free(pat); | |
5544 if (mustfree) | |
5545 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5546 hash_clear(&found_ht); |
716 | 5547 return OK; |
5548 } | |
5549 | |
5550 | |
7 | 5551 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5552 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5553 * 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
|
5554 * return the result (either a string or a List). |
7 | 5555 */ |
407 | 5556 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5557 call_user_expand_func( |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5558 void *(*user_expand_func)(char_u *, int, typval_T *), |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5559 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5560 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5561 char_u ***file) |
7 | 5562 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5563 int keep = 0; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5564 typval_T args[4]; |
7 | 5565 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5566 char_u *pat = NULL; |
407 | 5567 void *ret; |
13 | 5568 struct cmdline_info save_ccline; |
7 | 5569 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5570 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5571 return NULL; |
7 | 5572 *num_file = 0; |
5573 *file = NULL; | |
5574 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5575 if (ccline.cmdbuff != NULL) |
1518 | 5576 { |
5577 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5578 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5579 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5580 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5581 pat = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len); |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5582 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5583 args[0].v_type = VAR_STRING; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5584 args[0].vval.v_string = pat; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5585 args[1].v_type = VAR_STRING; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5586 args[1].vval.v_string = xp->xp_line; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5587 args[2].v_type = VAR_NUMBER; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5588 args[2].vval.v_number = xp->xp_col; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5589 args[3].v_type = VAR_UNKNOWN; |
7 | 5590 |
13 | 5591 /* Save the cmdline, we don't know what the function may do. */ |
5592 save_ccline = ccline; | |
5593 ccline.cmdbuff = NULL; | |
5594 ccline.cmdprompt = NULL; | |
7 | 5595 current_SID = xp->xp_scriptID; |
13 | 5596 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5597 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5598 |
5599 ccline = save_ccline; | |
7 | 5600 current_SID = save_current_SID; |
1518 | 5601 if (ccline.cmdbuff != NULL) |
5602 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5603 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5604 vim_free(pat); |
407 | 5605 return ret; |
5606 } | |
5607 | |
5608 /* | |
5609 * Expand names with a function defined by the user. | |
5610 */ | |
5611 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5612 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5613 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5614 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5615 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5616 char_u ***file) |
407 | 5617 { |
5618 char_u *retstr; | |
5619 char_u *s; | |
5620 char_u *e; | |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5621 int keep; |
407 | 5622 garray_T ga; |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5623 int skip; |
407 | 5624 |
5625 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5626 if (retstr == NULL) | |
7 | 5627 return FAIL; |
5628 | |
5629 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5630 for (s = retstr; *s != NUL; s = e) |
7 | 5631 { |
5632 e = vim_strchr(s, '\n'); | |
5633 if (e == NULL) | |
5634 e = s + STRLEN(s); | |
5635 keep = *e; | |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5636 *e = NUL; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5637 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5638 skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5639 *e = keep; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5640 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5641 if (!skip) |
7 | 5642 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5643 if (ga_grow(&ga, 1) == FAIL) |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5644 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5645 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s)); |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5646 ++ga.ga_len; |
7 | 5647 } |
5648 | |
5649 if (*e != NUL) | |
5650 ++e; | |
5651 } | |
407 | 5652 vim_free(retstr); |
5653 *file = ga.ga_data; | |
5654 *num_file = ga.ga_len; | |
5655 return OK; | |
5656 } | |
5657 | |
5658 /* | |
5659 * Expand names with a list returned by a function defined by the user. | |
5660 */ | |
5661 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5662 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5663 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5664 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5665 char_u ***file) |
407 | 5666 { |
5667 list_T *retlist; | |
5668 listitem_T *li; | |
5669 garray_T ga; | |
5670 | |
5671 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5672 if (retlist == NULL) | |
5673 return FAIL; | |
5674 | |
5675 ga_init2(&ga, (int)sizeof(char *), 3); | |
5676 /* Loop over the items in the list. */ | |
5677 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5678 { | |
1917 | 5679 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5680 continue; /* Skip non-string items and empty strings */ | |
407 | 5681 |
5682 if (ga_grow(&ga, 1) == FAIL) | |
5683 break; | |
5684 | |
5685 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5686 vim_strsave(li->li_tv.vval.v_string); |
407 | 5687 ++ga.ga_len; |
5688 } | |
5689 list_unref(retlist); | |
5690 | |
7 | 5691 *file = ga.ga_data; |
5692 *num_file = ga.ga_len; | |
5693 return OK; | |
5694 } | |
5695 #endif | |
5696 | |
5697 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5698 * 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
|
5699 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5700 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5701 * 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
|
5702 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5703 * 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
|
5704 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5705 * "dirnames" is an array with one or more directory names. |
7 | 5706 */ |
5707 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5708 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5709 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5711 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5712 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5713 char *dirnames[]) |
7 | 5714 { |
5715 char_u *s; | |
5716 char_u *e; | |
5873 | 5717 char_u *match; |
7 | 5718 garray_T ga; |
2929 | 5719 int i; |
5720 int pat_len; | |
7 | 5721 |
5722 *num_file = 0; | |
5723 *file = NULL; | |
2931 | 5724 pat_len = (int)STRLEN(pat); |
2929 | 5725 ga_init2(&ga, (int)sizeof(char *), 10); |
5726 | |
5727 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5728 { |
2929 | 5729 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5730 if (s == NULL) | |
5731 { | |
5732 ga_clear_strings(&ga); | |
5733 return FAIL; | |
5734 } | |
5735 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5736 globpath(p_rtp, s, &ga, 0); |
2929 | 5737 vim_free(s); |
5873 | 5738 } |
5739 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5740 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5741 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
|
5742 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5743 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
|
5744 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5745 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5746 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5747 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5748 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5749 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
|
5750 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5751 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5752 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5753 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5754 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5755 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5756 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
|
5757 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5758 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
|
5759 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5760 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5761 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5762 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5763 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5764 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
|
5765 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5766 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5767 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5768 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5769 |
5873 | 5770 for (i = 0; i < ga.ga_len; ++i) |
5771 { | |
5772 match = ((char_u **)ga.ga_data)[i]; | |
5773 s = match; | |
5774 e = s + STRLEN(s); | |
5775 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5776 { |
5873 | 5777 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5778 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5779 if (s < match || vim_ispathsep(*s)) |
5780 break; | |
5781 ++s; | |
5782 *e = NUL; | |
5783 mch_memmove(match, s, e - s + 1); | |
7 | 5784 } |
5785 } | |
5873 | 5786 |
2929 | 5787 if (ga.ga_len == 0) |
3628 | 5788 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5789 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5790 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5791 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5792 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5793 |
7 | 5794 *file = ga.ga_data; |
5795 *num_file = ga.ga_len; | |
5796 return OK; | |
5797 } | |
5798 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5799 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5800 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5801 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5802 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5803 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5804 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5805 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5806 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5807 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5808 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5809 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5810 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5811 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5815 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5816 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5817 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5818 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5819 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
|
5820 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5821 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5822 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5823 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5824 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5827 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
|
5828 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5830 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 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
|
5832 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5833 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
|
5834 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5835 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 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
|
5837 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5841 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5842 /* 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
|
5843 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5844 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5845 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5846 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5847 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5849 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5850 |
7 | 5851 #endif |
5852 | |
5853 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5854 /* | |
5855 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5856 * Adds the matches to "ga". Caller must init "ga". |
7 | 5857 */ |
5873 | 5858 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5859 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5860 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5861 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5862 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5863 int expand_options) |
7 | 5864 { |
5865 expand_T xpc; | |
5866 char_u *buf; | |
5867 int i; | |
5868 int num_p; | |
5869 char_u **p; | |
5870 | |
5871 buf = alloc(MAXPATHL); | |
5872 if (buf == NULL) | |
5873 | 5873 return; |
7 | 5874 |
632 | 5875 ExpandInit(&xpc); |
7 | 5876 xpc.xp_context = EXPAND_FILES; |
632 | 5877 |
7 | 5878 /* Loop over all entries in {path}. */ |
5879 while (*path != NUL) | |
5880 { | |
5881 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5882 copy_option_part(&path, buf, MAXPATHL, ","); | |
5883 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5884 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5885 # 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
|
5886 /* 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
|
5887 * 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
|
5888 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
|
5889 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5890 # else |
7 | 5891 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
|
5892 # endif |
7 | 5893 STRCAT(buf, file); |
1754 | 5894 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5895 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5896 { |
1754 | 5897 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5898 |
5899 if (ga_grow(ga, num_p) == OK) | |
7 | 5900 { |
5901 for (i = 0; i < num_p; ++i) | |
5902 { | |
5873 | 5903 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5904 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5905 ++ga->ga_len; |
7 | 5906 } |
5907 } | |
5873 | 5908 |
7 | 5909 FreeWild(num_p, p); |
5910 } | |
5911 } | |
5912 } | |
5913 | |
5914 vim_free(buf); | |
5915 } | |
5916 | |
5917 #endif | |
5918 | |
5919 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5920 | |
5921 /********************************* | |
5922 * Command line history stuff * | |
5923 *********************************/ | |
5924 | |
5925 /* | |
5926 * Translate a history character to the associated type number. | |
5927 */ | |
5928 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5929 hist_char2type(int c) |
7 | 5930 { |
5931 if (c == ':') | |
5932 return HIST_CMD; | |
5933 if (c == '=') | |
5934 return HIST_EXPR; | |
5935 if (c == '@') | |
5936 return HIST_INPUT; | |
5937 if (c == '>') | |
5938 return HIST_DEBUG; | |
5939 return HIST_SEARCH; /* must be '?' or '/' */ | |
5940 } | |
5941 | |
5942 /* | |
5943 * Table of history names. | |
5944 * These names are used in :history and various hist...() functions. | |
5945 * It is sufficient to give the significant prefix of a history name. | |
5946 */ | |
5947 | |
5948 static char *(history_names[]) = | |
5949 { | |
5950 "cmd", | |
5951 "search", | |
5952 "expr", | |
5953 "input", | |
5954 "debug", | |
5955 NULL | |
5956 }; | |
5957 | |
3503 | 5958 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5959 /* | |
5960 * Function given to ExpandGeneric() to obtain the possible first | |
5961 * arguments of the ":history command. | |
5962 */ | |
5963 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5964 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5965 { |
5966 static char_u compl[2] = { NUL, NUL }; | |
5967 char *short_names = ":=@>?/"; | |
3529 | 5968 int short_names_count = (int)STRLEN(short_names); |
3503 | 5969 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5970 | |
5971 if (idx < short_names_count) | |
5972 { | |
5973 compl[0] = (char_u)short_names[idx]; | |
5974 return compl; | |
5975 } | |
5976 if (idx < short_names_count + history_name_count) | |
5977 return (char_u *)history_names[idx - short_names_count]; | |
5978 if (idx == short_names_count + history_name_count) | |
5979 return (char_u *)"all"; | |
5980 return NULL; | |
5981 } | |
5982 #endif | |
5983 | |
7 | 5984 /* |
5985 * init_history() - Initialize the command line history. | |
5986 * Also used to re-allocate the history when the size changes. | |
5987 */ | |
356 | 5988 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5989 init_history(void) |
7 | 5990 { |
5991 int newlen; /* new length of history table */ | |
5992 histentry_T *temp; | |
5993 int i; | |
5994 int j; | |
5995 int type; | |
5996 | |
5997 /* | |
5998 * If size of history table changed, reallocate it | |
5999 */ | |
6000 newlen = (int)p_hi; | |
6001 if (newlen != hislen) /* history length changed */ | |
6002 { | |
6003 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6004 { | |
6005 if (newlen) | |
6006 { | |
6007 temp = (histentry_T *)lalloc( | |
6008 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6009 if (temp == NULL) /* out of memory! */ | |
6010 { | |
6011 if (type == 0) /* first one: just keep the old length */ | |
6012 { | |
6013 newlen = hislen; | |
6014 break; | |
6015 } | |
6016 /* Already changed one table, now we can only have zero | |
6017 * length for all tables. */ | |
6018 newlen = 0; | |
6019 type = -1; | |
6020 continue; | |
6021 } | |
6022 } | |
6023 else | |
6024 temp = NULL; | |
6025 if (newlen == 0 || temp != NULL) | |
6026 { | |
6027 if (hisidx[type] < 0) /* there are no entries yet */ | |
6028 { | |
6029 for (i = 0; i < newlen; ++i) | |
4258 | 6030 clear_hist_entry(&temp[i]); |
7 | 6031 } |
6032 else if (newlen > hislen) /* array becomes bigger */ | |
6033 { | |
6034 for (i = 0; i <= hisidx[type]; ++i) | |
6035 temp[i] = history[type][i]; | |
6036 j = i; | |
6037 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6038 clear_hist_entry(&temp[i]); |
7 | 6039 for ( ; j < hislen; ++i, ++j) |
6040 temp[i] = history[type][j]; | |
6041 } | |
6042 else /* array becomes smaller or 0 */ | |
6043 { | |
6044 j = hisidx[type]; | |
6045 for (i = newlen - 1; ; --i) | |
6046 { | |
6047 if (i >= 0) /* copy newest entries */ | |
6048 temp[i] = history[type][j]; | |
6049 else /* remove older entries */ | |
6050 vim_free(history[type][j].hisstr); | |
6051 if (--j < 0) | |
6052 j = hislen - 1; | |
6053 if (j == hisidx[type]) | |
6054 break; | |
6055 } | |
6056 hisidx[type] = newlen - 1; | |
6057 } | |
6058 vim_free(history[type]); | |
6059 history[type] = temp; | |
6060 } | |
6061 } | |
6062 hislen = newlen; | |
6063 } | |
6064 } | |
6065 | |
4258 | 6066 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6067 clear_hist_entry(histentry_T *hisptr) |
4258 | 6068 { |
6069 hisptr->hisnum = 0; | |
6070 hisptr->viminfo = FALSE; | |
6071 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6072 hisptr->time_set = 0; |
4258 | 6073 } |
6074 | |
7 | 6075 /* |
6076 * Check if command line 'str' is already in history. | |
6077 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6078 */ | |
6079 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6080 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6081 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6082 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6083 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
|
6084 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6085 int writing) /* ignore entries read from viminfo */ |
7 | 6086 { |
6087 int i; | |
6088 int last_i = -1; | |
2986 | 6089 char_u *p; |
7 | 6090 |
6091 if (hisidx[type] < 0) | |
6092 return FALSE; | |
6093 i = hisidx[type]; | |
6094 do | |
6095 { | |
6096 if (history[type][i].hisstr == NULL) | |
6097 return FALSE; | |
2986 | 6098 |
6099 /* For search history, check that the separator character matches as | |
6100 * well. */ | |
6101 p = history[type][i].hisstr; | |
6102 if (STRCMP(str, p) == 0 | |
4285 | 6103 && !(writing && history[type][i].viminfo) |
2986 | 6104 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6105 { |
6106 if (!move_to_front) | |
6107 return TRUE; | |
6108 last_i = i; | |
6109 break; | |
6110 } | |
6111 if (--i < 0) | |
6112 i = hislen - 1; | |
6113 } while (i != hisidx[type]); | |
6114 | |
6115 if (last_i >= 0) | |
6116 { | |
6117 str = history[type][i].hisstr; | |
6118 while (i != hisidx[type]) | |
6119 { | |
6120 if (++i >= hislen) | |
6121 i = 0; | |
6122 history[type][last_i] = history[type][i]; | |
6123 last_i = i; | |
6124 } | |
4258 | 6125 history[type][i].hisnum = ++hisnum[type]; |
6126 history[type][i].viminfo = FALSE; | |
7 | 6127 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6128 history[type][i].time_set = vim_time(); |
7 | 6129 return TRUE; |
6130 } | |
6131 return FALSE; | |
6132 } | |
6133 | |
6134 /* | |
6135 * Convert history name (from table above) to its HIST_ equivalent. | |
6136 * When "name" is empty, return "cmd" history. | |
6137 * Returns -1 for unknown history name. | |
6138 */ | |
6139 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6140 get_histtype(char_u *name) |
7 | 6141 { |
6142 int i; | |
6143 int len = (int)STRLEN(name); | |
6144 | |
6145 /* No argument: use current history. */ | |
6146 if (len == 0) | |
6147 return hist_char2type(ccline.cmdfirstc); | |
6148 | |
6149 for (i = 0; history_names[i] != NULL; ++i) | |
6150 if (STRNICMP(name, history_names[i], len) == 0) | |
6151 return i; | |
6152 | |
6153 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6154 return hist_char2type(name[0]); | |
6155 | |
6156 return -1; | |
6157 } | |
6158 | |
6159 static int last_maptick = -1; /* last seen maptick */ | |
6160 | |
6161 /* | |
6162 * Add the given string to the given history. If the string is already in the | |
6163 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6164 * values. | |
6165 */ | |
6166 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6167 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6168 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6169 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6170 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
|
6171 int sep) /* separator character used (search hist) */ |
7 | 6172 { |
6173 histentry_T *hisptr; | |
6174 int len; | |
6175 | |
6176 if (hislen == 0) /* no history */ | |
6177 return; | |
6178 | |
5467 | 6179 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6180 return; | |
6181 | |
7 | 6182 /* |
6183 * Searches inside the same mapping overwrite each other, so that only | |
6184 * the last line is kept. Be careful not to remove a line that was moved | |
6185 * down, only lines that were added. | |
6186 */ | |
6187 if (histype == HIST_SEARCH && in_map) | |
6188 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6189 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6190 { |
6191 /* Current line is from the same mapping, remove it */ | |
6192 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6193 vim_free(hisptr->hisstr); | |
4258 | 6194 clear_hist_entry(hisptr); |
7 | 6195 --hisnum[histype]; |
6196 if (--hisidx[HIST_SEARCH] < 0) | |
6197 hisidx[HIST_SEARCH] = hislen - 1; | |
6198 } | |
6199 last_maptick = -1; | |
6200 } | |
4285 | 6201 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6202 { |
6203 if (++hisidx[histype] == hislen) | |
6204 hisidx[histype] = 0; | |
6205 hisptr = &history[histype][hisidx[histype]]; | |
6206 vim_free(hisptr->hisstr); | |
6207 | |
6208 /* Store the separator after the NUL of the string. */ | |
835 | 6209 len = (int)STRLEN(new_entry); |
7 | 6210 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6211 if (hisptr->hisstr != NULL) | |
6212 hisptr->hisstr[len + 1] = sep; | |
6213 | |
6214 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6215 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6216 hisptr->time_set = vim_time(); |
7 | 6217 if (histype == HIST_SEARCH && in_map) |
6218 last_maptick = maptick; | |
6219 } | |
6220 } | |
6221 | |
6222 #if defined(FEAT_EVAL) || defined(PROTO) | |
6223 | |
6224 /* | |
6225 * Get identifier of newest history entry. | |
6226 * "histype" may be one of the HIST_ values. | |
6227 */ | |
6228 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6229 get_history_idx(int histype) |
7 | 6230 { |
6231 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6232 || hisidx[histype] < 0) | |
6233 return -1; | |
6234 | |
6235 return history[histype][hisidx[histype]].hisnum; | |
6236 } | |
6237 | |
531 | 6238 /* |
7 | 6239 * Calculate history index from a number: |
6240 * num > 0: seen as identifying number of a history entry | |
6241 * num < 0: relative position in history wrt newest entry | |
6242 * "histype" may be one of the HIST_ values. | |
6243 */ | |
6244 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6245 calc_hist_idx(int histype, int num) |
7 | 6246 { |
6247 int i; | |
6248 histentry_T *hist; | |
6249 int wrapped = FALSE; | |
6250 | |
6251 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6252 || (i = hisidx[histype]) < 0 || num == 0) | |
6253 return -1; | |
6254 | |
6255 hist = history[histype]; | |
6256 if (num > 0) | |
6257 { | |
6258 while (hist[i].hisnum > num) | |
6259 if (--i < 0) | |
6260 { | |
6261 if (wrapped) | |
6262 break; | |
6263 i += hislen; | |
6264 wrapped = TRUE; | |
6265 } | |
6266 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6267 return i; | |
6268 } | |
6269 else if (-num <= hislen) | |
6270 { | |
6271 i += num + 1; | |
6272 if (i < 0) | |
6273 i += hislen; | |
6274 if (hist[i].hisstr != NULL) | |
6275 return i; | |
6276 } | |
6277 return -1; | |
6278 } | |
6279 | |
6280 /* | |
6281 * Get a history entry by its index. | |
6282 * "histype" may be one of the HIST_ values. | |
6283 */ | |
6284 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6285 get_history_entry(int histype, int idx) |
7 | 6286 { |
6287 idx = calc_hist_idx(histype, idx); | |
6288 if (idx >= 0) | |
6289 return history[histype][idx].hisstr; | |
6290 else | |
6291 return (char_u *)""; | |
6292 } | |
6293 | |
6294 /* | |
6295 * Clear all entries of a history. | |
6296 * "histype" may be one of the HIST_ values. | |
6297 */ | |
6298 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6299 clr_history(int histype) |
7 | 6300 { |
6301 int i; | |
6302 histentry_T *hisptr; | |
6303 | |
6304 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6305 { | |
6306 hisptr = history[histype]; | |
6307 for (i = hislen; i--;) | |
6308 { | |
6309 vim_free(hisptr->hisstr); | |
4258 | 6310 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6311 hisptr++; |
7 | 6312 } |
6313 hisidx[histype] = -1; /* mark history as cleared */ | |
6314 hisnum[histype] = 0; /* reset identifier counter */ | |
6315 return OK; | |
6316 } | |
6317 return FAIL; | |
6318 } | |
6319 | |
6320 /* | |
6321 * Remove all entries matching {str} from a history. | |
6322 * "histype" may be one of the HIST_ values. | |
6323 */ | |
6324 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6325 del_history_entry(int histype, char_u *str) |
7 | 6326 { |
6327 regmatch_T regmatch; | |
6328 histentry_T *hisptr; | |
6329 int idx; | |
6330 int i; | |
6331 int last; | |
6332 int found = FALSE; | |
6333 | |
6334 regmatch.regprog = NULL; | |
6335 regmatch.rm_ic = FALSE; /* always match case */ | |
6336 if (hislen != 0 | |
6337 && histype >= 0 | |
6338 && histype < HIST_COUNT | |
6339 && *str != NUL | |
6340 && (idx = hisidx[histype]) >= 0 | |
6341 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6342 != NULL) | |
6343 { | |
6344 i = last = idx; | |
6345 do | |
6346 { | |
6347 hisptr = &history[histype][i]; | |
6348 if (hisptr->hisstr == NULL) | |
6349 break; | |
6350 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6351 { | |
6352 found = TRUE; | |
6353 vim_free(hisptr->hisstr); | |
4258 | 6354 clear_hist_entry(hisptr); |
7 | 6355 } |
6356 else | |
6357 { | |
6358 if (i != last) | |
6359 { | |
6360 history[histype][last] = *hisptr; | |
4258 | 6361 clear_hist_entry(hisptr); |
7 | 6362 } |
6363 if (--last < 0) | |
6364 last += hislen; | |
6365 } | |
6366 if (--i < 0) | |
6367 i += hislen; | |
6368 } while (i != idx); | |
6369 if (history[histype][idx].hisstr == NULL) | |
6370 hisidx[histype] = -1; | |
6371 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6372 vim_regfree(regmatch.regprog); |
7 | 6373 return found; |
6374 } | |
6375 | |
6376 /* | |
6377 * Remove an indexed entry from a history. | |
6378 * "histype" may be one of the HIST_ values. | |
6379 */ | |
6380 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6381 del_history_idx(int histype, int idx) |
7 | 6382 { |
6383 int i, j; | |
6384 | |
6385 i = calc_hist_idx(histype, idx); | |
6386 if (i < 0) | |
6387 return FALSE; | |
6388 idx = hisidx[histype]; | |
6389 vim_free(history[histype][i].hisstr); | |
6390 | |
6391 /* When deleting the last added search string in a mapping, reset | |
6392 * last_maptick, so that the last added search string isn't deleted again. | |
6393 */ | |
6394 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6395 last_maptick = -1; | |
6396 | |
6397 while (i != idx) | |
6398 { | |
6399 j = (i + 1) % hislen; | |
6400 history[histype][i] = history[histype][j]; | |
6401 i = j; | |
6402 } | |
4258 | 6403 clear_hist_entry(&history[histype][i]); |
7 | 6404 if (--i < 0) |
6405 i += hislen; | |
6406 hisidx[histype] = i; | |
6407 return TRUE; | |
6408 } | |
6409 | |
6410 #endif /* FEAT_EVAL */ | |
6411 | |
6412 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6413 /* | |
6414 * Very specific function to remove the value in ":set key=val" from the | |
6415 * history. | |
6416 */ | |
6417 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6418 remove_key_from_history(void) |
7 | 6419 { |
6420 char_u *p; | |
6421 int i; | |
6422 | |
6423 i = hisidx[HIST_CMD]; | |
6424 if (i < 0) | |
6425 return; | |
6426 p = history[HIST_CMD][i].hisstr; | |
6427 if (p != NULL) | |
6428 for ( ; *p; ++p) | |
6429 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6430 { | |
6431 p = vim_strchr(p + 3, '='); | |
6432 if (p == NULL) | |
6433 break; | |
6434 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6435 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6436 if (p[i] == '\\' && p[i + 1]) |
6437 ++i; | |
1621 | 6438 STRMOVE(p, p + i); |
7 | 6439 --p; |
6440 } | |
6441 } | |
6442 #endif | |
6443 | |
6444 #endif /* FEAT_CMDHIST */ | |
6445 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6446 #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
|
6447 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6448 * 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
|
6449 * 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
|
6450 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6453 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6455 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6456 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6457 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 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
|
6459 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6462 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6463 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6464 #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
|
6465 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 * 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
|
6467 * 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
|
6468 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6472 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 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
|
6474 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6475 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 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
|
6478 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 * 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
|
6482 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 * 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
|
6484 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6486 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6487 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6488 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6489 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
|
6490 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6495 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6496 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 * 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
|
6498 * 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
|
6499 * 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
|
6500 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6501 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6503 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6504 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 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
|
6506 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6507 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6509 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6510 /* 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
|
6511 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6512 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6513 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6514 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6515 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6516 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6517 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6519 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 #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
|
6521 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6522 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6524 * 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
|
6525 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6526 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6527 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6528 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6529 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 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
|
6531 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6532 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6533 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6534 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6535 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6536 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6537 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6538 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6539 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6541 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6542 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6543 |
7 | 6544 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6545 /* | |
6546 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6547 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6548 * Returns OK if parsed successfully, otherwise FAIL. | |
6549 */ | |
6550 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6551 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6552 { |
6553 int len; | |
6554 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6555 varnumber_T num; |
7 | 6556 |
6557 *str = skipwhite(*str); | |
6558 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6559 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6560 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6561 *str += len; |
6562 *num1 = (int)num; | |
6563 first = TRUE; | |
6564 } | |
6565 *str = skipwhite(*str); | |
6566 if (**str == ',') /* parse "to" part of range */ | |
6567 { | |
6568 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6569 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6570 if (len > 0) |
6571 { | |
6572 *num2 = (int)num; | |
6573 *str = skipwhite(*str + len); | |
6574 } | |
6575 else if (!first) /* no number given at all */ | |
6576 return FAIL; | |
6577 } | |
6578 else if (first) /* only one number given */ | |
6579 *num2 = *num1; | |
6580 return OK; | |
6581 } | |
6582 #endif | |
6583 | |
6584 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6585 /* | |
6586 * :history command - print a history | |
6587 */ | |
6588 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6589 ex_history(exarg_T *eap) |
7 | 6590 { |
6591 histentry_T *hist; | |
6592 int histype1 = HIST_CMD; | |
6593 int histype2 = HIST_CMD; | |
6594 int hisidx1 = 1; | |
6595 int hisidx2 = -1; | |
6596 int idx; | |
6597 int i, j, k; | |
6598 char_u *end; | |
6599 char_u *arg = eap->arg; | |
6600 | |
6601 if (hislen == 0) | |
6602 { | |
6603 MSG(_("'history' option is zero")); | |
6604 return; | |
6605 } | |
6606 | |
6607 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6608 { | |
6609 end = arg; | |
6610 while (ASCII_ISALPHA(*end) | |
6611 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6612 end++; | |
6613 i = *end; | |
6614 *end = NUL; | |
6615 histype1 = get_histtype(arg); | |
6616 if (histype1 == -1) | |
6617 { | |
1853 | 6618 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6619 { |
6620 histype1 = 0; | |
6621 histype2 = HIST_COUNT-1; | |
6622 } | |
6623 else | |
6624 { | |
6625 *end = i; | |
6626 EMSG(_(e_trailing)); | |
6627 return; | |
6628 } | |
6629 } | |
6630 else | |
6631 histype2 = histype1; | |
6632 *end = i; | |
6633 } | |
6634 else | |
6635 end = arg; | |
6636 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6637 { | |
6638 EMSG(_(e_trailing)); | |
6639 return; | |
6640 } | |
6641 | |
6642 for (; !got_int && histype1 <= histype2; ++histype1) | |
6643 { | |
6644 STRCPY(IObuff, "\n # "); | |
6645 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6646 MSG_PUTS_TITLE(IObuff); | |
6647 idx = hisidx[histype1]; | |
6648 hist = history[histype1]; | |
6649 j = hisidx1; | |
6650 k = hisidx2; | |
6651 if (j < 0) | |
6652 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6653 if (k < 0) | |
6654 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6655 if (idx >= 0 && j <= k) | |
6656 for (i = idx + 1; !got_int; ++i) | |
6657 { | |
6658 if (i == hislen) | |
6659 i = 0; | |
6660 if (hist[i].hisstr != NULL | |
6661 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6662 { | |
6663 msg_putchar('\n'); | |
6664 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6665 hist[i].hisnum); | |
6666 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6667 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6668 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6669 else |
6670 STRCAT(IObuff, hist[i].hisstr); | |
6671 msg_outtrans(IObuff); | |
6672 out_flush(); | |
6673 } | |
6674 if (i == idx) | |
6675 break; | |
6676 } | |
6677 } | |
6678 } | |
6679 #endif | |
6680 | |
6681 #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
|
6682 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6683 * 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
|
6684 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6685 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
|
6686 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6687 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
|
6688 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6689 static int viminfo_add_at_front = FALSE; |
6690 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6691 static int hist_type2char(int type, int use_question); |
7 | 6692 |
6693 /* | |
6694 * Translate a history type number to the associated character. | |
6695 */ | |
6696 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6697 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6698 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6699 int use_question) /* use '?' instead of '/' */ |
7 | 6700 { |
6701 if (type == HIST_CMD) | |
6702 return ':'; | |
6703 if (type == HIST_SEARCH) | |
6704 { | |
6705 if (use_question) | |
6706 return '?'; | |
6707 else | |
6708 return '/'; | |
6709 } | |
6710 if (type == HIST_EXPR) | |
6711 return '='; | |
6712 return '@'; | |
6713 } | |
6714 | |
6715 /* | |
6716 * Prepare for reading the history from the viminfo file. | |
6717 * This allocates history arrays to store the read history lines. | |
6718 */ | |
6719 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6720 prepare_viminfo_history(int asklen, int writing) |
7 | 6721 { |
6722 int i; | |
6723 int num; | |
6724 int type; | |
6725 int len; | |
6726 | |
6727 init_history(); | |
4285 | 6728 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6729 if (asklen > hislen) |
6730 asklen = hislen; | |
6731 | |
6732 for (type = 0; type < HIST_COUNT; ++type) | |
6733 { | |
4258 | 6734 /* Count the number of empty spaces in the history list. Entries read |
6735 * from viminfo previously are also considered empty. If there are | |
6736 * more spaces available than we request, then fill them up. */ | |
7 | 6737 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6738 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6739 num++; |
6740 len = asklen; | |
6741 if (num > len) | |
6742 len = num; | |
6743 if (len <= 0) | |
6744 viminfo_history[type] = NULL; | |
6745 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6746 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6747 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6748 if (viminfo_history[type] == NULL) |
6749 len = 0; | |
6750 viminfo_hislen[type] = len; | |
6751 viminfo_hisidx[type] = 0; | |
6752 } | |
6753 } | |
6754 | |
6755 /* | |
6756 * Accept a line from the viminfo, store it in the history array when it's | |
6757 * new. | |
6758 */ | |
6759 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6760 read_viminfo_history(vir_T *virp, int writing) |
7 | 6761 { |
6762 int type; | |
6763 long_u len; | |
6764 char_u *val; | |
6765 char_u *p; | |
6766 | |
6767 type = hist_char2type(virp->vir_line[0]); | |
6768 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6769 { | |
6770 val = viminfo_readstring(virp, 1, TRUE); | |
6771 if (val != NULL && *val != NUL) | |
6772 { | |
3316 | 6773 int sep = (*val == ' ' ? NUL : *val); |
6774 | |
7 | 6775 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6776 viminfo_add_at_front, sep, writing)) |
7 | 6777 { |
6778 /* Need to re-allocate to append the separator byte. */ | |
6779 len = STRLEN(val); | |
6780 p = lalloc(len + 2, TRUE); | |
6781 if (p != NULL) | |
6782 { | |
6783 if (type == HIST_SEARCH) | |
6784 { | |
6785 /* Search entry: Move the separator from the first | |
6786 * column to after the NUL. */ | |
6787 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6788 p[len] = sep; |
7 | 6789 } |
6790 else | |
6791 { | |
6792 /* Not a search entry: No separator in the viminfo | |
6793 * file, add a NUL separator. */ | |
6794 mch_memmove(p, val, (size_t)len + 1); | |
6795 p[len + 1] = NUL; | |
6796 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6797 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
|
6798 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
|
6799 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
|
6800 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
|
6801 viminfo_hisidx[type]++; |
7 | 6802 } |
6803 } | |
6804 } | |
6805 vim_free(val); | |
6806 } | |
6807 return viminfo_readline(virp); | |
6808 } | |
6809 | |
4285 | 6810 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 * 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
|
6812 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6813 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6815 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6816 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6817 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6819 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6820 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6821 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6823 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
|
6824 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6827 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6828 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6829 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6830 || (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
|
6831 || 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
|
6832 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6834 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6837 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
|
6838 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6839 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6841 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6842 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
|
6843 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6844 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6845 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6846 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 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
|
6848 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 /* 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
|
6850 * 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
|
6851 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
|
6852 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6855 && (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
|
6856 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6857 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6858 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6859 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6862 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6863 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6864 /* 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
|
6865 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6866 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6868 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6869 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6870 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6871 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6872 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
|
6873 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6874 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6875 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
|
6876 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6877 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6878 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
|
6879 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 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
|
6881 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6882 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6883 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6885 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6886 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6887 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6888 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6889 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 * 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
|
6891 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 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
|
6921 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 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
|
6924 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 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
|
6926 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 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
|
6932 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 #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
|
6939 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 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
|
6944 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 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
|
6949 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
|
6950 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 * 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
|
6956 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6958 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6962 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6965 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 /* 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
|
6968 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 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
|
6970 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
|
6971 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
|
6972 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 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
|
6978 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
|
6979 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6982 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6983 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6984 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6985 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
|
6986 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6990 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6991 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6993 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6996 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6997 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6999 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7000 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
|
7001 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7003 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
|
7004 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
|
7005 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7007 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7008 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7009 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7010 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7011 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7012 /* |
4285 | 7013 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7014 */ | |
7 | 7015 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 finish_viminfo_history(vir_T *virp) |
7 | 7017 { |
7018 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7020 |
7021 for (type = 0; type < HIST_COUNT; ++type) | |
7022 { | |
7023 if (history[type] == NULL) | |
4283 | 7024 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7025 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7026 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7027 merge_history(type); |
7 | 7028 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7029 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7030 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7031 VIM_CLEAR(viminfo_history[type]); |
4327 | 7032 viminfo_hisidx[type] = 0; |
7 | 7033 } |
7034 } | |
7035 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7036 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7037 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7038 * 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
|
7039 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7040 * 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
|
7041 */ |
7 | 7042 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7043 write_viminfo_history(FILE *fp, int merge) |
7 | 7044 { |
7045 int i; | |
7046 int type; | |
7047 int num_saved; | |
4283 | 7048 int round; |
7 | 7049 |
7050 init_history(); | |
7051 if (hislen == 0) | |
7052 return; | |
7053 for (type = 0; type < HIST_COUNT; ++type) | |
7054 { | |
7055 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7056 if (num_saved == 0) | |
7057 continue; | |
7058 if (num_saved < 0) /* Use default */ | |
7059 num_saved = hislen; | |
7060 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7061 type == HIST_CMD ? _("Command Line") : | |
7062 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7063 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7064 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7065 _("Debug Line")); |
7 | 7066 if (num_saved > hislen) |
7067 num_saved = hislen; | |
4283 | 7068 |
7069 /* | |
7070 * Merge typed and viminfo history: | |
7071 * round 1: history of typed commands. | |
7072 * round 2: history from recently read viminfo. | |
7073 */ | |
7074 for (round = 1; round <= 2; ++round) | |
7075 { | |
4307 | 7076 if (round == 1) |
7077 /* start at newest entry, somewhere in the list */ | |
7078 i = hisidx[type]; | |
7079 else if (viminfo_hisidx[type] > 0) | |
7080 /* start at newest entry, first in the list */ | |
7081 i = 0; | |
7082 else | |
7083 /* empty list */ | |
7084 i = -1; | |
4283 | 7085 if (i >= 0) |
7086 while (num_saved > 0 | |
7087 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7088 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7089 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7090 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7091 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7092 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7093 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7094 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7095 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7096 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7097 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7098 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7099 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7100 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7101 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7102 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7103 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7104 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7105 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7106 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7107 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7108 || !history[type][i].viminfo)) |
7 | 7109 { |
4283 | 7110 --num_saved; |
7111 fputc(hist_type2char(type, TRUE), fp); | |
7112 /* For the search history: put the separator in the | |
7113 * second column; use a space if there isn't one. */ | |
7114 if (type == HIST_SEARCH) | |
7115 { | |
7116 c = p[STRLEN(p) + 1]; | |
7117 putc(c == NUL ? ' ' : c, fp); | |
7118 } | |
7119 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7120 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7121 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7122 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7123 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7124 /* 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
|
7125 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7126 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7127 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7128 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7129 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7130 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
|
7131 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7132 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7133 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7134 } |
7 | 7135 } |
4283 | 7136 if (round == 1) |
7137 { | |
7138 /* Decrement index, loop around and stop when back at | |
7139 * the start. */ | |
7140 if (--i < 0) | |
7141 i = hislen - 1; | |
7142 if (i == hisidx[type]) | |
7143 break; | |
7144 } | |
7145 else | |
7146 { | |
7147 /* Increment index. Stop at the end in the while. */ | |
7148 ++i; | |
7149 } | |
7 | 7150 } |
4283 | 7151 } |
4285 | 7152 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7153 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7154 vim_free(viminfo_history[type][i].hisstr); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7155 VIM_CLEAR(viminfo_history[type]); |
4311 | 7156 viminfo_hisidx[type] = 0; |
7 | 7157 } |
7158 } | |
7159 #endif /* FEAT_VIMINFO */ | |
7160 | |
7161 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7162 /* | |
7163 * Write a character at the current cursor+offset position. | |
7164 * It is directly written into the command buffer block. | |
7165 */ | |
7166 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7167 cmd_pchar(int c, int offset) |
7 | 7168 { |
7169 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7170 { | |
7171 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7172 return; | |
7173 } | |
7174 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7175 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7176 } | |
7177 | |
7178 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7179 cmd_gchar(int offset) |
7 | 7180 { |
7181 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7182 { | |
7183 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7184 return NUL; | |
7185 } | |
7186 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7187 } | |
7188 #endif | |
7189 | |
7190 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7191 /* | |
7192 * Open a window on the current command line and history. Allow editing in | |
7193 * the window. Returns when the window is closed. | |
7194 * Returns: | |
7195 * CR if the command is to be executed | |
7196 * Ctrl_C if it is to be abandoned | |
7197 * K_IGNORE if editing continues | |
7198 */ | |
7199 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
|
7200 open_cmdwin(void) |
7 | 7201 { |
7202 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7203 bufref_T old_curbuf; |
7 | 7204 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7205 bufref_T bufref; |
7 | 7206 win_T *wp; |
7207 int i; | |
7208 linenr_T lnum; | |
7209 int histtype; | |
7210 garray_T winsizes; | |
7211 int save_restart_edit = restart_edit; | |
7212 int save_State = State; | |
7213 int save_exmode = exmode_active; | |
510 | 7214 #ifdef FEAT_RIGHTLEFT |
7215 int save_cmdmsg_rl = cmdmsg_rl; | |
7216 #endif | |
6145 | 7217 #ifdef FEAT_FOLDING |
7218 int save_KeyTyped; | |
7219 #endif | |
7 | 7220 |
7221 /* Can't do this recursively. Can't do it when typing a password. */ | |
7222 if (cmdwin_type != 0 | |
7223 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7224 || cmdline_star > 0 | |
7225 # endif | |
7226 ) | |
7227 { | |
7228 beep_flush(); | |
7229 return K_IGNORE; | |
7230 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7231 set_bufref(&old_curbuf, curbuf); |
7 | 7232 |
7233 /* Save current window sizes. */ | |
7234 win_size_save(&winsizes); | |
7235 | |
7236 /* Don't execute autocommands while creating the window. */ | |
1410 | 7237 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7238 |
683 | 7239 /* don't use a new tab page */ |
7240 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
|
7241 cmdmod.noswapfile = 1; |
683 | 7242 |
7 | 7243 /* Create a window for the command-line buffer. */ |
7244 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7245 { | |
7246 beep_flush(); | |
1410 | 7247 unblock_autocmds(); |
7 | 7248 return K_IGNORE; |
7249 } | |
1831 | 7250 cmdwin_type = get_cmdline_type(); |
7 | 7251 |
7252 /* Create the command-line buffer empty. */ | |
1743 | 7253 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7254 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7255 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7256 curbuf->b_p_ma = TRUE; | |
1865 | 7257 #ifdef FEAT_FOLDING |
7258 curwin->w_p_fen = FALSE; | |
7259 #endif | |
7 | 7260 # ifdef FEAT_RIGHTLEFT |
510 | 7261 curwin->w_p_rl = cmdmsg_rl; |
7262 cmdmsg_rl = FALSE; | |
7 | 7263 # endif |
2583 | 7264 RESET_BINDING(curwin); |
7 | 7265 |
7266 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7267 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7268 /* 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
|
7269 ++curbuf_lock; |
7 | 7270 |
510 | 7271 /* Showing the prompt may have set need_wait_return, reset it. */ |
7272 need_wait_return = FALSE; | |
7273 | |
1831 | 7274 histtype = hist_char2type(cmdwin_type); |
7 | 7275 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7276 { | |
7277 if (p_wc == TAB) | |
7278 { | |
7279 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7280 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7281 } | |
7282 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7283 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7284 --curbuf_lock; |
7 | 7285 |
10 | 7286 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7287 * sets 'textwidth' to 78). */ | |
7288 curbuf->b_p_tw = 0; | |
7289 | |
7 | 7290 /* Fill the buffer with the history. */ |
7291 init_history(); | |
7292 if (hislen > 0) | |
7293 { | |
7294 i = hisidx[histtype]; | |
7295 if (i >= 0) | |
7296 { | |
7297 lnum = 0; | |
7298 do | |
7299 { | |
7300 if (++i == hislen) | |
7301 i = 0; | |
7302 if (history[histtype][i].hisstr != NULL) | |
7303 ml_append(lnum++, history[histtype][i].hisstr, | |
7304 (colnr_T)0, FALSE); | |
7305 } | |
7306 while (i != hisidx[histtype]); | |
7307 } | |
7308 } | |
7309 | |
7310 /* Replace the empty last line with the current command-line and put the | |
7311 * cursor there. */ | |
7312 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7313 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7314 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7315 changed_line_abv_curs(); |
7316 invalidate_botline(); | |
743 | 7317 redraw_later(SOME_VALID); |
7 | 7318 |
7319 /* 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
|
7320 save_cmdline(&save_ccline); |
7 | 7321 |
7322 /* No Ex mode here! */ | |
7323 exmode_active = 0; | |
7324 | |
7325 State = NORMAL; | |
7326 # ifdef FEAT_MOUSE | |
7327 setmouse(); | |
7328 # endif | |
7329 | |
7330 /* 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
|
7331 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7332 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7333 stuffcharReadbuff(K_NOP); | |
7 | 7334 |
7335 i = RedrawingDisabled; | |
7336 RedrawingDisabled = 0; | |
7337 | |
7338 /* | |
7339 * Call the main loop until <CR> or CTRL-C is typed. | |
7340 */ | |
7341 cmdwin_result = 0; | |
168 | 7342 main_loop(TRUE, FALSE); |
7 | 7343 |
7344 RedrawingDisabled = i; | |
7345 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7346 # ifdef FEAT_FOLDING |
6145 | 7347 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7348 # endif |
6145 | 7349 |
7 | 7350 /* 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
|
7351 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7352 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7353 # ifdef FEAT_FOLDING |
6145 | 7354 /* Restore KeyTyped in case it is modified by autocommands */ |
7355 KeyTyped = save_KeyTyped; | |
7 | 7356 # endif |
7357 | |
1214 | 7358 /* 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
|
7359 restore_cmdline(&save_ccline); |
7 | 7360 cmdwin_type = 0; |
7361 | |
7362 exmode_active = save_exmode; | |
7363 | |
1612 | 7364 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7365 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7366 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7367 { |
7368 cmdwin_result = Ctrl_C; | |
7369 EMSG(_("E199: Active window or buffer deleted")); | |
7370 } | |
7371 else | |
7372 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7373 # if defined(FEAT_EVAL) |
7 | 7374 /* autocmds may abort script processing */ |
7375 if (aborting() && cmdwin_result != K_IGNORE) | |
7376 cmdwin_result = Ctrl_C; | |
7377 # endif | |
7378 /* Set the new command line from the cmdline buffer. */ | |
7379 vim_free(ccline.cmdbuff); | |
510 | 7380 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7381 { |
510 | 7382 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7383 | |
7384 if (histtype == HIST_CMD) | |
7385 { | |
7386 /* Execute the command directly. */ | |
7387 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7388 cmdwin_result = CAR; | |
7389 } | |
7390 else | |
7391 { | |
7392 /* First need to cancel what we were doing. */ | |
7393 ccline.cmdbuff = NULL; | |
7394 stuffcharReadbuff(':'); | |
7395 stuffReadbuff((char_u *)p); | |
7396 stuffcharReadbuff(CAR); | |
7397 } | |
7 | 7398 } |
7399 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7400 { | |
7401 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7402 cmdwin_result = CAR; | |
7403 } | |
2839 | 7404 else if (cmdwin_result == Ctrl_C) |
7405 { | |
7406 /* :q or :close, don't execute any command | |
7407 * and don't modify the cmd window. */ | |
7408 ccline.cmdbuff = NULL; | |
7409 } | |
7 | 7410 else |
7411 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7412 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
|
7413 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7414 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
|
7415 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
|
7416 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
|
7417 ccline.cmdpos = 0; |
7 | 7418 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
|
7419 } |
7 | 7420 else |
7421 { | |
7422 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7423 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7424 ccline.cmdpos = curwin->w_cursor.col; | |
7425 if (ccline.cmdpos > ccline.cmdlen) | |
7426 ccline.cmdpos = ccline.cmdlen; | |
7427 if (cmdwin_result == K_IGNORE) | |
7428 { | |
7429 set_cmdspos_cursor(); | |
7430 redrawcmd(); | |
7431 } | |
7432 } | |
7433 | |
7434 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7435 block_autocmds(); |
6876 | 7436 # ifdef FEAT_CONCEAL |
7437 /* Avoid command-line window first character being concealed. */ | |
7438 curwin->w_p_cole = 0; | |
7439 # endif | |
7 | 7440 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7441 set_bufref(&bufref, curbuf); |
7 | 7442 win_goto(old_curwin); |
7443 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7444 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7445 /* 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
|
7446 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7447 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7448 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7449 |
7450 /* Restore window sizes. */ | |
7451 win_size_restore(&winsizes); | |
7452 | |
1410 | 7453 unblock_autocmds(); |
7 | 7454 } |
7455 | |
7456 ga_clear(&winsizes); | |
7457 restart_edit = save_restart_edit; | |
510 | 7458 # ifdef FEAT_RIGHTLEFT |
7459 cmdmsg_rl = save_cmdmsg_rl; | |
7460 # endif | |
7 | 7461 |
7462 State = save_State; | |
7463 # ifdef FEAT_MOUSE | |
7464 setmouse(); | |
7465 # endif | |
7466 | |
7467 return cmdwin_result; | |
7468 } | |
7469 #endif /* FEAT_CMDWIN */ | |
7470 | |
7471 /* | |
7472 * Used for commands that either take a simple command string argument, or: | |
7473 * cmd << endmarker | |
7474 * {script} | |
7475 * endmarker | |
7476 * Returns a pointer to allocated memory with {script} or NULL. | |
7477 */ | |
7478 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7479 script_get(exarg_T *eap, char_u *cmd) |
7 | 7480 { |
7481 char_u *theline; | |
7482 char *end_pattern = NULL; | |
7483 char dot[] = "."; | |
7484 garray_T ga; | |
7485 | |
7486 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7487 return NULL; | |
7488 | |
7489 ga_init2(&ga, 1, 0x400); | |
7490 | |
7491 if (cmd[2] != NUL) | |
7492 end_pattern = (char *)skipwhite(cmd + 2); | |
7493 else | |
7494 end_pattern = dot; | |
7495 | |
7496 for (;;) | |
7497 { | |
7498 theline = eap->getline( | |
7499 #ifdef FEAT_EVAL | |
75 | 7500 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7501 #endif |
7502 NUL, eap->cookie, 0); | |
7503 | |
7504 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7505 { |
7506 vim_free(theline); | |
7 | 7507 break; |
1694 | 7508 } |
7 | 7509 |
7510 ga_concat(&ga, theline); | |
7511 ga_append(&ga, '\n'); | |
7512 vim_free(theline); | |
7513 } | |
21 | 7514 ga_append(&ga, NUL); |
7 | 7515 |
7516 return (char_u *)ga.ga_data; | |
7517 } |