Mercurial > vim
annotate src/ex_getln.c @ 14677:7771a1ff8b99 v8.1.0351
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
commit https://github.com/vim/vim/commit/198cb66d652d3d8ac16226dcc929a11b0b720151
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 6 21:44:17 2018 +0200
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Problem: 'incsearch' for :/foo/s//<Esc> changes last search pattern.
Solution: Save the last search pattern earlier.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 06 Sep 2018 21:45:05 +0200 |
parents | f3b183c3d3e2 |
children | 2982a54aa304 |
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. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
274 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
281 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
283 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
285 char_u *end; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 char_u *dummy; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
288 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
289 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
290 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 *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
|
292 *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
|
293 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
333 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
337 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
343 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
347 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
350 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
351 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
353 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
354 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
355 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
356 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
357 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
358 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
359 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
360 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
362 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
363 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
364 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
365 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
366 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
368 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
369 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
371 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
372 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
374 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
376 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
377 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
378 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
379 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
380 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
381 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
382 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
383 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 curwin->w_cursor = is_state->search_start; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
391 parse_cmd_address(&ea, &dummy); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
397 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
398 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
401 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
402 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
403 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
404 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
405 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
406 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
407 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
408 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
409 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
410 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
411 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
412 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
413 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
414 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
416 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 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
|
421 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
|
422 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 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
|
424 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 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
|
426 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 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
|
428 else |
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 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
|
431 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 // 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
|
433 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
|
434 setpcmark(); |
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 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
|
437 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 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
|
439 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
440 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
441 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
442 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
443 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
444 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
445 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
446 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 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
|
448 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
|
449 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
|
450 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
451 redraw_all_later(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
452 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
453 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
454 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 * 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
|
457 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 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
|
460 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
461 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 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
|
463 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
464 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
|
465 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 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
|
467 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
|
468 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
471 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
472 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
|
473 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
474 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
475 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
476 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
477 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
|
478 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
479 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
480 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
|
481 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
482 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 // 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
|
485 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
487 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 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
|
489 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 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
|
492 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
493 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
|
494 // 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
|
495 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
|
496 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
497 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
498 // 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
|
499 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
|
500 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
|
501 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
503 // 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
|
504 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
|
505 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
|
506 && 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
|
507 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
508 // 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
|
509 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
|
510 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 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
|
513 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
|
514 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 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
|
518 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 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
|
520 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 ++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
|
522 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 // 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
|
524 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
|
525 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
539 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
|
540 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
542 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
|
543 || 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
|
544 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
545 // 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
|
546 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
547 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
|
548 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
549 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 // 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
|
551 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 (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
|
554 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
|
555 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
556 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 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
|
558 // 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
|
559 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
|
560 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 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
|
563 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 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
|
565 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 // 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
|
567 // 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
|
568 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
|
569 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
|
570 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 if (i != 0) |
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 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
|
575 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
576 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
|
577 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
|
578 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 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
|
580 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
|
581 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
|
582 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 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
|
585 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
586 // Disable 'hlsearch' highlighting if the pattern matches everything. |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
587 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
588 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
589 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
590 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
591 ccline.cmdbuff[skiplen + patlen] = NUL; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
592 if (empty_pattern(ccline.cmdbuff)) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
593 set_no_hlsearch(TRUE); |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
594 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
595 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
596 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 // 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
|
599 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
|
600 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
|
601 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 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
|
606 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 // 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
|
608 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 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
|
610 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 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
|
614 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 * 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
|
618 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 * 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
|
620 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 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
|
623 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
|
624 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 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
|
626 int c) |
14503
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 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
|
629 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 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
|
632 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
|
633 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
|
634 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
635 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
636 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
637 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
638 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
639 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
640 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
642 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
643 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
644 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
645 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
647 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
649 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
|
650 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 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
|
652 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
653 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
|
654 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 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
|
656 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
|
657 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
658 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 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
|
661 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 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
|
663 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
|
664 // 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
|
665 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 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
|
668 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 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
|
671 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 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
|
673 ++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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 --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
|
681 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
|
682 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 { |
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 = 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
|
685 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
|
686 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
|
687 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
|
688 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 // 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
|
690 // 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
|
691 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
|
692 (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
|
693 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
694 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
|
695 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
696 // 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
|
697 // 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
|
698 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
|
699 (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
|
700 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
701 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
|
702 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 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
|
705 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 (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
|
707 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 (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
|
709 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
710 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
711 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
|
712 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
|
713 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
|
714 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
715 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
716 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
717 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
|
718 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
|
719 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
720 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
721 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 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
|
723 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
|
724 return FAIL; |
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 |
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 * 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
|
729 * 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
|
730 * 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
|
731 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
732 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 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
|
734 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
735 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
|
736 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
737 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
738 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
739 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
740 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
741 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
742 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
743 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
744 } |
14503
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 // 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
|
747 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
|
748 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
749 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
|
750 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
|
751 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
752 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
753 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
754 // 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
|
755 // 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
|
756 // 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
|
757 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
|
758 *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
|
759 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
760 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
761 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
|
762 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
|
763 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
764 // 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
|
765 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
766 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
767 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
768 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
769 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
770 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
771 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
772 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
773 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
774 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
775 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
776 /* |
7 | 777 * getcmdline() - accept a command line starting with firstc. |
778 * | |
779 * firstc == ':' get ":" command line. | |
780 * firstc == '/' or '?' get search pattern | |
781 * firstc == '=' get expression | |
782 * firstc == '@' get text for input() function | |
783 * firstc == '>' get text for debug mode | |
784 * firstc == NUL get text for :insert command | |
785 * firstc == -1 like NUL, and break on CTRL-C | |
786 * | |
787 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
788 * command line. | |
789 * | |
790 * Careful: getcmdline() can be called recursively! | |
791 * | |
792 * Return pointer to allocated string if there is a commandline, NULL | |
793 * otherwise. | |
794 */ | |
795 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
796 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
797 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
798 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
|
799 int indent) /* indent for inside conditionals */ |
7 | 800 { |
801 int c; | |
802 int i; | |
803 int j; | |
804 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
805 int do_abbr; /* when TRUE check for abbr. */ | |
806 #ifdef FEAT_CMDHIST | |
807 char_u *lookfor = NULL; /* string to match */ | |
808 int hiscnt; /* current history line in use */ | |
809 int histype; /* history type to be used */ | |
810 #endif | |
811 #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
|
812 incsearch_state_T is_state; |
7 | 813 #endif |
814 int did_wild_list = FALSE; /* did wild_list() recently */ | |
815 int wim_index = 0; /* index in wim_flags[] */ | |
816 int res; | |
817 int save_msg_scroll = msg_scroll; | |
818 int save_State = State; /* remember State when called */ | |
819 int some_key_typed = FALSE; /* one of the keys was typed */ | |
820 #ifdef FEAT_MOUSE | |
821 /* mouse drag and release events are ignored, unless they are | |
822 * preceded with a mouse down event */ | |
823 int ignore_drag_release = TRUE; | |
824 #endif | |
825 #ifdef FEAT_EVAL | |
826 int break_ctrl_c = FALSE; | |
827 #endif | |
828 expand_T xpc; | |
829 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
|
830 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 831 /* Everything that may work recursively should save and restore the |
832 * current command line in save_ccline. That includes update_screen(), a | |
833 * custom status line may invoke ":normal". */ | |
834 struct cmdline_info save_ccline; | |
835 #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
|
836 int cmdline_type; |
7 | 837 |
838 #ifdef FEAT_EVAL | |
839 if (firstc == -1) | |
840 { | |
841 firstc = NUL; | |
842 break_ctrl_c = TRUE; | |
843 } | |
844 #endif | |
845 #ifdef FEAT_RIGHTLEFT | |
846 /* start without Hebrew mapping for a command line */ | |
847 if (firstc == ':' || firstc == '=' || firstc == '>') | |
848 cmd_hkmap = 0; | |
849 #endif | |
850 | |
851 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
|
852 |
7 | 853 #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
|
854 init_incsearch_state(&is_state); |
7 | 855 #endif |
856 | |
857 /* | |
858 * set some variables for redrawcmd() | |
859 */ | |
860 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 861 ccline.cmdindent = (firstc > 0 ? indent : 0); |
862 | |
863 /* alloc initial ccline.cmdbuff */ | |
864 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 865 if (ccline.cmdbuff == NULL) |
866 return NULL; /* out of memory */ | |
867 ccline.cmdlen = ccline.cmdpos = 0; | |
868 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
|
869 sb_text_start_cmdline(); |
7 | 870 |
164 | 871 /* autoindent for :insert and :append */ |
872 if (firstc <= 0) | |
873 { | |
6929 | 874 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 875 ccline.cmdbuff[indent] = NUL; |
876 ccline.cmdpos = indent; | |
877 ccline.cmdspos = indent; | |
878 ccline.cmdlen = indent; | |
879 } | |
880 | |
7 | 881 ExpandInit(&xpc); |
1718 | 882 ccline.xpc = &xpc; |
7 | 883 |
884 #ifdef FEAT_RIGHTLEFT | |
885 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
886 && (firstc == '/' || firstc == '?')) | |
887 cmdmsg_rl = TRUE; | |
888 else | |
889 cmdmsg_rl = FALSE; | |
890 #endif | |
891 | |
892 redir_off = TRUE; /* don't redirect the typed command */ | |
893 if (!cmd_silent) | |
894 { | |
895 i = msg_scrolled; | |
896 msg_scrolled = 0; /* avoid wait_return message */ | |
897 gotocmdline(TRUE); | |
898 msg_scrolled += i; | |
899 redrawcmdprompt(); /* draw prompt or indent */ | |
900 set_cmdspos(); | |
901 } | |
902 xpc.xp_context = EXPAND_NOTHING; | |
903 xpc.xp_backslash = XP_BS_NONE; | |
632 | 904 #ifndef BACKSLASH_IN_FILENAME |
905 xpc.xp_shell = FALSE; | |
906 #endif | |
7 | 907 |
531 | 908 #if defined(FEAT_EVAL) |
909 if (ccline.input_fn) | |
910 { | |
911 xpc.xp_context = ccline.xp_context; | |
912 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 913 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 914 xpc.xp_arg = ccline.xp_arg; |
1322 | 915 # endif |
531 | 916 } |
917 #endif | |
918 | |
7 | 919 /* |
920 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
921 * doing ":@0" when register 0 doesn't contain a CR. | |
922 */ | |
923 msg_scroll = FALSE; | |
924 | |
925 State = CMDLINE; | |
926 | |
927 if (firstc == '/' || firstc == '?' || firstc == '@') | |
928 { | |
929 /* Use ":lmap" mappings for search pattern and input(). */ | |
930 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
931 b_im_ptr = &curbuf->b_p_iminsert; | |
932 else | |
933 b_im_ptr = &curbuf->b_p_imsearch; | |
934 if (*b_im_ptr == B_IMODE_LMAP) | |
935 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
936 #ifdef HAVE_INPUT_METHOD |
7 | 937 im_set_active(*b_im_ptr == B_IMODE_IM); |
938 #endif | |
939 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
940 #ifdef HAVE_INPUT_METHOD |
7 | 941 else if (p_imcmdline) |
942 im_set_active(TRUE); | |
943 #endif | |
944 | |
945 #ifdef FEAT_MOUSE | |
946 setmouse(); | |
947 #endif | |
948 #ifdef CURSOR_SHAPE | |
949 ui_cursor_shape(); /* may show different cursor shape */ | |
950 #endif | |
951 | |
571 | 952 /* When inside an autocommand for writing "exiting" may be set and |
953 * terminal mode set to cooked. Need to set raw mode here then. */ | |
954 settmode(TMODE_RAW); | |
955 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
956 /* 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
|
957 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
|
958 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
|
959 |
7 | 960 #ifdef FEAT_CMDHIST |
961 init_history(); | |
962 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
963 histype = hist_char2type(firstc); | |
964 #endif | |
965 | |
966 #ifdef FEAT_DIGRAPHS | |
1868 | 967 do_digraph(-1); /* init digraph typeahead */ |
7 | 968 #endif |
969 | |
5993 | 970 /* If something above caused an error, reset the flags, we do want to type |
971 * and execute commands. Display may be messed up a bit. */ | |
972 if (did_emsg) | |
973 redrawcmd(); | |
974 did_emsg = FALSE; | |
975 got_int = FALSE; | |
976 | |
7 | 977 /* |
978 * Collect the command string, handling editing keys. | |
979 */ | |
980 for (;;) | |
981 { | |
972 | 982 redir_off = TRUE; /* Don't redirect the typed command. |
983 Repeated, because a ":redir" inside | |
984 completion may switch it on. */ | |
7 | 985 #ifdef USE_ON_FLY_SCROLL |
986 dont_scroll = FALSE; /* allow scrolling here */ | |
987 #endif | |
988 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
989 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
990 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
|
991 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
|
992 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
|
993 |
7 | 994 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 995 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
996 /* 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
|
997 * anything, such as stop completion. */ |
1472 | 998 do |
999 { | |
1000 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
|
1001 } while (c == K_IGNORE || c == K_NOP); |
1472 | 1002 |
7 | 1003 if (KeyTyped) |
1004 { | |
1005 some_key_typed = TRUE; | |
1006 #ifdef FEAT_RIGHTLEFT | |
1007 if (cmd_hkmap) | |
1008 c = hkmap(c); | |
1009 # ifdef FEAT_FKMAP | |
1010 if (cmd_fkmap) | |
1011 c = cmdl_fkmap(c); | |
1012 # endif | |
1013 if (cmdmsg_rl && !KeyStuffed) | |
1014 { | |
1015 /* Invert horizontal movements and operations. Only when | |
1016 * typed by the user directly, not when the result of a | |
1017 * mapping. */ | |
1018 switch (c) | |
1019 { | |
1020 case K_RIGHT: c = K_LEFT; break; | |
1021 case K_S_RIGHT: c = K_S_LEFT; break; | |
1022 case K_C_RIGHT: c = K_C_LEFT; break; | |
1023 case K_LEFT: c = K_RIGHT; break; | |
1024 case K_S_LEFT: c = K_S_RIGHT; break; | |
1025 case K_C_LEFT: c = K_C_RIGHT; break; | |
1026 } | |
1027 } | |
1028 #endif | |
1029 } | |
1030 | |
1031 /* | |
1032 * Ignore got_int when CTRL-C was typed here. | |
1033 * Don't ignore it in :global, we really need to break then, e.g., for | |
1034 * ":g/pat/normal /pat" (without the <CR>). | |
1035 * Don't ignore it for the input() function. | |
1036 */ | |
1037 if ((c == Ctrl_C | |
1038 #ifdef UNIX | |
1039 || c == intr_char | |
1040 #endif | |
1041 ) | |
1042 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1043 && firstc != '@' | |
1044 #endif | |
1045 #ifdef FEAT_EVAL | |
1046 && !break_ctrl_c | |
1047 #endif | |
1048 && !global_busy) | |
1049 got_int = FALSE; | |
1050 | |
1051 #ifdef FEAT_CMDHIST | |
1052 /* free old command line when finished moving around in the history | |
1053 * list */ | |
1054 if (lookfor != NULL | |
180 | 1055 && c != K_S_DOWN && c != K_S_UP |
230 | 1056 && c != K_DOWN && c != K_UP |
7 | 1057 && c != K_PAGEDOWN && c != K_PAGEUP |
1058 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1059 && c != K_LEFT && c != K_RIGHT |
7 | 1060 && (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
|
1061 VIM_CLEAR(lookfor); |
7 | 1062 #endif |
1063 | |
1064 /* | |
1718 | 1065 * When there are matching completions to select <S-Tab> works like |
1066 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1067 */ |
1718 | 1068 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1069 c = Ctrl_P; |
1070 | |
1071 #ifdef FEAT_WILDMENU | |
1072 /* Special translations for 'wildmenu' */ | |
1073 if (did_wild_list && p_wmnu) | |
1074 { | |
230 | 1075 if (c == K_LEFT) |
7 | 1076 c = Ctrl_P; |
230 | 1077 else if (c == K_RIGHT) |
7 | 1078 c = Ctrl_N; |
1079 } | |
1080 /* Hitting CR after "emenu Name.": complete submenu */ | |
1081 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1082 && ccline.cmdpos > 1 | |
1083 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1084 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1085 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1086 c = K_DOWN; | |
1087 #endif | |
1088 | |
1089 /* free expanded names when finished walking through matches */ | |
1090 if (xpc.xp_numfiles != -1 | |
1091 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1092 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1093 && c != Ctrl_L) | |
1094 { | |
1095 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1096 did_wild_list = FALSE; | |
1097 #ifdef FEAT_WILDMENU | |
230 | 1098 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1099 #endif |
1100 xpc.xp_context = EXPAND_NOTHING; | |
1101 wim_index = 0; | |
1102 #ifdef FEAT_WILDMENU | |
1103 if (p_wmnu && wild_menu_showing != 0) | |
1104 { | |
1105 int skt = KeyTyped; | |
532 | 1106 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1107 |
1108 if (ccline.input_fn) | |
1109 RedrawingDisabled = 0; | |
7 | 1110 |
1111 if (wild_menu_showing == WM_SCROLLED) | |
1112 { | |
1113 /* Entered command line, move it up */ | |
1114 cmdline_row--; | |
1115 redrawcmd(); | |
1116 } | |
1117 else if (save_p_ls != -1) | |
1118 { | |
1119 /* restore 'laststatus' and 'winminheight' */ | |
1120 p_ls = save_p_ls; | |
1121 p_wmh = save_p_wmh; | |
1122 last_status(FALSE); | |
195 | 1123 save_cmdline(&save_ccline); |
7 | 1124 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1125 restore_cmdline(&save_ccline); |
7 | 1126 redrawcmd(); |
1127 save_p_ls = -1; | |
1128 } | |
1129 else | |
1130 { | |
1131 win_redraw_last_status(topframe); | |
1132 redraw_statuslines(); | |
1133 } | |
532 | 1134 KeyTyped = skt; |
1135 wild_menu_showing = 0; | |
531 | 1136 if (ccline.input_fn) |
1137 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1138 } |
1139 #endif | |
1140 } | |
1141 | |
1142 #ifdef FEAT_WILDMENU | |
1143 /* Special translations for 'wildmenu' */ | |
1144 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1145 { | |
1146 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1147 if (c == K_DOWN && ccline.cmdpos > 0 |
1148 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1149 c = p_wc; |
230 | 1150 else if (c == K_UP) |
7 | 1151 { |
1152 /* Hitting <Up>: Remove one submenu name in front of the | |
1153 * cursor */ | |
1154 int found = FALSE; | |
1155 | |
1156 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1157 i = 0; | |
1158 while (--j > 0) | |
1159 { | |
1160 /* check for start of menu name */ | |
1161 if (ccline.cmdbuff[j] == ' ' | |
1162 && ccline.cmdbuff[j - 1] != '\\') | |
1163 { | |
1164 i = j + 1; | |
1165 break; | |
1166 } | |
1167 /* check for start of submenu name */ | |
1168 if (ccline.cmdbuff[j] == '.' | |
1169 && ccline.cmdbuff[j - 1] != '\\') | |
1170 { | |
1171 if (found) | |
1172 { | |
1173 i = j + 1; | |
1174 break; | |
1175 } | |
1176 else | |
1177 found = TRUE; | |
1178 } | |
1179 } | |
1180 if (i > 0) | |
1181 cmdline_del(i); | |
1182 c = p_wc; | |
1183 xpc.xp_context = EXPAND_NOTHING; | |
1184 } | |
1185 } | |
714 | 1186 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1187 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1188 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1189 { |
1190 char_u upseg[5]; | |
1191 | |
1192 upseg[0] = PATHSEP; | |
1193 upseg[1] = '.'; | |
1194 upseg[2] = '.'; | |
1195 upseg[3] = PATHSEP; | |
1196 upseg[4] = NUL; | |
1197 | |
1318 | 1198 if (c == K_DOWN |
1199 && ccline.cmdpos > 0 | |
1200 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1201 && (ccline.cmdpos < 3 | |
1202 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1203 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1204 { | |
1205 /* go down a directory */ | |
1206 c = p_wc; | |
1207 } | |
230 | 1208 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1209 { |
1210 /* If in a direct ancestor, strip off one ../ to go down */ | |
1211 int found = FALSE; | |
1212 | |
1213 j = ccline.cmdpos; | |
1214 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1215 while (--j > i) | |
1216 { | |
39 | 1217 #ifdef FEAT_MBYTE |
1218 if (has_mbyte) | |
1219 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1220 #endif | |
7 | 1221 if (vim_ispathsep(ccline.cmdbuff[j])) |
1222 { | |
1223 found = TRUE; | |
1224 break; | |
1225 } | |
1226 } | |
1227 if (found | |
1228 && ccline.cmdbuff[j - 1] == '.' | |
1229 && ccline.cmdbuff[j - 2] == '.' | |
1230 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1231 { | |
1232 cmdline_del(j - 2); | |
1233 c = p_wc; | |
1234 } | |
1235 } | |
230 | 1236 else if (c == K_UP) |
7 | 1237 { |
1238 /* go up a directory */ | |
1239 int found = FALSE; | |
1240 | |
1241 j = ccline.cmdpos - 1; | |
1242 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1243 while (--j > i) | |
1244 { | |
1245 #ifdef FEAT_MBYTE | |
1246 if (has_mbyte) | |
1247 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1248 #endif | |
1249 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1250 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1251 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1252 ccline.cmdbuff[j + 1]) == NULL |
7 | 1253 #endif |
1254 ) | |
1255 { | |
1256 if (found) | |
1257 { | |
1258 i = j + 1; | |
1259 break; | |
1260 } | |
1261 else | |
1262 found = TRUE; | |
1263 } | |
1264 } | |
1265 | |
1266 if (!found) | |
1267 j = i; | |
1268 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1269 j += 4; | |
1270 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1271 && j == i) | |
1272 j += 3; | |
1273 else | |
1274 j = 0; | |
1275 if (j > 0) | |
1276 { | |
1277 /* TODO this is only for DOS/UNIX systems - need to put in | |
1278 * machine-specific stuff here and in upseg init */ | |
1279 cmdline_del(j); | |
1280 put_on_cmdline(upseg + 1, 3, FALSE); | |
1281 } | |
1282 else if (ccline.cmdpos > i) | |
1283 cmdline_del(i); | |
3204 | 1284 |
1285 /* Now complete in the new directory. Set KeyTyped in case the | |
1286 * Up key came from a mapping. */ | |
7 | 1287 c = p_wc; |
3204 | 1288 KeyTyped = TRUE; |
7 | 1289 } |
1290 } | |
1291 | |
1292 #endif /* FEAT_WILDMENU */ | |
1293 | |
1294 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1295 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1296 if (c == Ctrl_BSL) | |
1297 { | |
1298 ++no_mapping; | |
1299 ++allow_keys; | |
1389 | 1300 c = plain_vgetc(); |
7 | 1301 --no_mapping; |
1302 --allow_keys; | |
3859 | 1303 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1304 * is in a mapping. */ | |
1305 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1306 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1307 { |
1308 vungetc(c); | |
1309 c = Ctrl_BSL; | |
1310 } | |
1311 #ifdef FEAT_EVAL | |
1312 else if (c == 'e') | |
1313 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1314 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1315 int len; |
7 | 1316 |
1317 /* | |
1318 * Replace the command line with the result of an expression. | |
625 | 1319 * Need to save and restore the current command line, to be |
1320 * able to enter a new one... | |
7 | 1321 */ |
1322 if (ccline.cmdpos == ccline.cmdlen) | |
1323 new_cmdpos = 99999; /* keep it at the end */ | |
1324 else | |
1325 new_cmdpos = ccline.cmdpos; | |
95 | 1326 |
1327 save_cmdline(&save_ccline); | |
7 | 1328 c = get_expr_register(); |
95 | 1329 restore_cmdline(&save_ccline); |
7 | 1330 if (c == '=') |
1331 { | |
634 | 1332 /* Need to save and restore ccline. And set "textlock" |
632 | 1333 * to avoid nasty things like going to another buffer when |
1334 * evaluating an expression. */ | |
95 | 1335 save_cmdline(&save_ccline); |
634 | 1336 ++textlock; |
7 | 1337 p = get_expr_line(); |
634 | 1338 --textlock; |
95 | 1339 restore_cmdline(&save_ccline); |
2617 | 1340 |
1341 if (p != NULL) | |
7 | 1342 { |
2617 | 1343 len = (int)STRLEN(p); |
1344 if (realloc_cmdbuff(len + 1) == OK) | |
1345 { | |
1346 ccline.cmdlen = len; | |
1347 STRCPY(ccline.cmdbuff, p); | |
1348 vim_free(p); | |
1349 | |
1350 /* Restore the cursor or use the position set with | |
1351 * set_cmdline_pos(). */ | |
1352 if (new_cmdpos > ccline.cmdlen) | |
1353 ccline.cmdpos = ccline.cmdlen; | |
1354 else | |
1355 ccline.cmdpos = new_cmdpos; | |
1356 | |
1357 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1358 redrawcmd(); | |
1359 goto cmdline_changed; | |
1360 } | |
7 | 1361 } |
1362 } | |
1363 beep_flush(); | |
2636 | 1364 got_int = FALSE; /* don't abandon the command line */ |
1365 did_emsg = FALSE; | |
1366 emsg_on_display = FALSE; | |
1367 redrawcmd(); | |
1368 goto cmdline_not_changed; | |
7 | 1369 } |
1370 #endif | |
1371 else | |
1372 { | |
1373 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1374 restart_edit = 'a'; | |
1375 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1376 in history */ | |
1377 goto returncmd; /* back to Normal mode */ | |
1378 } | |
1379 } | |
1380 | |
1381 #ifdef FEAT_CMDWIN | |
1382 if (c == cedit_key || c == K_CMDWIN) | |
1383 { | |
6211 | 1384 if (ex_normal_busy == 0 && got_int == FALSE) |
1385 { | |
1386 /* | |
1387 * Open a window to edit the command line (and history). | |
1388 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1389 c = open_cmdwin(); |
6211 | 1390 some_key_typed = TRUE; |
1391 } | |
7 | 1392 } |
1393 # ifdef FEAT_DIGRAPHS | |
1394 else | |
1395 # endif | |
1396 #endif | |
1397 #ifdef FEAT_DIGRAPHS | |
1398 c = do_digraph(c); | |
1399 #endif | |
1400 | |
1401 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1402 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1403 { | |
168 | 1404 /* In Ex mode a backslash escapes a newline. */ |
1405 if (exmode_active | |
1406 && c != ESC | |
1318 | 1407 && ccline.cmdpos == ccline.cmdlen |
168 | 1408 && ccline.cmdpos > 0 |
1409 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1410 { | |
1411 if (c == K_KENTER) | |
1412 c = '\n'; | |
1413 } | |
1414 else | |
7 | 1415 { |
168 | 1416 gotesc = FALSE; /* Might have typed ESC previously, don't |
1417 truncate the cmdline now. */ | |
1418 if (ccheck_abbr(c + ABBR_OFF)) | |
1419 goto cmdline_changed; | |
1420 if (!cmd_silent) | |
1421 { | |
1422 windgoto(msg_row, 0); | |
1423 out_flush(); | |
1424 } | |
1425 break; | |
7 | 1426 } |
1427 } | |
1428 | |
1429 /* | |
1430 * Completion for 'wildchar' or 'wildcharm' key. | |
1431 * - hitting <ESC> twice means: abandon command line. | |
1432 * - wildcard expansion is only done when the 'wildchar' key is really | |
1433 * typed, not when it comes from a macro | |
1434 */ | |
1435 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1436 { | |
1437 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1438 { | |
1439 /* if 'wildmode' contains "list" may still need to list */ | |
1440 if (xpc.xp_numfiles > 1 | |
1441 && !did_wild_list | |
1442 && (wim_flags[wim_index] & WIM_LIST)) | |
1443 { | |
1444 (void)showmatches(&xpc, FALSE); | |
1445 redrawcmd(); | |
1446 did_wild_list = TRUE; | |
1447 } | |
1448 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1449 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1450 firstc != '@'); | |
7 | 1451 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1452 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1453 firstc != '@'); | |
7 | 1454 else |
1455 res = OK; /* don't insert 'wildchar' now */ | |
1456 } | |
1457 else /* typed p_wc first time */ | |
1458 { | |
1459 wim_index = 0; | |
1460 j = ccline.cmdpos; | |
1461 /* if 'wildmode' first contains "longest", get longest | |
1462 * common part */ | |
1463 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1464 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1465 firstc != '@'); | |
7 | 1466 else |
3961 | 1467 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1468 firstc != '@'); | |
7 | 1469 |
1470 /* if interrupted while completing, behave like it failed */ | |
1471 if (got_int) | |
1472 { | |
1473 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1474 got_int = FALSE; /* don't abandon the command line */ | |
1475 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1476 #ifdef FEAT_WILDMENU | |
1477 xpc.xp_context = EXPAND_NOTHING; | |
1478 #endif | |
1479 goto cmdline_changed; | |
1480 } | |
1481 | |
1482 /* when more than one match, and 'wildmode' first contains | |
1483 * "list", or no change and 'wildmode' contains "longest,list", | |
1484 * list all matches */ | |
1485 if (res == OK && xpc.xp_numfiles > 1) | |
1486 { | |
1487 /* a "longest" that didn't do anything is skipped (but not | |
1488 * "list:longest") */ | |
1489 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1490 wim_index = 1; | |
1491 if ((wim_flags[wim_index] & WIM_LIST) | |
1492 #ifdef FEAT_WILDMENU | |
1493 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1494 #endif | |
1495 ) | |
1496 { | |
1497 if (!(wim_flags[0] & WIM_LONGEST)) | |
1498 { | |
1499 #ifdef FEAT_WILDMENU | |
1500 int p_wmnu_save = p_wmnu; | |
1501 p_wmnu = 0; | |
1502 #endif | |
3961 | 1503 /* remove match */ |
1504 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1505 #ifdef FEAT_WILDMENU |
1506 p_wmnu = p_wmnu_save; | |
1507 #endif | |
1508 } | |
1509 #ifdef FEAT_WILDMENU | |
1510 (void)showmatches(&xpc, p_wmnu | |
1511 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1512 #else | |
1513 (void)showmatches(&xpc, FALSE); | |
1514 #endif | |
1515 redrawcmd(); | |
1516 did_wild_list = TRUE; | |
1517 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1518 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1519 firstc != '@'); | |
7 | 1520 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1521 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1522 firstc != '@'); | |
7 | 1523 } |
1524 else | |
6949 | 1525 vim_beep(BO_WILD); |
7 | 1526 } |
1527 #ifdef FEAT_WILDMENU | |
1528 else if (xpc.xp_numfiles == -1) | |
1529 xpc.xp_context = EXPAND_NOTHING; | |
1530 #endif | |
1531 } | |
1532 if (wim_index < 3) | |
1533 ++wim_index; | |
1534 if (c == ESC) | |
1535 gotesc = TRUE; | |
1536 if (res == OK) | |
1537 goto cmdline_changed; | |
1538 } | |
1539 | |
1540 gotesc = FALSE; | |
1541 | |
1542 /* <S-Tab> goes to last match, in a clumsy way */ | |
1543 if (c == K_S_TAB && KeyTyped) | |
1544 { | |
3961 | 1545 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1546 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1547 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1548 goto cmdline_changed; |
1549 } | |
1550 | |
1551 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1552 c = NL; | |
1553 | |
1554 do_abbr = TRUE; /* default: check for abbreviation */ | |
1555 | |
1556 /* | |
1557 * Big switch for a typed command line character. | |
1558 */ | |
1559 switch (c) | |
1560 { | |
1561 case K_BS: | |
1562 case Ctrl_H: | |
1563 case K_DEL: | |
1564 case K_KDEL: | |
1565 case Ctrl_W: | |
1566 #ifdef FEAT_FKMAP | |
1567 if (cmd_fkmap && c == K_BS) | |
1568 c = K_DEL; | |
1569 #endif | |
1570 if (c == K_KDEL) | |
1571 c = K_DEL; | |
1572 | |
1573 /* | |
1574 * delete current character is the same as backspace on next | |
1575 * character, except at end of line | |
1576 */ | |
1577 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1578 ++ccline.cmdpos; | |
1579 #ifdef FEAT_MBYTE | |
1580 if (has_mbyte && c == K_DEL) | |
1581 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1582 ccline.cmdbuff + ccline.cmdpos); | |
1583 #endif | |
1584 if (ccline.cmdpos > 0) | |
1585 { | |
1586 char_u *p; | |
1587 | |
1588 j = ccline.cmdpos; | |
1589 p = ccline.cmdbuff + j; | |
1590 #ifdef FEAT_MBYTE | |
1591 if (has_mbyte) | |
1592 { | |
1593 p = mb_prevptr(ccline.cmdbuff, p); | |
1594 if (c == Ctrl_W) | |
1595 { | |
1596 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1597 p = mb_prevptr(ccline.cmdbuff, p); | |
1598 i = mb_get_class(p); | |
1599 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1600 p = mb_prevptr(ccline.cmdbuff, p); | |
1601 if (mb_get_class(p) != i) | |
474 | 1602 p += (*mb_ptr2len)(p); |
7 | 1603 } |
1604 } | |
1605 else | |
1606 #endif | |
1607 if (c == Ctrl_W) | |
1608 { | |
1609 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1610 --p; | |
1611 i = vim_iswordc(p[-1]); | |
1612 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1613 && vim_iswordc(p[-1]) == i) | |
1614 --p; | |
1615 } | |
1616 else | |
1617 --p; | |
1618 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1619 ccline.cmdlen -= j - ccline.cmdpos; | |
1620 i = ccline.cmdpos; | |
1621 while (i < ccline.cmdlen) | |
1622 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1623 | |
1624 /* Truncate at the end, required for multi-byte chars. */ | |
1625 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1626 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1627 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1628 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1629 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
|
1630 /* 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
|
1631 * 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
|
1632 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
|
1633 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1634 #endif |
7 | 1635 redrawcmd(); |
1636 } | |
1637 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1638 && ccline.cmdprompt == NULL && indent == 0) | |
1639 { | |
1640 /* In ex and debug mode it doesn't make sense to return. */ | |
1641 if (exmode_active | |
1642 #ifdef FEAT_EVAL | |
1643 || ccline.cmdfirstc == '>' | |
1644 #endif | |
1645 ) | |
1646 goto cmdline_not_changed; | |
1647 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1648 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1649 if (!cmd_silent) |
1650 { | |
1651 #ifdef FEAT_RIGHTLEFT | |
1652 if (cmdmsg_rl) | |
1653 msg_col = Columns; | |
1654 else | |
1655 #endif | |
1656 msg_col = 0; | |
1657 msg_putchar(' '); /* delete ':' */ | |
1658 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1659 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1660 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
|
1661 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
|
1662 #endif |
7 | 1663 redraw_cmdline = TRUE; |
1664 goto returncmd; /* back to cmd mode */ | |
1665 } | |
1666 goto cmdline_changed; | |
1667 | |
1668 case K_INS: | |
1669 case K_KINS: | |
1670 #ifdef FEAT_FKMAP | |
1671 /* if Farsi mode set, we are in reverse insert mode - | |
1672 Do not change the mode */ | |
1673 if (cmd_fkmap) | |
1674 beep_flush(); | |
1675 else | |
1676 #endif | |
1677 ccline.overstrike = !ccline.overstrike; | |
1678 #ifdef CURSOR_SHAPE | |
1679 ui_cursor_shape(); /* may show different cursor shape */ | |
1680 #endif | |
1681 goto cmdline_not_changed; | |
1682 | |
1683 case Ctrl_HAT: | |
782 | 1684 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1685 { |
1686 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1687 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1688 #ifdef HAVE_INPUT_METHOD |
7 | 1689 im_set_active(FALSE); /* Disable input method */ |
1690 #endif | |
1691 if (b_im_ptr != NULL) | |
1692 { | |
1693 if (State & LANGMAP) | |
1694 *b_im_ptr = B_IMODE_LMAP; | |
1695 else | |
1696 *b_im_ptr = B_IMODE_NONE; | |
1697 } | |
1698 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1699 #ifdef HAVE_INPUT_METHOD |
7 | 1700 else |
1701 { | |
1702 /* There are no ":lmap" mappings, toggle IM. When | |
1703 * 'imdisable' is set don't try getting the status, it's | |
1704 * always off. */ | |
1705 if ((p_imdisable && b_im_ptr != NULL) | |
1706 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1707 { | |
1708 im_set_active(FALSE); /* Disable input method */ | |
1709 if (b_im_ptr != NULL) | |
1710 *b_im_ptr = B_IMODE_NONE; | |
1711 } | |
1712 else | |
1713 { | |
1714 im_set_active(TRUE); /* Enable input method */ | |
1715 if (b_im_ptr != NULL) | |
1716 *b_im_ptr = B_IMODE_IM; | |
1717 } | |
1718 } | |
1719 #endif | |
1720 if (b_im_ptr != NULL) | |
1721 { | |
1722 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1723 set_iminsert_global(); | |
1724 else | |
1725 set_imsearch_global(); | |
1726 } | |
1727 #ifdef CURSOR_SHAPE | |
1728 ui_cursor_shape(); /* may show different cursor shape */ | |
1729 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1730 #if defined(FEAT_KEYMAP) |
7 | 1731 /* Show/unshow value of 'keymap' in status lines later. */ |
1732 status_redraw_curbuf(); | |
1733 #endif | |
1734 goto cmdline_not_changed; | |
1735 | |
1736 /* case '@': only in very old vi */ | |
1737 case Ctrl_U: | |
1738 /* delete all characters left of the cursor */ | |
1739 j = ccline.cmdpos; | |
1740 ccline.cmdlen -= j; | |
1741 i = ccline.cmdpos = 0; | |
1742 while (i < ccline.cmdlen) | |
1743 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1744 /* Truncate at the end, required for multi-byte chars. */ | |
1745 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1746 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1747 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
|
1748 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
|
1749 #endif |
7 | 1750 redrawcmd(); |
1751 goto cmdline_changed; | |
1752 | |
1753 #ifdef FEAT_CLIPBOARD | |
1754 case Ctrl_Y: | |
1755 /* Copy the modeless selection, if there is one. */ | |
1756 if (clip_star.state != SELECT_CLEARED) | |
1757 { | |
1758 if (clip_star.state == SELECT_DONE) | |
1759 clip_copy_modeless_selection(TRUE); | |
1760 goto cmdline_not_changed; | |
1761 } | |
1762 break; | |
1763 #endif | |
1764 | |
1765 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1766 case Ctrl_C: | |
571 | 1767 /* In exmode it doesn't make sense to return. Except when |
161 | 1768 * ":normal" runs out of characters. */ |
1769 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1770 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1771 goto cmdline_not_changed; |
1772 | |
1773 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1774 putting it in history */ | |
1775 goto returncmd; /* back to cmd mode */ | |
1776 | |
1777 case Ctrl_R: /* insert register */ | |
1778 #ifdef USE_ON_FLY_SCROLL | |
1779 dont_scroll = TRUE; /* disallow scrolling here */ | |
1780 #endif | |
1781 putcmdline('"', TRUE); | |
1782 ++no_mapping; | |
1389 | 1783 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1784 if (i == Ctrl_O) |
1785 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1786 if (i == Ctrl_R) | |
1389 | 1787 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
|
1788 extra_char = NUL; |
7 | 1789 --no_mapping; |
1790 #ifdef FEAT_EVAL | |
1791 /* | |
1792 * Insert the result of an expression. | |
1793 * Need to save the current command line, to be able to enter | |
1794 * a new one... | |
1795 */ | |
1796 new_cmdpos = -1; | |
1797 if (c == '=') | |
1798 { | |
1799 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1800 { | |
1801 beep_flush(); | |
1802 c = ESC; | |
1803 } | |
1804 else | |
1805 { | |
95 | 1806 save_cmdline(&save_ccline); |
7 | 1807 c = get_expr_register(); |
95 | 1808 restore_cmdline(&save_ccline); |
7 | 1809 } |
1810 } | |
1811 #endif | |
1812 if (c != ESC) /* use ESC to cancel inserting register */ | |
1813 { | |
1015 | 1814 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1815 |
613 | 1816 #ifdef FEAT_EVAL |
606 | 1817 /* When there was a serious error abort getting the |
1818 * command line. */ | |
1819 if (aborting()) | |
1820 { | |
1821 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1822 putting it in history */ | |
1823 goto returncmd; /* back to cmd mode */ | |
1824 } | |
613 | 1825 #endif |
7 | 1826 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1827 #ifdef FEAT_EVAL | |
1828 if (new_cmdpos >= 0) | |
1829 { | |
1830 /* set_cmdline_pos() was used */ | |
1831 if (new_cmdpos > ccline.cmdlen) | |
1832 ccline.cmdpos = ccline.cmdlen; | |
1833 else | |
1834 ccline.cmdpos = new_cmdpos; | |
1835 } | |
1836 #endif | |
1837 } | |
1838 redrawcmd(); | |
1839 goto cmdline_changed; | |
1840 | |
1841 case Ctrl_D: | |
1842 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1843 break; /* Use ^D as normal char instead */ | |
1844 | |
1845 redrawcmd(); | |
1846 continue; /* don't do incremental search now */ | |
1847 | |
1848 case K_RIGHT: | |
1849 case K_S_RIGHT: | |
1850 case K_C_RIGHT: | |
1851 do | |
1852 { | |
1853 if (ccline.cmdpos >= ccline.cmdlen) | |
1854 break; | |
1855 i = cmdline_charsize(ccline.cmdpos); | |
1856 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1857 break; | |
1858 ccline.cmdspos += i; | |
1859 #ifdef FEAT_MBYTE | |
1860 if (has_mbyte) | |
474 | 1861 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1862 + ccline.cmdpos); |
1863 else | |
1864 #endif | |
1865 ++ccline.cmdpos; | |
1866 } | |
180 | 1867 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1868 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1869 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1870 #ifdef FEAT_MBYTE | |
1871 if (has_mbyte) | |
1872 set_cmdspos_cursor(); | |
1873 #endif | |
1874 goto cmdline_not_changed; | |
1875 | |
1876 case K_LEFT: | |
1877 case K_S_LEFT: | |
1878 case K_C_LEFT: | |
1456 | 1879 if (ccline.cmdpos == 0) |
1880 goto cmdline_not_changed; | |
7 | 1881 do |
1882 { | |
1883 --ccline.cmdpos; | |
1884 #ifdef FEAT_MBYTE | |
1885 if (has_mbyte) /* move to first byte of char */ | |
1886 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1887 ccline.cmdbuff + ccline.cmdpos); | |
1888 #endif | |
1889 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1890 } | |
1456 | 1891 while (ccline.cmdpos > 0 |
1892 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1893 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1894 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1895 #ifdef FEAT_MBYTE | |
1896 if (has_mbyte) | |
1897 set_cmdspos_cursor(); | |
1898 #endif | |
1899 goto cmdline_not_changed; | |
1900 | |
1901 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
|
1902 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1903 goto cmdline_not_changed; |
7 | 1904 |
625 | 1905 #ifdef FEAT_GUI_W32 |
1906 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1907 * cancelled. */ | |
1908 case K_F4: | |
1909 if (mod_mask == MOD_MASK_ALT) | |
1910 { | |
1911 redrawcmd(); /* somehow the cmdline is cleared */ | |
1912 goto cmdline_not_changed; | |
1913 } | |
1914 break; | |
1915 #endif | |
1916 | |
7 | 1917 #ifdef FEAT_MOUSE |
1918 case K_MIDDLEDRAG: | |
1919 case K_MIDDLERELEASE: | |
1920 goto cmdline_not_changed; /* Ignore mouse */ | |
1921 | |
1922 case K_MIDDLEMOUSE: | |
1923 # ifdef FEAT_GUI | |
1924 /* When GUI is active, also paste when 'mouse' is empty */ | |
1925 if (!gui.in_use) | |
1926 # endif | |
1927 if (!mouse_has(MOUSE_COMMAND)) | |
1928 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1929 # ifdef FEAT_CLIPBOARD |
7 | 1930 if (clip_star.available) |
1015 | 1931 cmdline_paste('*', TRUE, TRUE); |
7 | 1932 else |
692 | 1933 # endif |
1015 | 1934 cmdline_paste(0, TRUE, TRUE); |
7 | 1935 redrawcmd(); |
1936 goto cmdline_changed; | |
1937 | |
692 | 1938 # ifdef FEAT_DND |
7 | 1939 case K_DROP: |
1015 | 1940 cmdline_paste('~', TRUE, FALSE); |
7 | 1941 redrawcmd(); |
1942 goto cmdline_changed; | |
692 | 1943 # endif |
7 | 1944 |
1945 case K_LEFTDRAG: | |
1946 case K_LEFTRELEASE: | |
1947 case K_RIGHTDRAG: | |
1948 case K_RIGHTRELEASE: | |
1949 /* Ignore drag and release events when the button-down wasn't | |
1950 * seen before. */ | |
1951 if (ignore_drag_release) | |
1952 goto cmdline_not_changed; | |
1953 /* FALLTHROUGH */ | |
1954 case K_LEFTMOUSE: | |
1955 case K_RIGHTMOUSE: | |
1956 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1957 ignore_drag_release = TRUE; | |
1958 else | |
1959 ignore_drag_release = FALSE; | |
1960 # ifdef FEAT_GUI | |
1961 /* When GUI is active, also move when 'mouse' is empty */ | |
1962 if (!gui.in_use) | |
1963 # endif | |
1964 if (!mouse_has(MOUSE_COMMAND)) | |
1965 goto cmdline_not_changed; /* Ignore mouse */ | |
1966 # ifdef FEAT_CLIPBOARD | |
1967 if (mouse_row < cmdline_row && clip_star.available) | |
1968 { | |
1969 int button, is_click, is_drag; | |
1970 | |
1971 /* | |
1972 * Handle modeless selection. | |
1973 */ | |
1974 button = get_mouse_button(KEY2TERMCAP1(c), | |
1975 &is_click, &is_drag); | |
1976 if (mouse_model_popup() && button == MOUSE_LEFT | |
1977 && (mod_mask & MOD_MASK_SHIFT)) | |
1978 { | |
1979 /* Translate shift-left to right button. */ | |
1980 button = MOUSE_RIGHT; | |
1981 mod_mask &= ~MOD_MASK_SHIFT; | |
1982 } | |
1983 clip_modeless(button, is_click, is_drag); | |
1984 goto cmdline_not_changed; | |
1985 } | |
1986 # endif | |
1987 | |
1988 set_cmdspos(); | |
1989 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1990 ++ccline.cmdpos) | |
1991 { | |
1992 i = cmdline_charsize(ccline.cmdpos); | |
1993 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1994 && mouse_col < ccline.cmdspos % Columns + i) | |
1995 break; | |
692 | 1996 # ifdef FEAT_MBYTE |
7 | 1997 if (has_mbyte) |
1998 { | |
1999 /* Count ">" for double-wide char that doesn't fit. */ | |
2000 correct_cmdspos(ccline.cmdpos, i); | |
474 | 2001 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 2002 + ccline.cmdpos) - 1; |
2003 } | |
692 | 2004 # endif |
7 | 2005 ccline.cmdspos += i; |
2006 } | |
2007 goto cmdline_not_changed; | |
2008 | |
2009 /* Mouse scroll wheel: ignored here */ | |
2010 case K_MOUSEDOWN: | |
2011 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2012 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2013 case K_MOUSERIGHT: |
7 | 2014 /* Alternate buttons ignored here */ |
2015 case K_X1MOUSE: | |
2016 case K_X1DRAG: | |
2017 case K_X1RELEASE: | |
2018 case K_X2MOUSE: | |
2019 case K_X2DRAG: | |
2020 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2021 case K_MOUSEMOVE: |
7 | 2022 goto cmdline_not_changed; |
2023 | |
2024 #endif /* FEAT_MOUSE */ | |
2025 | |
2026 #ifdef FEAT_GUI | |
2027 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2028 case K_LEFTRELEASE_NM: | |
2029 goto cmdline_not_changed; | |
2030 | |
2031 case K_VER_SCROLLBAR: | |
540 | 2032 if (msg_scrolled == 0) |
7 | 2033 { |
2034 gui_do_scroll(); | |
2035 redrawcmd(); | |
2036 } | |
2037 goto cmdline_not_changed; | |
2038 | |
2039 case K_HOR_SCROLLBAR: | |
540 | 2040 if (msg_scrolled == 0) |
7 | 2041 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2042 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2043 redrawcmd(); |
2044 } | |
2045 goto cmdline_not_changed; | |
2046 #endif | |
692 | 2047 #ifdef FEAT_GUI_TABLINE |
2048 case K_TABLINE: | |
2049 case K_TABMENU: | |
2050 /* Don't want to change any tabs here. Make sure the same tab | |
2051 * is still selected. */ | |
2052 if (gui_use_tabline()) | |
2053 gui_mch_set_curtab(tabpage_index(curtab)); | |
2054 goto cmdline_not_changed; | |
2055 #endif | |
2056 | |
7 | 2057 case K_SELECT: /* end of Select mode mapping - ignore */ |
2058 goto cmdline_not_changed; | |
2059 | |
2060 case Ctrl_B: /* begin of command line */ | |
2061 case K_HOME: | |
2062 case K_KHOME: | |
2063 case K_S_HOME: | |
2064 case K_C_HOME: | |
2065 ccline.cmdpos = 0; | |
2066 set_cmdspos(); | |
2067 goto cmdline_not_changed; | |
2068 | |
2069 case Ctrl_E: /* end of command line */ | |
2070 case K_END: | |
2071 case K_KEND: | |
2072 case K_S_END: | |
2073 case K_C_END: | |
2074 ccline.cmdpos = ccline.cmdlen; | |
2075 set_cmdspos_cursor(); | |
2076 goto cmdline_not_changed; | |
2077 | |
2078 case Ctrl_A: /* all matches */ | |
3961 | 2079 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2080 break; |
2081 goto cmdline_changed; | |
2082 | |
772 | 2083 case Ctrl_L: |
2084 #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
|
2085 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2086 goto cmdline_not_changed; |
2087 #endif | |
2088 | |
2089 /* completion: longest common part */ | |
3961 | 2090 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2091 break; |
2092 goto cmdline_changed; | |
2093 | |
2094 case Ctrl_N: /* next match */ | |
2095 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2096 if (xpc.xp_numfiles > 0) |
7 | 2097 { |
3961 | 2098 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2099 0, firstc != '@') == FAIL) | |
7 | 2100 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2101 goto cmdline_not_changed; |
7 | 2102 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2103 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2104 /* FALLTHROUGH */ |
7 | 2105 case K_UP: |
2106 case K_DOWN: | |
2107 case K_S_UP: | |
2108 case K_S_DOWN: | |
2109 case K_PAGEUP: | |
2110 case K_KPAGEUP: | |
2111 case K_PAGEDOWN: | |
2112 case K_KPAGEDOWN: | |
2113 if (hislen == 0 || firstc == NUL) /* no history */ | |
2114 goto cmdline_not_changed; | |
2115 | |
2116 i = hiscnt; | |
2117 | |
2118 /* save current command string so it can be restored later */ | |
2119 if (lookfor == NULL) | |
2120 { | |
2121 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2122 goto cmdline_not_changed; | |
2123 lookfor[ccline.cmdpos] = NUL; | |
2124 } | |
2125 | |
2126 j = (int)STRLEN(lookfor); | |
2127 for (;;) | |
2128 { | |
2129 /* one step backwards */ | |
230 | 2130 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2131 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2132 { |
2133 if (hiscnt == hislen) /* first time */ | |
2134 hiscnt = hisidx[histype]; | |
2135 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2136 hiscnt = hislen - 1; | |
2137 else if (hiscnt != hisidx[histype] + 1) | |
2138 --hiscnt; | |
2139 else /* at top of list */ | |
2140 { | |
2141 hiscnt = i; | |
2142 break; | |
2143 } | |
2144 } | |
2145 else /* one step forwards */ | |
2146 { | |
2147 /* on last entry, clear the line */ | |
2148 if (hiscnt == hisidx[histype]) | |
2149 { | |
2150 hiscnt = hislen; | |
2151 break; | |
2152 } | |
2153 | |
2154 /* not on a history line, nothing to do */ | |
2155 if (hiscnt == hislen) | |
2156 break; | |
2157 if (hiscnt == hislen - 1) /* wrap around */ | |
2158 hiscnt = 0; | |
2159 else | |
2160 ++hiscnt; | |
2161 } | |
2162 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2163 { | |
2164 hiscnt = i; | |
2165 break; | |
2166 } | |
230 | 2167 if ((c != K_UP && c != K_DOWN) |
180 | 2168 || hiscnt == i |
7 | 2169 || STRNCMP(history[histype][hiscnt].hisstr, |
2170 lookfor, (size_t)j) == 0) | |
2171 break; | |
2172 } | |
2173 | |
2174 if (hiscnt != i) /* jumped to other entry */ | |
2175 { | |
2176 char_u *p; | |
2177 int len; | |
2178 int old_firstc; | |
2179 | |
2180 vim_free(ccline.cmdbuff); | |
1718 | 2181 xpc.xp_context = EXPAND_NOTHING; |
7 | 2182 if (hiscnt == hislen) |
2183 p = lookfor; /* back to the old one */ | |
2184 else | |
2185 p = history[histype][hiscnt].hisstr; | |
2186 | |
2187 if (histype == HIST_SEARCH | |
2188 && p != lookfor | |
2189 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2190 { | |
2191 /* Correct for the separator character used when | |
2192 * adding the history entry vs the one used now. | |
2193 * First loop: count length. | |
2194 * Second loop: copy the characters. */ | |
2195 for (i = 0; i <= 1; ++i) | |
2196 { | |
2197 len = 0; | |
2198 for (j = 0; p[j] != NUL; ++j) | |
2199 { | |
2200 /* Replace old sep with new sep, unless it is | |
2201 * escaped. */ | |
2202 if (p[j] == old_firstc | |
2203 && (j == 0 || p[j - 1] != '\\')) | |
2204 { | |
2205 if (i > 0) | |
2206 ccline.cmdbuff[len] = firstc; | |
2207 } | |
2208 else | |
2209 { | |
2210 /* Escape new sep, unless it is already | |
2211 * escaped. */ | |
2212 if (p[j] == firstc | |
2213 && (j == 0 || p[j - 1] != '\\')) | |
2214 { | |
2215 if (i > 0) | |
2216 ccline.cmdbuff[len] = '\\'; | |
2217 ++len; | |
2218 } | |
2219 if (i > 0) | |
2220 ccline.cmdbuff[len] = p[j]; | |
2221 } | |
2222 ++len; | |
2223 } | |
2224 if (i == 0) | |
2225 { | |
2226 alloc_cmdbuff(len); | |
2227 if (ccline.cmdbuff == NULL) | |
2228 goto returncmd; | |
2229 } | |
2230 } | |
2231 ccline.cmdbuff[len] = NUL; | |
2232 } | |
2233 else | |
2234 { | |
2235 alloc_cmdbuff((int)STRLEN(p)); | |
2236 if (ccline.cmdbuff == NULL) | |
2237 goto returncmd; | |
2238 STRCPY(ccline.cmdbuff, p); | |
2239 } | |
2240 | |
2241 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2242 redrawcmd(); | |
2243 goto cmdline_changed; | |
2244 } | |
2245 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2246 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2247 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2248 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2249 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2250 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2251 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
|
2252 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
|
2253 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
|
2254 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2255 break; |
7 | 2256 #endif |
2257 | |
2258 case Ctrl_V: | |
2259 case Ctrl_Q: | |
2260 #ifdef FEAT_MOUSE | |
2261 ignore_drag_release = TRUE; | |
2262 #endif | |
2263 putcmdline('^', TRUE); | |
2264 c = get_literal(); /* get next (two) character(s) */ | |
2265 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
|
2266 extra_char = NUL; |
7 | 2267 #ifdef FEAT_MBYTE |
2268 /* may need to remove ^ when composing char was typed */ | |
2269 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2270 { | |
2271 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2272 msg_putchar(' '); | |
2273 cursorcmd(); | |
2274 } | |
2275 #endif | |
2276 break; | |
2277 | |
2278 #ifdef FEAT_DIGRAPHS | |
2279 case Ctrl_K: | |
2280 #ifdef FEAT_MOUSE | |
2281 ignore_drag_release = TRUE; | |
2282 #endif | |
2283 putcmdline('?', TRUE); | |
2284 #ifdef USE_ON_FLY_SCROLL | |
2285 dont_scroll = TRUE; /* disallow scrolling here */ | |
2286 #endif | |
2287 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
|
2288 extra_char = NUL; |
7 | 2289 if (c != NUL) |
2290 break; | |
2291 | |
2292 redrawcmd(); | |
2293 goto cmdline_not_changed; | |
2294 #endif /* FEAT_DIGRAPHS */ | |
2295 | |
2296 #ifdef FEAT_RIGHTLEFT | |
2297 case Ctrl__: /* CTRL-_: switch language mode */ | |
2298 if (!p_ari) | |
2299 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2300 # ifdef FEAT_FKMAP |
7 | 2301 if (p_altkeymap) |
2302 { | |
2303 cmd_fkmap = !cmd_fkmap; | |
2304 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2305 ccline.overstrike = FALSE; | |
2306 } | |
2307 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2308 # endif |
7 | 2309 cmd_hkmap = !cmd_hkmap; |
2310 goto cmdline_not_changed; | |
2311 #endif | |
2312 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2313 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
|
2314 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
|
2315 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
|
2316 |
7 | 2317 default: |
2318 #ifdef UNIX | |
2319 if (c == intr_char) | |
2320 { | |
2321 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2322 putting it in history */ | |
2323 goto returncmd; /* back to Normal mode */ | |
2324 } | |
2325 #endif | |
2326 /* | |
2327 * Normal character with no special meaning. Just set mod_mask | |
2328 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2329 * the string <S-Space>. This should only happen after ^V. | |
2330 */ | |
2331 if (!IS_SPECIAL(c)) | |
2332 mod_mask = 0x0; | |
2333 break; | |
2334 } | |
2335 /* | |
2336 * End of switch on command line character. | |
2337 * We come here if we have a normal character. | |
2338 */ | |
2339 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2340 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2341 #ifdef FEAT_MBYTE |
2342 /* Add ABBR_OFF for characters above 0x100, this is | |
2343 * what check_abbr() expects. */ | |
2344 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2345 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2346 c) || c == Ctrl_RSB)) |
7 | 2347 goto cmdline_changed; |
2348 | |
2349 /* | |
2350 * put the character in the command line | |
2351 */ | |
2352 if (IS_SPECIAL(c) || mod_mask != 0) | |
2353 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2354 else | |
2355 { | |
2356 #ifdef FEAT_MBYTE | |
2357 if (has_mbyte) | |
2358 { | |
2359 j = (*mb_char2bytes)(c, IObuff); | |
2360 IObuff[j] = NUL; /* exclude composing chars */ | |
2361 put_on_cmdline(IObuff, j, TRUE); | |
2362 } | |
2363 else | |
2364 #endif | |
2365 { | |
2366 IObuff[0] = c; | |
2367 put_on_cmdline(IObuff, 1, TRUE); | |
2368 } | |
2369 } | |
2370 goto cmdline_changed; | |
2371 | |
2372 /* | |
2373 * This part implements incremental searches for "/" and "?" | |
2374 * Jump to cmdline_not_changed when a character has been read but the command | |
2375 * line did not change. Then we only search and redraw if something changed in | |
2376 * the past. | |
2377 * Jump to cmdline_changed when the command line did change. | |
2378 * (Sorry for the goto's, I know it is ugly). | |
2379 */ | |
2380 cmdline_not_changed: | |
2381 #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
|
2382 if (!is_state.incsearch_postponed) |
7 | 2383 continue; |
2384 #endif | |
2385 | |
2386 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
|
2387 /* 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
|
2388 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
|
2389 |
7 | 2390 #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
|
2391 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2392 #endif |
2393 | |
2394 #ifdef FEAT_RIGHTLEFT | |
2395 if (cmdmsg_rl | |
2396 # ifdef FEAT_ARABIC | |
534 | 2397 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2398 # endif |
2399 ) | |
2400 /* Always redraw the whole command line to fix shaping and | |
3374 | 2401 * right-left typing. Not efficient, but it works. |
2402 * Do it only when there are no characters left to read | |
2403 * to avoid useless intermediate redraws. */ | |
2404 if (vpeekc() == NUL) | |
2405 redrawcmd(); | |
7 | 2406 #endif |
2407 } | |
2408 | |
2409 returncmd: | |
2410 | |
2411 #ifdef FEAT_RIGHTLEFT | |
2412 cmdmsg_rl = FALSE; | |
2413 #endif | |
2414 | |
2415 #ifdef FEAT_FKMAP | |
2416 cmd_fkmap = 0; | |
2417 #endif | |
2418 | |
2419 ExpandCleanup(&xpc); | |
1718 | 2420 ccline.xpc = NULL; |
7 | 2421 |
2422 #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
|
2423 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2424 #endif |
2425 | |
2426 if (ccline.cmdbuff != NULL) | |
2427 { | |
2428 /* | |
2429 * Put line in history buffer (":" and "=" only when it was typed). | |
2430 */ | |
2431 #ifdef FEAT_CMDHIST | |
2432 if (ccline.cmdlen && firstc != NUL | |
2433 && (some_key_typed || histype == HIST_SEARCH)) | |
2434 { | |
2435 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2436 histype == HIST_SEARCH ? firstc : NUL); | |
2437 if (firstc == ':') | |
2438 { | |
2439 vim_free(new_last_cmdline); | |
2440 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2441 } | |
2442 } | |
2443 #endif | |
2444 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2445 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
|
2446 abandon_cmdline(); |
7 | 2447 } |
2448 | |
2449 /* | |
2450 * If the screen was shifted up, redraw the whole screen (later). | |
2451 * If the line is too long, clear it, so ruler and shown command do | |
2452 * not get printed in the middle of it. | |
2453 */ | |
2454 msg_check(); | |
2455 msg_scroll = save_msg_scroll; | |
2456 redir_off = FALSE; | |
2457 | |
2458 /* When the command line was typed, no need for a wait-return prompt. */ | |
2459 if (some_key_typed) | |
2460 need_wait_return = FALSE; | |
2461 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2462 /* 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
|
2463 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
|
2464 |
7 | 2465 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2466 #ifdef HAVE_INPUT_METHOD |
7 | 2467 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2468 im_save_status(b_im_ptr); | |
2469 im_set_active(FALSE); | |
2470 #endif | |
2471 #ifdef FEAT_MOUSE | |
2472 setmouse(); | |
2473 #endif | |
2474 #ifdef CURSOR_SHAPE | |
2475 ui_cursor_shape(); /* may show different cursor shape */ | |
2476 #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
|
2477 sb_text_end_cmdline(); |
7 | 2478 |
95 | 2479 { |
2480 char_u *p = ccline.cmdbuff; | |
2481 | |
2482 /* Make ccline empty, getcmdline() may try to use it. */ | |
2483 ccline.cmdbuff = NULL; | |
2484 return p; | |
2485 } | |
7 | 2486 } |
2487 | |
2488 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2489 /* | |
2490 * Get a command line with a prompt. | |
2491 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2492 * f_input() when evaluating an expression from CTRL-R =). | |
2493 * Returns the command line in allocated memory, or NULL. | |
2494 */ | |
2495 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2496 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2497 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2498 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2499 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2500 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2501 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2502 { |
2503 char_u *s; | |
2504 struct cmdline_info save_ccline; | |
2505 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
|
2506 int msg_silent_save = msg_silent; |
7 | 2507 |
95 | 2508 save_cmdline(&save_ccline); |
7 | 2509 ccline.cmdprompt = prompt; |
2510 ccline.cmdattr = attr; | |
531 | 2511 # ifdef FEAT_EVAL |
2512 ccline.xp_context = xp_context; | |
2513 ccline.xp_arg = xp_arg; | |
2514 ccline.input_fn = (firstc == '@'); | |
2515 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2516 msg_silent = 0; |
7 | 2517 s = getcmdline(firstc, 1L, 0); |
95 | 2518 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2519 msg_silent = msg_silent_save; |
3020 | 2520 /* Restore msg_col, the prompt from input() may have changed it. |
2521 * But only if called recursively and the commandline is therefore being | |
2522 * restored to an old one; if not, the input() prompt stays on the screen, | |
2523 * so we need its modified msg_col left intact. */ | |
2524 if (ccline.cmdbuff != NULL) | |
2525 msg_col = msg_col_save; | |
7 | 2526 |
2527 return s; | |
2528 } | |
2529 #endif | |
2530 | |
632 | 2531 /* |
634 | 2532 * Return TRUE when the text must not be changed and we can't switch to |
2533 * another window or buffer. Used when editing the command line, evaluating | |
2534 * 'balloonexpr', etc. | |
632 | 2535 */ |
2536 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2537 text_locked(void) |
632 | 2538 { |
2539 #ifdef FEAT_CMDWIN | |
2540 if (cmdwin_type != 0) | |
2541 return TRUE; | |
2542 #endif | |
634 | 2543 return textlock != 0; |
632 | 2544 } |
2545 | |
2546 /* | |
2547 * Give an error message for a command that isn't allowed while the cmdline | |
2548 * window is open or editing the cmdline in another way. | |
2549 */ | |
2550 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2551 text_locked_msg(void) |
632 | 2552 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2553 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2554 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2555 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2556 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2557 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2558 { |
632 | 2559 #ifdef FEAT_CMDWIN |
2560 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2561 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2562 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2563 return e_secure; |
632 | 2564 } |
2565 | |
819 | 2566 /* |
1834 | 2567 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2568 * and give an error message. | |
819 | 2569 */ |
2570 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2571 curbuf_locked(void) |
819 | 2572 { |
2573 if (curbuf_lock > 0) | |
2574 { | |
2575 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2576 return TRUE; | |
2577 } | |
1834 | 2578 return allbuf_locked(); |
2579 } | |
2580 | |
2581 /* | |
2582 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2583 * message. | |
2584 */ | |
2585 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2586 allbuf_locked(void) |
1834 | 2587 { |
2588 if (allbuf_lock > 0) | |
2589 { | |
2590 EMSG(_("E811: Not allowed to change buffer information now")); | |
2591 return TRUE; | |
2592 } | |
819 | 2593 return FALSE; |
2594 } | |
2595 | |
7 | 2596 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2597 cmdline_charsize(int idx) |
7 | 2598 { |
2599 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2600 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2601 return 1; | |
2602 #endif | |
2603 return ptr2cells(ccline.cmdbuff + idx); | |
2604 } | |
2605 | |
2606 /* | |
2607 * Compute the offset of the cursor on the command line for the prompt and | |
2608 * indent. | |
2609 */ | |
2610 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2611 set_cmdspos(void) |
7 | 2612 { |
531 | 2613 if (ccline.cmdfirstc != NUL) |
7 | 2614 ccline.cmdspos = 1 + ccline.cmdindent; |
2615 else | |
2616 ccline.cmdspos = 0 + ccline.cmdindent; | |
2617 } | |
2618 | |
2619 /* | |
2620 * Compute the screen position for the cursor on the command line. | |
2621 */ | |
2622 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2623 set_cmdspos_cursor(void) |
7 | 2624 { |
2625 int i, m, c; | |
2626 | |
2627 set_cmdspos(); | |
2628 if (KeyTyped) | |
534 | 2629 { |
7 | 2630 m = Columns * Rows; |
534 | 2631 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2632 m = MAXCOL; | |
2633 } | |
7 | 2634 else |
2635 m = MAXCOL; | |
2636 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2637 { | |
2638 c = cmdline_charsize(i); | |
2639 #ifdef FEAT_MBYTE | |
2640 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2641 if (has_mbyte) | |
2642 correct_cmdspos(i, c); | |
2643 #endif | |
1612 | 2644 /* If the cmdline doesn't fit, show cursor on last visible char. |
2645 * Don't move the cursor itself, so we can still append. */ | |
7 | 2646 if ((ccline.cmdspos += c) >= m) |
2647 { | |
2648 ccline.cmdspos -= c; | |
2649 break; | |
2650 } | |
2651 #ifdef FEAT_MBYTE | |
2652 if (has_mbyte) | |
474 | 2653 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2654 #endif |
2655 } | |
2656 } | |
2657 | |
2658 #ifdef FEAT_MBYTE | |
2659 /* | |
2660 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2661 * character that doesn't fit, so that a ">" must be displayed. | |
2662 */ | |
2663 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2664 correct_cmdspos(int idx, int cells) |
7 | 2665 { |
474 | 2666 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2667 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2668 && ccline.cmdspos % Columns + cells > Columns) | |
2669 ccline.cmdspos++; | |
2670 } | |
2671 #endif | |
2672 | |
2673 /* | |
2674 * Get an Ex command line for the ":" command. | |
2675 */ | |
2676 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2677 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2678 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2679 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2680 int indent) /* indent for inside conditionals */ |
7 | 2681 { |
2682 /* When executing a register, remove ':' that's in front of each line. */ | |
2683 if (exec_from_reg && vpeekc() == ':') | |
2684 (void)vgetc(); | |
2685 return getcmdline(c, 1L, indent); | |
2686 } | |
2687 | |
2688 /* | |
2689 * Get an Ex command line for Ex mode. | |
2690 * In Ex mode we only use the OS supplied line editing features and no | |
2691 * mappings or abbreviations. | |
168 | 2692 * Returns a string in allocated memory or NULL. |
7 | 2693 */ |
2694 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2695 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2696 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2697 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2698 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2699 int indent) /* indent for inside conditionals */ |
7 | 2700 { |
168 | 2701 garray_T line_ga; |
2702 char_u *pend; | |
2703 int startcol = 0; | |
1329 | 2704 int c1 = 0; |
168 | 2705 int escaped = FALSE; /* CTRL-V typed */ |
2706 int vcol = 0; | |
2707 char_u *p; | |
1329 | 2708 int prev_char; |
5966 | 2709 int len; |
7 | 2710 |
2711 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2712 * confuses the system function that computes tabstops. */ | |
2713 cursor_on(); | |
2714 | |
2715 /* always start in column 0; write a newline if necessary */ | |
2716 compute_cmdrow(); | |
168 | 2717 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2718 msg_putchar('\n'); |
168 | 2719 if (promptc == ':') |
7 | 2720 { |
164 | 2721 /* indent that is only displayed, not in the line itself */ |
168 | 2722 if (p_prompt) |
2723 msg_putchar(':'); | |
7 | 2724 while (indent-- > 0) |
2725 msg_putchar(' '); | |
2726 startcol = msg_col; | |
2727 } | |
2728 | |
2729 ga_init2(&line_ga, 1, 30); | |
2730 | |
164 | 2731 /* autoindent for :insert and :append is in the line itself */ |
168 | 2732 if (promptc <= 0) |
164 | 2733 { |
2734 vcol = indent; | |
2735 while (indent >= 8) | |
2736 { | |
2737 ga_append(&line_ga, TAB); | |
2738 msg_puts((char_u *)" "); | |
2739 indent -= 8; | |
2740 } | |
2741 while (indent-- > 0) | |
2742 { | |
2743 ga_append(&line_ga, ' '); | |
2744 msg_putchar(' '); | |
2745 } | |
2746 } | |
168 | 2747 ++no_mapping; |
2748 ++allow_keys; | |
164 | 2749 |
7 | 2750 /* |
2751 * Get the line, one character at a time. | |
2752 */ | |
2753 got_int = FALSE; | |
168 | 2754 while (!got_int) |
7 | 2755 { |
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
|
2756 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
|
2757 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
|
2758 |
7 | 2759 if (ga_grow(&line_ga, 40) == FAIL) |
2760 break; | |
2761 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2762 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2763 * 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
|
2764 */ |
1329 | 2765 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
|
2766 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2767 /* 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
|
2768 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
|
2769 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
|
2770 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2771 c1 = vgetc(); |
7 | 2772 |
2773 /* | |
168 | 2774 * Handle line editing. |
2775 * Previously this was left to the system, putting the terminal in | |
2776 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2777 */ |
168 | 2778 if (got_int) |
2779 { | |
2780 msg_putchar('\n'); | |
2781 break; | |
2782 } | |
2783 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2784 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
|
2785 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2786 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
|
2787 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
|
2788 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2789 |
168 | 2790 if (!escaped) |
7 | 2791 { |
168 | 2792 /* CR typed means "enter", which is NL */ |
2793 if (c1 == '\r') | |
2794 c1 = '\n'; | |
2795 | |
2796 if (c1 == BS || c1 == K_BS | |
2797 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2798 { |
168 | 2799 if (line_ga.ga_len > 0) |
2800 { | |
5966 | 2801 #ifdef FEAT_MBYTE |
2802 if (has_mbyte) | |
2803 { | |
2804 p = (char_u *)line_ga.ga_data; | |
2805 p[line_ga.ga_len] = NUL; | |
2806 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2807 line_ga.ga_len -= len; | |
2808 } | |
2809 else | |
2810 #endif | |
2811 --line_ga.ga_len; | |
168 | 2812 goto redraw; |
2813 } | |
2814 continue; | |
7 | 2815 } |
2816 | |
168 | 2817 if (c1 == Ctrl_U) |
7 | 2818 { |
168 | 2819 msg_col = startcol; |
2820 msg_clr_eos(); | |
2821 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
|
2822 goto redraw; |
168 | 2823 } |
2824 | |
2825 if (c1 == Ctrl_T) | |
2826 { | |
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
|
2827 sw = get_sw_value(curbuf); |
168 | 2828 p = (char_u *)line_ga.ga_data; |
2829 p[line_ga.ga_len] = NUL; | |
5995 | 2830 indent = get_indent_str(p, 8, FALSE); |
3740 | 2831 indent += sw - indent % sw; |
168 | 2832 add_indent: |
5995 | 2833 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2834 { |
7009 | 2835 (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
|
2836 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
|
2837 s = skipwhite(p); |
168 | 2838 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2839 *s = ' '; | |
2840 ++line_ga.ga_len; | |
7 | 2841 } |
168 | 2842 redraw: |
2843 /* redraw the line */ | |
2844 msg_col = startcol; | |
2845 vcol = 0; | |
5966 | 2846 p = (char_u *)line_ga.ga_data; |
2847 p[line_ga.ga_len] = NUL; | |
2848 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2849 { |
168 | 2850 if (*p == TAB) |
7 | 2851 { |
168 | 2852 do |
7 | 2853 { |
168 | 2854 msg_putchar(' '); |
2855 } while (++vcol % 8); | |
5966 | 2856 ++p; |
7 | 2857 } |
168 | 2858 else |
164 | 2859 { |
5966 | 2860 len = MB_PTR2LEN(p); |
2861 msg_outtrans_len(p, len); | |
2862 vcol += ptr2cells(p); | |
2863 p += len; | |
7 | 2864 } |
2865 } | |
168 | 2866 msg_clr_eos(); |
1329 | 2867 windgoto(msg_row, msg_col); |
168 | 2868 continue; |
2869 } | |
2870 | |
2871 if (c1 == Ctrl_D) | |
2872 { | |
2873 /* Delete one shiftwidth. */ | |
2874 p = (char_u *)line_ga.ga_data; | |
2875 if (prev_char == '0' || prev_char == '^') | |
7 | 2876 { |
168 | 2877 if (prev_char == '^') |
2878 ex_keep_indent = TRUE; | |
2879 indent = 0; | |
2880 p[--line_ga.ga_len] = NUL; | |
7 | 2881 } |
2882 else | |
2883 { | |
168 | 2884 p[line_ga.ga_len] = NUL; |
5995 | 2885 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
|
2886 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
|
2887 { |
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
|
2888 --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
|
2889 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
|
2890 } |
168 | 2891 } |
5995 | 2892 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2893 { |
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
|
2894 s = skipwhite(p); |
168 | 2895 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2896 --line_ga.ga_len; | |
7 | 2897 } |
168 | 2898 goto add_indent; |
2899 } | |
2900 | |
2901 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2902 { | |
2903 escaped = TRUE; | |
2904 continue; | |
7 | 2905 } |
168 | 2906 |
2907 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2908 if (IS_SPECIAL(c1)) | |
2909 continue; | |
7 | 2910 } |
168 | 2911 |
2912 if (IS_SPECIAL(c1)) | |
2913 c1 = '?'; | |
5966 | 2914 #ifdef FEAT_MBYTE |
2915 if (has_mbyte) | |
2916 len = (*mb_char2bytes)(c1, | |
2917 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2918 else | |
2919 #endif | |
2920 { | |
2921 len = 1; | |
2922 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2923 } | |
168 | 2924 if (c1 == '\n') |
2925 msg_putchar('\n'); | |
2926 else if (c1 == TAB) | |
2927 { | |
2928 /* Don't use chartabsize(), 'ts' can be different */ | |
2929 do | |
2930 { | |
2931 msg_putchar(' '); | |
2932 } while (++vcol % 8); | |
2933 } | |
7 | 2934 else |
2935 { | |
168 | 2936 msg_outtrans_len( |
5966 | 2937 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2938 vcol += char2cells(c1); |
7 | 2939 } |
5966 | 2940 line_ga.ga_len += len; |
168 | 2941 escaped = FALSE; |
2942 | |
2943 windgoto(msg_row, msg_col); | |
164 | 2944 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2945 |
2590 | 2946 /* We are done when a NL is entered, but not when it comes after an |
2947 * odd number of backslashes, that results in a NUL. */ | |
2948 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2949 { |
2590 | 2950 int bcount = 0; |
2951 | |
2952 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2953 ++bcount; | |
2954 | |
2955 if (bcount > 0) | |
2956 { | |
2957 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2958 * "\NL", etc. */ | |
2959 line_ga.ga_len -= (bcount + 1) / 2; | |
2960 pend -= (bcount + 1) / 2; | |
2961 pend[-1] = '\n'; | |
2962 } | |
2963 | |
2964 if ((bcount & 1) == 0) | |
2965 { | |
2966 --line_ga.ga_len; | |
2967 --pend; | |
2968 *pend = NUL; | |
2969 break; | |
2970 } | |
7 | 2971 } |
2972 } | |
2973 | |
168 | 2974 --no_mapping; |
2975 --allow_keys; | |
2976 | |
7 | 2977 /* make following messages go to the next line */ |
2978 msg_didout = FALSE; | |
2979 msg_col = 0; | |
2980 if (msg_row < Rows - 1) | |
2981 ++msg_row; | |
2982 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2983 | |
2984 if (got_int) | |
2985 ga_clear(&line_ga); | |
2986 | |
2987 return (char_u *)line_ga.ga_data; | |
2988 } | |
2989 | |
502 | 2990 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2991 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2992 /* |
2993 * Return TRUE if ccline.overstrike is on. | |
2994 */ | |
2995 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2996 cmdline_overstrike(void) |
7 | 2997 { |
2998 return ccline.overstrike; | |
2999 } | |
3000 | |
3001 /* | |
3002 * Return TRUE if the cursor is at the end of the cmdline. | |
3003 */ | |
3004 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3005 cmdline_at_end(void) |
7 | 3006 { |
3007 return (ccline.cmdpos >= ccline.cmdlen); | |
3008 } | |
3009 #endif | |
3010 | |
574 | 3011 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 3012 /* |
3013 * Return the virtual column number at the current cursor position. | |
3014 * This is used by the IM code to obtain the start of the preedit string. | |
3015 */ | |
3016 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3017 cmdline_getvcol_cursor(void) |
7 | 3018 { |
3019 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3020 return MAXCOL; | |
3021 | |
3022 # ifdef FEAT_MBYTE | |
3023 if (has_mbyte) | |
3024 { | |
3025 colnr_T col; | |
3026 int i = 0; | |
3027 | |
3028 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3029 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3030 |
3031 return col; | |
3032 } | |
3033 else | |
3034 # endif | |
3035 return ccline.cmdpos; | |
3036 } | |
3037 #endif | |
3038 | |
3039 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3040 /* | |
3041 * If part of the command line is an IM preedit string, redraw it with | |
3042 * IM feedback attributes. The cursor position is restored after drawing. | |
3043 */ | |
3044 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3045 redrawcmd_preedit(void) |
7 | 3046 { |
3047 if ((State & CMDLINE) | |
3048 && xic != NULL | |
976 | 3049 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3050 && !p_imdisable |
3051 && im_is_preediting()) | |
3052 { | |
3053 int cmdpos = 0; | |
3054 int cmdspos; | |
3055 int old_row; | |
3056 int old_col; | |
3057 colnr_T col; | |
3058 | |
3059 old_row = msg_row; | |
3060 old_col = msg_col; | |
531 | 3061 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3062 |
3063 # ifdef FEAT_MBYTE | |
3064 if (has_mbyte) | |
3065 { | |
3066 for (col = 0; col < preedit_start_col | |
3067 && cmdpos < ccline.cmdlen; ++col) | |
3068 { | |
3069 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3070 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3071 } |
3072 } | |
3073 else | |
3074 # endif | |
3075 { | |
3076 cmdspos += preedit_start_col; | |
3077 cmdpos += preedit_start_col; | |
3078 } | |
3079 | |
3080 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3081 msg_col = cmdspos % (int)Columns; | |
3082 if (msg_row >= Rows) | |
3083 msg_row = Rows - 1; | |
3084 | |
3085 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3086 { | |
3087 int char_len; | |
3088 int char_attr; | |
3089 | |
3090 char_attr = im_get_feedback_attr(col); | |
3091 if (char_attr < 0) | |
3092 break; /* end of preedit string */ | |
3093 | |
3094 # ifdef FEAT_MBYTE | |
3095 if (has_mbyte) | |
474 | 3096 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3097 else |
3098 # endif | |
3099 char_len = 1; | |
3100 | |
3101 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3102 cmdpos += char_len; | |
3103 } | |
3104 | |
3105 msg_row = old_row; | |
3106 msg_col = old_col; | |
3107 } | |
3108 } | |
3109 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3110 | |
3111 /* | |
3112 * Allocate a new command line buffer. | |
3113 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3114 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3115 */ | |
3116 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3117 alloc_cmdbuff(int len) |
7 | 3118 { |
3119 /* | |
3120 * give some extra space to avoid having to allocate all the time | |
3121 */ | |
3122 if (len < 80) | |
3123 len = 100; | |
3124 else | |
3125 len += 20; | |
3126 | |
3127 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3128 ccline.cmdbufflen = len; | |
3129 } | |
3130 | |
3131 /* | |
3132 * Re-allocate the command line to length len + something extra. | |
3133 * return FAIL for failure, OK otherwise | |
3134 */ | |
3135 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3136 realloc_cmdbuff(int len) |
7 | 3137 { |
3138 char_u *p; | |
3139 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3140 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3141 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
|
3142 |
7 | 3143 p = ccline.cmdbuff; |
3144 alloc_cmdbuff(len); /* will get some more */ | |
3145 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3146 { | |
3147 ccline.cmdbuff = p; /* keep the old one */ | |
3148 return FAIL; | |
3149 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3150 /* 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
|
3151 * 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
|
3152 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
|
3153 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3154 vim_free(p); |
1718 | 3155 |
3156 if (ccline.xpc != NULL | |
3157 && ccline.xpc->xp_pattern != NULL | |
3158 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3159 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3160 { | |
1754 | 3161 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3162 |
3163 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3164 * to point into the newly allocated memory. */ | |
3165 if (i >= 0 && i <= ccline.cmdlen) | |
3166 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3167 } | |
3168 | |
7 | 3169 return OK; |
3170 } | |
3171 | |
359 | 3172 #if defined(FEAT_ARABIC) || defined(PROTO) |
3173 static char_u *arshape_buf = NULL; | |
3174 | |
3175 # if defined(EXITFREE) || defined(PROTO) | |
3176 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3177 free_cmdline_buf(void) |
359 | 3178 { |
3179 vim_free(arshape_buf); | |
3180 } | |
3181 # endif | |
3182 #endif | |
3183 | |
7 | 3184 /* |
3185 * Draw part of the cmdline at the current cursor position. But draw stars | |
3186 * when cmdline_star is TRUE. | |
3187 */ | |
3188 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3189 draw_cmdline(int start, int len) |
7 | 3190 { |
3191 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3192 int i; | |
3193 | |
3194 if (cmdline_star > 0) | |
3195 for (i = 0; i < len; ++i) | |
3196 { | |
3197 msg_putchar('*'); | |
3198 # ifdef FEAT_MBYTE | |
3199 if (has_mbyte) | |
474 | 3200 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3201 # endif |
3202 } | |
3203 else | |
3204 #endif | |
3205 #ifdef FEAT_ARABIC | |
3206 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3207 { | |
3208 static int buflen = 0; | |
3209 char_u *p; | |
3210 int j; | |
3211 int newlen = 0; | |
3212 int mb_l; | |
719 | 3213 int pc, pc1 = 0; |
7 | 3214 int prev_c = 0; |
3215 int prev_c1 = 0; | |
714 | 3216 int u8c; |
3217 int u8cc[MAX_MCO]; | |
7 | 3218 int nc = 0; |
3219 | |
3220 /* | |
3221 * Do arabic shaping into a temporary buffer. This is very | |
3222 * inefficient! | |
3223 */ | |
507 | 3224 if (len * 2 + 2 > buflen) |
7 | 3225 { |
3226 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3227 * alloc()/free() calls. */ | |
359 | 3228 vim_free(arshape_buf); |
507 | 3229 buflen = len * 2 + 2; |
359 | 3230 arshape_buf = alloc(buflen); |
3231 if (arshape_buf == NULL) | |
7 | 3232 return; /* out of memory */ |
3233 } | |
3234 | |
507 | 3235 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3236 { | |
3237 /* Prepend a space to draw the leading composing char on. */ | |
3238 arshape_buf[0] = ' '; | |
3239 newlen = 1; | |
3240 } | |
3241 | |
7 | 3242 for (j = start; j < start + len; j += mb_l) |
3243 { | |
3244 p = ccline.cmdbuff + j; | |
714 | 3245 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3246 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3247 if (ARABIC_CHAR(u8c)) |
3248 { | |
3249 /* Do Arabic shaping. */ | |
3250 if (cmdmsg_rl) | |
3251 { | |
3252 /* displaying from right to left */ | |
3253 pc = prev_c; | |
3254 pc1 = prev_c1; | |
714 | 3255 prev_c1 = u8cc[0]; |
7 | 3256 if (j + mb_l >= start + len) |
3257 nc = NUL; | |
3258 else | |
3259 nc = utf_ptr2char(p + mb_l); | |
3260 } | |
3261 else | |
3262 { | |
3263 /* displaying from left to right */ | |
3264 if (j + mb_l >= start + len) | |
3265 pc = NUL; | |
3266 else | |
714 | 3267 { |
3268 int pcc[MAX_MCO]; | |
3269 | |
3270 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3271 start + len - j - mb_l); |
714 | 3272 pc1 = pcc[0]; |
3273 } | |
7 | 3274 nc = prev_c; |
3275 } | |
3276 prev_c = u8c; | |
3277 | |
714 | 3278 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3279 |
359 | 3280 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3281 if (u8cc[0] != 0) |
7 | 3282 { |
714 | 3283 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3284 if (u8cc[1] != 0) | |
3285 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3286 arshape_buf + newlen); |
7 | 3287 } |
3288 } | |
3289 else | |
3290 { | |
3291 prev_c = u8c; | |
359 | 3292 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3293 newlen += mb_l; |
3294 } | |
3295 } | |
3296 | |
359 | 3297 msg_outtrans_len(arshape_buf, newlen); |
7 | 3298 } |
3299 else | |
3300 #endif | |
3301 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3302 } | |
3303 | |
3304 /* | |
3305 * Put a character on the command line. Shifts the following text to the | |
3306 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3307 * "c" must be printable (fit in one display cell)! | |
3308 */ | |
3309 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3310 putcmdline(int c, int shift) |
7 | 3311 { |
3312 if (cmd_silent) | |
3313 return; | |
3314 msg_no_more = TRUE; | |
3315 msg_putchar(c); | |
3316 if (shift) | |
3317 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3318 msg_no_more = FALSE; | |
3319 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3320 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3321 extra_char_shift = shift; |
7 | 3322 } |
3323 | |
3324 /* | |
3325 * Undo a putcmdline(c, FALSE). | |
3326 */ | |
3327 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3328 unputcmdline(void) |
7 | 3329 { |
3330 if (cmd_silent) | |
3331 return; | |
3332 msg_no_more = TRUE; | |
3333 if (ccline.cmdlen == ccline.cmdpos) | |
3334 msg_putchar(' '); | |
3558 | 3335 #ifdef FEAT_MBYTE |
3336 else if (has_mbyte) | |
3337 draw_cmdline(ccline.cmdpos, | |
3338 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3339 #endif | |
7 | 3340 else |
3341 draw_cmdline(ccline.cmdpos, 1); | |
3342 msg_no_more = FALSE; | |
3343 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3344 extra_char = NUL; |
7 | 3345 } |
3346 | |
3347 /* | |
3348 * Put the given string, of the given length, onto the command line. | |
3349 * If len is -1, then STRLEN() is used to calculate the length. | |
3350 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3351 * part will be redrawn, otherwise it will not. If this function is called | |
3352 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3353 * called afterwards. | |
3354 */ | |
3355 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3356 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3357 { |
3358 int retval; | |
3359 int i; | |
3360 int m; | |
3361 int c; | |
3362 | |
3363 if (len < 0) | |
3364 len = (int)STRLEN(str); | |
3365 | |
3366 /* Check if ccline.cmdbuff needs to be longer */ | |
3367 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
|
3368 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3369 else |
3370 retval = OK; | |
3371 if (retval == OK) | |
3372 { | |
3373 if (!ccline.overstrike) | |
3374 { | |
3375 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3376 ccline.cmdbuff + ccline.cmdpos, | |
3377 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3378 ccline.cmdlen += len; | |
3379 } | |
3380 else | |
3381 { | |
3382 #ifdef FEAT_MBYTE | |
3383 if (has_mbyte) | |
3384 { | |
3385 /* Count nr of characters in the new string. */ | |
3386 m = 0; | |
474 | 3387 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3388 ++m; |
3389 /* Count nr of bytes in cmdline that are overwritten by these | |
3390 * characters. */ | |
3391 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3392 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3393 --m; |
3394 if (i < ccline.cmdlen) | |
3395 { | |
3396 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3397 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3398 ccline.cmdlen += ccline.cmdpos + len - i; | |
3399 } | |
3400 else | |
3401 ccline.cmdlen = ccline.cmdpos + len; | |
3402 } | |
3403 else | |
3404 #endif | |
3405 if (ccline.cmdpos + len > ccline.cmdlen) | |
3406 ccline.cmdlen = ccline.cmdpos + len; | |
3407 } | |
3408 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3409 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3410 | |
3411 #ifdef FEAT_MBYTE | |
3412 if (enc_utf8) | |
3413 { | |
3414 /* When the inserted text starts with a composing character, | |
3415 * backup to the character before it. There could be two of them. | |
3416 */ | |
3417 i = 0; | |
3418 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3419 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3420 { | |
3421 i = (*mb_head_off)(ccline.cmdbuff, | |
3422 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3423 ccline.cmdpos -= i; | |
3424 len += i; | |
3425 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3426 } | |
3427 # ifdef FEAT_ARABIC | |
3428 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3429 { | |
3430 /* Check the previous character for Arabic combining pair. */ | |
3431 i = (*mb_head_off)(ccline.cmdbuff, | |
3432 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3433 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3434 + ccline.cmdpos - i), c)) | |
3435 { | |
3436 ccline.cmdpos -= i; | |
3437 len += i; | |
3438 } | |
3439 else | |
3440 i = 0; | |
3441 } | |
3442 # endif | |
3443 if (i != 0) | |
3444 { | |
3445 /* Also backup the cursor position. */ | |
3446 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3447 ccline.cmdspos -= i; | |
3448 msg_col -= i; | |
3449 if (msg_col < 0) | |
3450 { | |
3451 msg_col += Columns; | |
3452 --msg_row; | |
3453 } | |
3454 } | |
3455 } | |
3456 #endif | |
3457 | |
3458 if (redraw && !cmd_silent) | |
3459 { | |
3460 msg_no_more = TRUE; | |
3461 i = cmdline_row; | |
3114 | 3462 cursorcmd(); |
7 | 3463 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3464 /* Avoid clearing the rest of the line too often. */ | |
3465 if (cmdline_row != i || ccline.overstrike) | |
3466 msg_clr_eos(); | |
3467 msg_no_more = FALSE; | |
3468 } | |
3469 #ifdef FEAT_FKMAP | |
3470 /* | |
3471 * If we are in Farsi command mode, the character input must be in | |
3472 * Insert mode. So do not advance the cmdpos. | |
3473 */ | |
3474 if (!cmd_fkmap) | |
3475 #endif | |
3476 { | |
3477 if (KeyTyped) | |
534 | 3478 { |
7 | 3479 m = Columns * Rows; |
534 | 3480 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3481 m = MAXCOL; | |
3482 } | |
7 | 3483 else |
3484 m = MAXCOL; | |
3485 for (i = 0; i < len; ++i) | |
3486 { | |
3487 c = cmdline_charsize(ccline.cmdpos); | |
3488 #ifdef FEAT_MBYTE | |
3489 /* count ">" for a double-wide char that doesn't fit. */ | |
3490 if (has_mbyte) | |
3491 correct_cmdspos(ccline.cmdpos, c); | |
3492 #endif | |
1612 | 3493 /* Stop cursor at the end of the screen, but do increment the |
3494 * insert position, so that entering a very long command | |
3495 * works, even though you can't see it. */ | |
3496 if (ccline.cmdspos + c < m) | |
3497 ccline.cmdspos += c; | |
7 | 3498 #ifdef FEAT_MBYTE |
3499 if (has_mbyte) | |
3500 { | |
474 | 3501 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3502 if (c > len - i - 1) |
3503 c = len - i - 1; | |
3504 ccline.cmdpos += c; | |
3505 i += c; | |
3506 } | |
3507 #endif | |
3508 ++ccline.cmdpos; | |
3509 } | |
3510 } | |
3511 } | |
3512 if (redraw) | |
3513 msg_check(); | |
3514 return retval; | |
3515 } | |
3516 | |
95 | 3517 static struct cmdline_info prev_ccline; |
3518 static int prev_ccline_used = FALSE; | |
3519 | |
3520 /* | |
3521 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3522 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3523 * available globally in prev_ccline. | |
3524 */ | |
3525 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3526 save_cmdline(struct cmdline_info *ccp) |
95 | 3527 { |
3528 if (!prev_ccline_used) | |
3529 { | |
3530 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3531 prev_ccline_used = TRUE; | |
3532 } | |
3533 *ccp = prev_ccline; | |
3534 prev_ccline = ccline; | |
3535 ccline.cmdbuff = NULL; | |
3536 ccline.cmdprompt = NULL; | |
1718 | 3537 ccline.xpc = NULL; |
95 | 3538 } |
3539 | |
3540 /* | |
1214 | 3541 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3542 */ |
3543 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3544 restore_cmdline(struct cmdline_info *ccp) |
95 | 3545 { |
3546 ccline = prev_ccline; | |
3547 prev_ccline = *ccp; | |
3548 } | |
3549 | |
849 | 3550 #if defined(FEAT_EVAL) || defined(PROTO) |
3551 /* | |
3552 * Save the command line into allocated memory. Returns a pointer to be | |
3553 * passed to restore_cmdline_alloc() later. | |
3554 * Returns NULL when failed. | |
3555 */ | |
3556 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3557 save_cmdline_alloc(void) |
849 | 3558 { |
3559 struct cmdline_info *p; | |
3560 | |
3561 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3562 if (p != NULL) | |
3563 save_cmdline(p); | |
3564 return (char_u *)p; | |
3565 } | |
3566 | |
3567 /* | |
3568 * Restore the command line from the return value of save_cmdline_alloc(). | |
3569 */ | |
3570 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3571 restore_cmdline_alloc(char_u *p) |
849 | 3572 { |
3573 if (p != NULL) | |
3574 { | |
3575 restore_cmdline((struct cmdline_info *)p); | |
3576 vim_free(p); | |
3577 } | |
3578 } | |
3579 #endif | |
3580 | |
15 | 3581 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3582 * 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
|
3583 * Used by CTRL-R command in command-line mode. |
15 | 3584 * insert_reg() can't be used here, because special characters from the |
3585 * register contents will be interpreted as commands. | |
3586 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3587 * Return FAIL for failure, OK otherwise. |
15 | 3588 */ |
3589 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3590 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3591 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3592 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
|
3593 int remcr) /* remove trailing CR */ |
15 | 3594 { |
3595 long i; | |
3596 char_u *arg; | |
772 | 3597 char_u *p; |
15 | 3598 int allocated; |
3599 struct cmdline_info save_ccline; | |
3600 | |
3601 /* check for valid regname; also accept special characters for CTRL-R in | |
3602 * the command line */ | |
3603 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
|
3604 && 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
|
3605 && !valid_yank_reg(regname, FALSE)) |
15 | 3606 return FAIL; |
3607 | |
3608 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3609 * CTRL-C to break the loop. */ | |
3610 line_breakcheck(); | |
3611 if (got_int) | |
3612 return FAIL; | |
3613 | |
3614 #ifdef FEAT_CLIPBOARD | |
3615 regname = may_get_selection(regname); | |
3616 #endif | |
3617 | |
634 | 3618 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3619 * things like going to another buffer when evaluating an expression. */ |
95 | 3620 save_cmdline(&save_ccline); |
634 | 3621 ++textlock; |
15 | 3622 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3623 --textlock; |
95 | 3624 restore_cmdline(&save_ccline); |
15 | 3625 |
3626 if (i) | |
3627 { | |
3628 /* Got the value of a special register in "arg". */ | |
3629 if (arg == NULL) | |
3630 return FAIL; | |
772 | 3631 |
3632 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3633 * part of the word. */ | |
3634 p = arg; | |
3635 if (p_is && regname == Ctrl_W) | |
3636 { | |
3637 char_u *w; | |
3638 int len; | |
3639 | |
3640 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3641 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3642 { |
3643 #ifdef FEAT_MBYTE | |
3644 if (has_mbyte) | |
3645 { | |
3646 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3647 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3648 break; | |
3649 w -= len; | |
3650 } | |
3651 else | |
3652 #endif | |
3653 { | |
3654 if (!vim_iswordc(w[-1])) | |
3655 break; | |
3656 --w; | |
3657 } | |
3658 } | |
2937 | 3659 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3660 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3661 p += len; | |
3662 } | |
3663 | |
3664 cmdline_paste_str(p, literally); | |
15 | 3665 if (allocated) |
3666 vim_free(arg); | |
3667 return OK; | |
3668 } | |
3669 | |
1015 | 3670 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3671 } |
3672 | |
3673 /* | |
3674 * Put a string on the command line. | |
3675 * When "literally" is TRUE, insert literally. | |
3676 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3677 * line. | |
3678 */ | |
3679 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3680 cmdline_paste_str(char_u *s, int literally) |
15 | 3681 { |
3682 int c, cv; | |
3683 | |
3684 if (literally) | |
3685 put_on_cmdline(s, -1, TRUE); | |
3686 else | |
3687 while (*s != NUL) | |
3688 { | |
3689 cv = *s; | |
3690 if (cv == Ctrl_V && s[1]) | |
3691 ++s; | |
3692 #ifdef FEAT_MBYTE | |
3693 if (has_mbyte) | |
1606 | 3694 c = mb_cptr2char_adv(&s); |
15 | 3695 else |
3696 #endif | |
3697 c = *s++; | |
3628 | 3698 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3699 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3700 #ifdef UNIX |
3701 || c == intr_char | |
3702 #endif | |
3703 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3704 stuffcharReadbuff(Ctrl_V); | |
3705 stuffcharReadbuff(c); | |
3706 } | |
3707 } | |
3708 | |
7 | 3709 #ifdef FEAT_WILDMENU |
3710 /* | |
3711 * Delete characters on the command line, from "from" to the current | |
3712 * position. | |
3713 */ | |
3714 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3715 cmdline_del(int from) |
7 | 3716 { |
3717 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3718 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3719 ccline.cmdlen -= ccline.cmdpos - from; | |
3720 ccline.cmdpos = from; | |
3721 } | |
3722 #endif | |
3723 | |
3724 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3725 * 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
|
3726 * 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
|
3727 * overwritten. |
7 | 3728 */ |
3729 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3730 redrawcmdline(void) |
7 | 3731 { |
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
|
3732 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
|
3733 } |
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
|
3734 |
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
|
3735 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
|
3736 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
|
3737 { |
7 | 3738 if (cmd_silent) |
3739 return; | |
3740 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
|
3741 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
|
3742 compute_cmdrow(); |
7 | 3743 redrawcmd(); |
3744 cursorcmd(); | |
3745 } | |
3746 | |
3747 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3748 redrawcmdprompt(void) |
7 | 3749 { |
3750 int i; | |
3751 | |
3752 if (cmd_silent) | |
3753 return; | |
531 | 3754 if (ccline.cmdfirstc != NUL) |
7 | 3755 msg_putchar(ccline.cmdfirstc); |
3756 if (ccline.cmdprompt != NULL) | |
3757 { | |
3758 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3759 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3760 /* do the reverse of set_cmdspos() */ | |
531 | 3761 if (ccline.cmdfirstc != NUL) |
7 | 3762 --ccline.cmdindent; |
3763 } | |
3764 else | |
3765 for (i = ccline.cmdindent; i > 0; --i) | |
3766 msg_putchar(' '); | |
3767 } | |
3768 | |
3769 /* | |
3770 * Redraw what is currently on the command line. | |
3771 */ | |
3772 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3773 redrawcmd(void) |
7 | 3774 { |
3775 if (cmd_silent) | |
3776 return; | |
3777 | |
683 | 3778 /* when 'incsearch' is set there may be no command line while redrawing */ |
3779 if (ccline.cmdbuff == NULL) | |
3780 { | |
3781 windgoto(cmdline_row, 0); | |
3782 msg_clr_eos(); | |
3783 return; | |
3784 } | |
3785 | |
7 | 3786 msg_start(); |
3787 redrawcmdprompt(); | |
3788 | |
3789 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3790 msg_no_more = TRUE; | |
3791 draw_cmdline(0, ccline.cmdlen); | |
3792 msg_clr_eos(); | |
3793 msg_no_more = FALSE; | |
3794 | |
3795 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
|
3796 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
|
3797 putcmdline(extra_char, extra_char_shift); |
7 | 3798 |
3799 /* | |
3800 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3801 * in cmdline mode we can reset them now. | |
3802 */ | |
3803 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3804 | |
3805 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3806 * in cmdline mode */ | |
3807 skip_redraw = FALSE; | |
3808 } | |
3809 | |
3810 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3811 compute_cmdrow(void) |
7 | 3812 { |
540 | 3813 if (exmode_active || msg_scrolled != 0) |
7 | 3814 cmdline_row = Rows - 1; |
3815 else | |
3816 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
|
3817 + lastwin->w_status_height; |
7 | 3818 } |
3819 | |
3820 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3821 cursorcmd(void) |
7 | 3822 { |
3823 if (cmd_silent) | |
3824 return; | |
3825 | |
3826 #ifdef FEAT_RIGHTLEFT | |
3827 if (cmdmsg_rl) | |
3828 { | |
3829 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3830 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3831 if (msg_row <= 0) | |
3832 msg_row = Rows - 1; | |
3833 } | |
3834 else | |
3835 #endif | |
3836 { | |
3837 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3838 msg_col = ccline.cmdspos % (int)Columns; | |
3839 if (msg_row >= Rows) | |
3840 msg_row = Rows - 1; | |
3841 } | |
3842 | |
3843 windgoto(msg_row, msg_col); | |
3844 #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
|
3845 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
|
3846 redrawcmd_preedit(); |
7 | 3847 #endif |
3848 #ifdef MCH_CURSOR_SHAPE | |
3849 mch_update_cursor(); | |
3850 #endif | |
3851 } | |
3852 | |
3853 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3854 gotocmdline(int clr) |
7 | 3855 { |
3856 msg_start(); | |
3857 #ifdef FEAT_RIGHTLEFT | |
3858 if (cmdmsg_rl) | |
3859 msg_col = Columns - 1; | |
3860 else | |
3861 #endif | |
3862 msg_col = 0; /* always start in column 0 */ | |
3863 if (clr) /* clear the bottom line(s) */ | |
3864 msg_clr_eos(); /* will reset clear_cmdline */ | |
3865 windgoto(cmdline_row, 0); | |
3866 } | |
3867 | |
3868 /* | |
3869 * Check the word in front of the cursor for an abbreviation. | |
3870 * Called when the non-id character "c" has been entered. | |
3871 * When an abbreviation is recognized it is removed from the text with | |
3872 * backspaces and the replacement string is inserted, followed by "c". | |
3873 */ | |
3874 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3875 ccheck_abbr(int c) |
7 | 3876 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3877 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3878 |
7 | 3879 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3880 return FALSE; | |
3881 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3882 /* 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
|
3883 * 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
|
3884 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
|
3885 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3886 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
|
3887 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3888 && 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
|
3889 && 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
|
3890 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3891 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3892 /* 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
|
3893 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3894 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3895 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3896 } |
3897 | |
3164 | 3898 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3899 static int | |
3900 #ifdef __BORLANDC__ | |
3901 _RTLENTRYF | |
3902 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3903 sort_func_compare(const void *s1, const void *s2) |
3164 | 3904 { |
3905 char_u *p1 = *(char_u **)s1; | |
3906 char_u *p2 = *(char_u **)s2; | |
3907 | |
3908 if (*p1 != '<' && *p2 == '<') return -1; | |
3909 if (*p1 == '<' && *p2 != '<') return 1; | |
3910 return STRCMP(p1, p2); | |
3911 } | |
3912 #endif | |
3913 | |
7 | 3914 /* |
3915 * Return FAIL if this is not an appropriate context in which to do | |
3916 * completion of anything, return OK if it is (even if there are no matches). | |
3917 * For the caller, this means that the character is just passed through like a | |
3918 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3919 */ | |
3920 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3921 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3922 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3923 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3924 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3925 int escape) /* if TRUE, escape the returned matches */ |
7 | 3926 { |
3927 int i, j; | |
3928 char_u *p1; | |
3929 char_u *p2; | |
3930 int difflen; | |
3931 int v; | |
3932 | |
3933 if (xp->xp_numfiles == -1) | |
3934 { | |
3935 set_expand_context(xp); | |
3936 cmd_showtail = expand_showtail(xp); | |
3937 } | |
3938 | |
3939 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3940 { | |
3941 beep_flush(); | |
3942 return OK; /* Something illegal on command line */ | |
3943 } | |
3944 if (xp->xp_context == EXPAND_NOTHING) | |
3945 { | |
3946 /* Caller can use the character as a normal char instead */ | |
3947 return FAIL; | |
3948 } | |
3949 | |
3950 MSG_PUTS("..."); /* show that we are busy */ | |
3951 out_flush(); | |
3952 | |
3953 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3954 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3955 |
3956 if (type == WILD_NEXT || type == WILD_PREV) | |
3957 { | |
3958 /* | |
3959 * Get next/previous match for a previous expanded pattern. | |
3960 */ | |
3961 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3962 } | |
3963 else | |
3964 { | |
3965 /* | |
3966 * Translate string into pattern and expand it. | |
3967 */ | |
1965 | 3968 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3969 xp->xp_context)) == NULL) | |
7 | 3970 p2 = NULL; |
3971 else | |
3972 { | |
2652 | 3973 int use_options = options | |
3961 | 3974 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3975 if (escape) | |
3976 use_options |= WILD_ESCAPE; | |
2652 | 3977 |
3978 if (p_wic) | |
3979 use_options += WILD_ICASE; | |
1965 | 3980 p2 = ExpandOne(xp, p1, |
3981 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3982 use_options, type); |
7 | 3983 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3984 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3985 if (p2 != NULL && type == WILD_LONGEST) |
3986 { | |
1965 | 3987 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3988 if (ccline.cmdbuff[i + j] == '*' |
3989 || ccline.cmdbuff[i + j] == '?') | |
3990 break; | |
3991 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
|
3992 VIM_CLEAR(p2); |
7 | 3993 } |
3994 } | |
3995 } | |
3996 | |
3997 if (p2 != NULL && !got_int) | |
3998 { | |
1965 | 3999 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
|
4000 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 4001 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
4002 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 4003 xp->xp_pattern = ccline.cmdbuff + i; |
4004 } | |
4005 else | |
4006 v = OK; | |
4007 if (v == OK) | |
4008 { | |
323 | 4009 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
4010 &ccline.cmdbuff[ccline.cmdpos], | |
4011 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
4012 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 4013 ccline.cmdlen += difflen; |
4014 ccline.cmdpos += difflen; | |
4015 } | |
4016 } | |
4017 vim_free(p2); | |
4018 | |
4019 redrawcmd(); | |
33 | 4020 cursorcmd(); |
7 | 4021 |
4022 /* When expanding a ":map" command and no matches are found, assume that | |
4023 * the key is supposed to be inserted literally */ | |
4024 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
4025 return FAIL; | |
4026 | |
4027 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4028 beep_flush(); | |
4029 else if (xp->xp_numfiles == 1) | |
4030 /* free expanded pattern */ | |
4031 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4032 | |
4033 return OK; | |
4034 } | |
4035 | |
4036 /* | |
4037 * Do wildcard expansion on the string 'str'. | |
4038 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4039 * Return a pointer to allocated memory containing the new string. |
7 | 4040 * Return NULL for failure. |
4041 * | |
1412 | 4042 * "orig" is the originally expanded string, copied to allocated memory. It |
4043 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4044 * WILD_PREV "orig" should be NULL. | |
4045 * | |
838 | 4046 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4047 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4048 * |
4049 * mode = WILD_FREE: just free previously expanded matches | |
4050 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4051 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4052 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4053 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4054 * mode = WILD_ALL: return all matches concatenated | |
4055 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4056 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4057 * |
4058 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4059 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4060 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4061 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4062 * options = WILD_ADD_SLASH: add a slash after directory names | |
4063 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4064 * options = WILD_SILENT: don't print warning messages | |
4065 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4066 * options = WILD_ICASE: ignore case for files |
7 | 4067 * |
4068 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4069 */ | |
4070 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4071 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4072 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4073 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4074 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
|
4075 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4076 int mode) |
7 | 4077 { |
4078 char_u *ss = NULL; | |
4079 static int findex; | |
4080 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4081 int orig_saved = FALSE; |
7 | 4082 int i; |
4083 long_u len; | |
4084 int non_suf_match; /* number without matching suffix */ | |
4085 | |
4086 /* | |
4087 * first handle the case of using an old match | |
4088 */ | |
4089 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4090 { | |
4091 if (xp->xp_numfiles > 0) | |
4092 { | |
4093 if (mode == WILD_PREV) | |
4094 { | |
4095 if (findex == -1) | |
4096 findex = xp->xp_numfiles; | |
4097 --findex; | |
4098 } | |
4099 else /* mode == WILD_NEXT */ | |
4100 ++findex; | |
4101 | |
4102 /* | |
4103 * When wrapping around, return the original string, set findex to | |
4104 * -1. | |
4105 */ | |
4106 if (findex < 0) | |
4107 { | |
4108 if (orig_save == NULL) | |
4109 findex = xp->xp_numfiles - 1; | |
4110 else | |
4111 findex = -1; | |
4112 } | |
4113 if (findex >= xp->xp_numfiles) | |
4114 { | |
4115 if (orig_save == NULL) | |
4116 findex = 0; | |
4117 else | |
4118 findex = -1; | |
4119 } | |
4120 #ifdef FEAT_WILDMENU | |
4121 if (p_wmnu) | |
4122 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4123 findex, cmd_showtail); | |
4124 #endif | |
4125 if (findex == -1) | |
4126 return vim_strsave(orig_save); | |
4127 return vim_strsave(xp->xp_files[findex]); | |
4128 } | |
4129 else | |
4130 return NULL; | |
4131 } | |
4132 | |
1412 | 4133 /* free old names */ |
7 | 4134 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4135 { | |
4136 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4137 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
|
4138 VIM_CLEAR(orig_save); |
7 | 4139 } |
4140 findex = 0; | |
4141 | |
4142 if (mode == WILD_FREE) /* only release file name */ | |
4143 return NULL; | |
4144 | |
4145 if (xp->xp_numfiles == -1) | |
4146 { | |
4147 vim_free(orig_save); | |
4148 orig_save = orig; | |
1432 | 4149 orig_saved = TRUE; |
7 | 4150 |
4151 /* | |
4152 * Do the expansion. | |
4153 */ | |
4154 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4155 options) == FAIL) | |
4156 { | |
4157 #ifdef FNAME_ILLEGAL | |
4158 /* Illegal file name has been silently skipped. But when there | |
4159 * are wildcards, the real problem is that there was no match, | |
4160 * causing the pattern to be added, which has illegal characters. | |
4161 */ | |
4162 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4163 EMSG2(_(e_nomatch2), str); | |
4164 #endif | |
4165 } | |
4166 else if (xp->xp_numfiles == 0) | |
4167 { | |
4168 if (!(options & WILD_SILENT)) | |
4169 EMSG2(_(e_nomatch2), str); | |
4170 } | |
4171 else | |
4172 { | |
4173 /* Escape the matches for use on the command line. */ | |
4174 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4175 | |
4176 /* | |
4177 * Check for matching suffixes in file names. | |
4178 */ | |
3398 | 4179 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4180 && mode != WILD_LONGEST) | |
7 | 4181 { |
4182 if (xp->xp_numfiles) | |
4183 non_suf_match = xp->xp_numfiles; | |
4184 else | |
4185 non_suf_match = 1; | |
4186 if ((xp->xp_context == EXPAND_FILES | |
4187 || xp->xp_context == EXPAND_DIRECTORIES) | |
4188 && xp->xp_numfiles > 1) | |
4189 { | |
4190 /* | |
4191 * More than one match; check suffix. | |
4192 * The files will have been sorted on matching suffix in | |
4193 * expand_wildcards, only need to check the first two. | |
4194 */ | |
4195 non_suf_match = 0; | |
4196 for (i = 0; i < 2; ++i) | |
4197 if (match_suffix(xp->xp_files[i])) | |
4198 ++non_suf_match; | |
4199 } | |
4200 if (non_suf_match != 1) | |
4201 { | |
4202 /* Can we ever get here unless it's while expanding | |
4203 * interactively? If not, we can get rid of this all | |
4204 * together. Don't really want to wait for this message | |
4205 * (and possibly have to hit return to continue!). | |
4206 */ | |
4207 if (!(options & WILD_SILENT)) | |
4208 EMSG(_(e_toomany)); | |
4209 else if (!(options & WILD_NO_BEEP)) | |
4210 beep_flush(); | |
4211 } | |
4212 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4213 ss = vim_strsave(xp->xp_files[0]); | |
4214 } | |
4215 } | |
4216 } | |
4217 | |
4218 /* Find longest common part */ | |
4219 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4220 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4221 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4222 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4223 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4224 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4225 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4226 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4227 if (has_mbyte) |
7 | 4228 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4229 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
|
4230 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
|
4231 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4232 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4233 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4234 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
|
4235 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
|
4236 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4237 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4238 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4239 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
|
4240 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4241 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4242 ci = xp->xp_files[i][len]; |
4242 | 4243 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4244 || xp->xp_context == EXPAND_FILES |
714 | 4245 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4246 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4247 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4248 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4249 break; |
4250 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4251 else if (c0 != ci) |
7 | 4252 break; |
4253 } | |
4254 if (i < xp->xp_numfiles) | |
4255 { | |
4256 if (!(options & WILD_NO_BEEP)) | |
6949 | 4257 vim_beep(BO_WILD); |
7 | 4258 break; |
4259 } | |
4260 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4261 |
7 | 4262 ss = alloc((unsigned)len + 1); |
4263 if (ss) | |
419 | 4264 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4265 findex = -1; /* next p_wc gets first one */ |
4266 } | |
4267 | |
4268 /* Concatenate all matching names */ | |
4269 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4270 { | |
4271 len = 0; | |
4272 for (i = 0; i < xp->xp_numfiles; ++i) | |
4273 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4274 ss = lalloc(len, TRUE); | |
4275 if (ss != NULL) | |
4276 { | |
4277 *ss = NUL; | |
4278 for (i = 0; i < xp->xp_numfiles; ++i) | |
4279 { | |
4280 STRCAT(ss, xp->xp_files[i]); | |
4281 if (i != xp->xp_numfiles - 1) | |
4282 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4283 } | |
4284 } | |
4285 } | |
4286 | |
4287 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4288 ExpandCleanup(xp); | |
4289 | |
1412 | 4290 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4291 if (!orig_saved) |
1412 | 4292 vim_free(orig); |
4293 | |
7 | 4294 return ss; |
4295 } | |
4296 | |
4297 /* | |
4298 * Prepare an expand structure for use. | |
4299 */ | |
4300 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4301 ExpandInit(expand_T *xp) |
7 | 4302 { |
1718 | 4303 xp->xp_pattern = NULL; |
1965 | 4304 xp->xp_pattern_len = 0; |
7 | 4305 xp->xp_backslash = XP_BS_NONE; |
632 | 4306 #ifndef BACKSLASH_IN_FILENAME |
4307 xp->xp_shell = FALSE; | |
4308 #endif | |
7 | 4309 xp->xp_numfiles = -1; |
4310 xp->xp_files = NULL; | |
632 | 4311 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4312 xp->xp_arg = NULL; | |
4313 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4314 xp->xp_line = NULL; |
7 | 4315 } |
4316 | |
4317 /* | |
4318 * Cleanup an expand structure after use. | |
4319 */ | |
4320 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4321 ExpandCleanup(expand_T *xp) |
7 | 4322 { |
4323 if (xp->xp_numfiles >= 0) | |
4324 { | |
4325 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4326 xp->xp_numfiles = -1; | |
4327 } | |
4328 } | |
4329 | |
4330 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4331 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4332 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4333 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4334 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4335 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4336 int options) |
7 | 4337 { |
4338 int i; | |
4339 char_u *p; | |
4340 | |
4341 /* | |
4342 * May change home directory back to "~" | |
4343 */ | |
4344 if (options & WILD_HOME_REPLACE) | |
4345 tilde_replace(str, numfiles, files); | |
4346 | |
4347 if (options & WILD_ESCAPE) | |
4348 { | |
4349 if (xp->xp_context == EXPAND_FILES | |
2778 | 4350 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4351 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4352 || xp->xp_context == EXPAND_BUFFERS |
4353 || xp->xp_context == EXPAND_DIRECTORIES) | |
4354 { | |
4355 /* | |
4356 * Insert a backslash into a file name before a space, \, %, # | |
4357 * and wildmatch characters, except '~'. | |
4358 */ | |
4359 for (i = 0; i < numfiles; ++i) | |
4360 { | |
4361 /* for ":set path=" we need to escape spaces twice */ | |
4362 if (xp->xp_backslash == XP_BS_THREE) | |
4363 { | |
4364 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4365 if (p != NULL) | |
4366 { | |
4367 vim_free(files[i]); | |
4368 files[i] = p; | |
719 | 4369 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4370 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4371 if (p != NULL) | |
4372 { | |
4373 vim_free(files[i]); | |
4374 files[i] = p; | |
4375 } | |
4376 #endif | |
4377 } | |
4378 } | |
1589 | 4379 #ifdef BACKSLASH_IN_FILENAME |
4380 p = vim_strsave_fnameescape(files[i], FALSE); | |
4381 #else | |
1586 | 4382 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4383 #endif |
7 | 4384 if (p != NULL) |
4385 { | |
4386 vim_free(files[i]); | |
4387 files[i] = p; | |
4388 } | |
4389 | |
4390 /* If 'str' starts with "\~", replace "~" at start of | |
4391 * files[i] with "\~". */ | |
4392 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4393 escape_fname(&files[i]); |
7 | 4394 } |
4395 xp->xp_backslash = XP_BS_NONE; | |
435 | 4396 |
4397 /* If the first file starts with a '+' escape it. Otherwise it | |
4398 * could be seen as "+cmd". */ | |
4399 if (*files[0] == '+') | |
4400 escape_fname(&files[0]); | |
7 | 4401 } |
4402 else if (xp->xp_context == EXPAND_TAGS) | |
4403 { | |
4404 /* | |
4405 * Insert a backslash before characters in a tag name that | |
4406 * would terminate the ":tag" command. | |
4407 */ | |
4408 for (i = 0; i < numfiles; ++i) | |
4409 { | |
4410 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4411 if (p != NULL) | |
4412 { | |
4413 vim_free(files[i]); | |
4414 files[i] = p; | |
4415 } | |
4416 } | |
4417 } | |
4418 } | |
4419 } | |
4420 | |
4421 /* | |
1586 | 4422 * Escape special characters in "fname" for when used as a file name argument |
4423 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4424 * Returns the result in allocated memory. | |
4425 */ | |
4426 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4427 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4428 { |
1685 | 4429 char_u *p; |
1586 | 4430 #ifdef BACKSLASH_IN_FILENAME |
4431 char_u buf[20]; | |
4432 int j = 0; | |
4433 | |
5481 | 4434 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4435 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4436 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4437 buf[j++] = *p; |
4438 buf[j] = NUL; | |
1700 | 4439 p = vim_strsave_escaped(fname, buf); |
1586 | 4440 #else |
1685 | 4441 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4442 if (shell && csh_like_shell() && p != NULL) | |
4443 { | |
4444 char_u *s; | |
4445 | |
4446 /* For csh and similar shells need to put two backslashes before '!'. | |
4447 * One is taken by Vim, one by the shell. */ | |
4448 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4449 vim_free(p); | |
4450 p = s; | |
4451 } | |
1700 | 4452 #endif |
4453 | |
4454 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4455 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4456 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4457 escape_fname(&p); |
4458 | |
1685 | 4459 return p; |
1586 | 4460 } |
4461 | |
4462 /* | |
435 | 4463 * Put a backslash before the file name in "pp", which is in allocated memory. |
4464 */ | |
4465 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4466 escape_fname(char_u **pp) |
435 | 4467 { |
4468 char_u *p; | |
4469 | |
4470 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4471 if (p != NULL) | |
4472 { | |
4473 p[0] = '\\'; | |
4474 STRCPY(p + 1, *pp); | |
4475 vim_free(*pp); | |
4476 *pp = p; | |
4477 } | |
4478 } | |
4479 | |
4480 /* | |
7 | 4481 * For each file name in files[num_files]: |
4482 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4483 */ | |
4484 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4485 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4486 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4487 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4488 char_u **files) |
7 | 4489 { |
4490 int i; | |
4491 char_u *p; | |
4492 | |
4493 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4494 { | |
4495 for (i = 0; i < num_files; ++i) | |
4496 { | |
4497 p = home_replace_save(NULL, files[i]); | |
4498 if (p != NULL) | |
4499 { | |
4500 vim_free(files[i]); | |
4501 files[i] = p; | |
4502 } | |
4503 } | |
4504 } | |
4505 } | |
4506 | |
4507 /* | |
4508 * Show all matches for completion on the command line. | |
4509 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4510 * be inserted like a normal character. | |
4511 */ | |
4512 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4513 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4514 { |
4515 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4516 int num_files; | |
4517 char_u **files_found; | |
4518 int i, j, k; | |
4519 int maxlen; | |
4520 int lines; | |
4521 int columns; | |
4522 char_u *p; | |
4523 int lastlen; | |
4524 int attr; | |
4525 int showtail; | |
4526 | |
4527 if (xp->xp_numfiles == -1) | |
4528 { | |
4529 set_expand_context(xp); | |
4530 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4531 &num_files, &files_found); | |
4532 showtail = expand_showtail(xp); | |
4533 if (i != EXPAND_OK) | |
4534 return i; | |
4535 | |
4536 } | |
4537 else | |
4538 { | |
4539 num_files = xp->xp_numfiles; | |
4540 files_found = xp->xp_files; | |
4541 showtail = cmd_showtail; | |
4542 } | |
4543 | |
4544 #ifdef FEAT_WILDMENU | |
4545 if (!wildmenu) | |
4546 { | |
4547 #endif | |
4548 msg_didany = FALSE; /* lines_left will be set */ | |
4549 msg_start(); /* prepare for paging */ | |
4550 msg_putchar('\n'); | |
4551 out_flush(); | |
4552 cmdline_row = msg_row; | |
4553 msg_didany = FALSE; /* lines_left will be set again */ | |
4554 msg_start(); /* prepare for paging */ | |
4555 #ifdef FEAT_WILDMENU | |
4556 } | |
4557 #endif | |
4558 | |
4559 if (got_int) | |
4560 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4561 #ifdef FEAT_WILDMENU | |
4562 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
|
4563 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4564 #endif |
4565 else | |
4566 { | |
4567 /* find the length of the longest file name */ | |
4568 maxlen = 0; | |
4569 for (i = 0; i < num_files; ++i) | |
4570 { | |
4571 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4572 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4573 || xp->xp_context == EXPAND_BUFFERS)) |
4574 { | |
4575 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4576 j = vim_strsize(NameBuff); | |
4577 } | |
4578 else | |
4579 j = vim_strsize(L_SHOWFILE(i)); | |
4580 if (j > maxlen) | |
4581 maxlen = j; | |
4582 } | |
4583 | |
4584 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4585 lines = num_files; | |
4586 else | |
4587 { | |
4588 /* compute the number of columns and lines for the listing */ | |
4589 maxlen += 2; /* two spaces between file names */ | |
4590 columns = ((int)Columns + 2) / maxlen; | |
4591 if (columns < 1) | |
4592 columns = 1; | |
4593 lines = (num_files + columns - 1) / columns; | |
4594 } | |
4595 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4596 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4597 |
4598 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4599 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4600 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4601 msg_clr_eos(); |
4602 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
|
4603 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4604 } |
4605 | |
4606 /* list the files line by line */ | |
4607 for (i = 0; i < lines; ++i) | |
4608 { | |
4609 lastlen = 999; | |
4610 for (k = i; k < num_files; k += lines) | |
4611 { | |
4612 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4613 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4614 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4615 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4616 msg_advance(maxlen + 1); | |
4617 msg_puts(p); | |
4618 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
|
4619 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4620 break; |
4621 } | |
4622 for (j = maxlen - lastlen; --j >= 0; ) | |
4623 msg_putchar(' '); | |
4624 if (xp->xp_context == EXPAND_FILES | |
714 | 4625 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4626 || xp->xp_context == EXPAND_BUFFERS) |
4627 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4628 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4629 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4630 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4631 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4632 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4633 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4634 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4635 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4636 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4637 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
|
4638 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4639 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4640 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4641 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4642 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4643 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4644 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4645 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4646 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4647 j = mch_isdir(files_found[k]); |
7 | 4648 if (showtail) |
4649 p = L_SHOWFILE(k); | |
4650 else | |
4651 { | |
4652 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4653 TRUE); | |
4654 p = NameBuff; | |
4655 } | |
4656 } | |
4657 else | |
4658 { | |
4659 j = FALSE; | |
4660 p = L_SHOWFILE(k); | |
4661 } | |
4662 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4663 } | |
4664 if (msg_col > 0) /* when not wrapped around */ | |
4665 { | |
4666 msg_clr_eos(); | |
4667 msg_putchar('\n'); | |
4668 } | |
4669 out_flush(); /* show one line at a time */ | |
4670 if (got_int) | |
4671 { | |
4672 got_int = FALSE; | |
4673 break; | |
4674 } | |
4675 } | |
4676 | |
4677 /* | |
4678 * we redraw the command below the lines that we have just listed | |
4679 * This is a bit tricky, but it saves a lot of screen updating. | |
4680 */ | |
4681 cmdline_row = msg_row; /* will put it back later */ | |
4682 } | |
4683 | |
4684 if (xp->xp_numfiles == -1) | |
4685 FreeWild(num_files, files_found); | |
4686 | |
4687 return EXPAND_OK; | |
4688 } | |
4689 | |
4690 /* | |
4691 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4692 * Find tail of file name path, but ignore trailing "/". | |
4693 */ | |
4694 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4695 sm_gettail(char_u *s) |
7 | 4696 { |
4697 char_u *p; | |
4698 char_u *t = s; | |
4699 int had_sep = FALSE; | |
4700 | |
4701 for (p = s; *p != NUL; ) | |
4702 { | |
4703 if (vim_ispathsep(*p) | |
4704 #ifdef BACKSLASH_IN_FILENAME | |
4705 && !rem_backslash(p) | |
4706 #endif | |
4707 ) | |
4708 had_sep = TRUE; | |
4709 else if (had_sep) | |
4710 { | |
4711 t = p; | |
4712 had_sep = FALSE; | |
4713 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4714 MB_PTR_ADV(p); |
7 | 4715 } |
4716 return t; | |
4717 } | |
4718 | |
4719 /* | |
4720 * Return TRUE if we only need to show the tail of completion matches. | |
4721 * When not completing file names or there is a wildcard in the path FALSE is | |
4722 * returned. | |
4723 */ | |
4724 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4725 expand_showtail(expand_T *xp) |
7 | 4726 { |
4727 char_u *s; | |
4728 char_u *end; | |
4729 | |
4730 /* When not completing file names a "/" may mean something different. */ | |
714 | 4731 if (xp->xp_context != EXPAND_FILES |
4732 && xp->xp_context != EXPAND_SHELLCMD | |
4733 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4734 return FALSE; |
4735 | |
4736 end = gettail(xp->xp_pattern); | |
4737 if (end == xp->xp_pattern) /* there is no path separator */ | |
4738 return FALSE; | |
4739 | |
4740 for (s = xp->xp_pattern; s < end; s++) | |
4741 { | |
4742 /* Skip escaped wildcards. Only when the backslash is not a path | |
4743 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4744 if (rem_backslash(s)) | |
4745 ++s; | |
4746 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4747 return FALSE; | |
4748 } | |
4749 return TRUE; | |
4750 } | |
4751 | |
4752 /* | |
4753 * Prepare a string for expansion. | |
4754 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4755 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4756 * When expanding other names: The string will be used with regcomp(). Copy |
4757 * the name into allocated memory and prepend "^". | |
4758 */ | |
4759 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4760 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4761 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4762 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4763 int context) /* EXPAND_FILES etc. */ |
7 | 4764 { |
4765 char_u *retval; | |
4766 int i, j; | |
4767 int new_len; | |
4768 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4769 int ends_in_star; |
7 | 4770 |
714 | 4771 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4772 && context != EXPAND_FILES_IN_PATH |
714 | 4773 && context != EXPAND_SHELLCMD |
4774 && context != EXPAND_DIRECTORIES) | |
7 | 4775 { |
4776 /* | |
4777 * Matching will be done internally (on something other than files). | |
4778 * So we convert the file-matching-type wildcards into our kind for | |
4779 * use with vim_regcomp(). First work out how long it will be: | |
4780 */ | |
4781 | |
4782 /* For help tags the translation is done in find_help_tags(). | |
4783 * For a tag pattern starting with "/" no translation is needed. */ | |
4784 if (context == EXPAND_HELP | |
4785 || context == EXPAND_COLORS | |
4786 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4787 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4788 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4789 || 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
|
4790 || ((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
|
4791 || 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
|
4792 && fname[0] == '/')) |
7 | 4793 retval = vim_strnsave(fname, len); |
4794 else | |
4795 { | |
4796 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4797 for (i = 0; i < len; i++) | |
4798 { | |
4799 if (fname[i] == '*' || fname[i] == '~') | |
4800 new_len++; /* '*' needs to be replaced by ".*" | |
4801 '~' needs to be replaced by "\~" */ | |
4802 | |
4803 /* Buffer names are like file names. "." should be literal */ | |
4804 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4805 new_len++; /* "." becomes "\." */ | |
4806 | |
4807 /* Custom expansion takes care of special things, match | |
4808 * backslashes literally (perhaps also for other types?) */ | |
634 | 4809 if ((context == EXPAND_USER_DEFINED |
4810 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4811 new_len++; /* '\' becomes "\\" */ |
4812 } | |
4813 retval = alloc(new_len); | |
4814 if (retval != NULL) | |
4815 { | |
4816 retval[0] = '^'; | |
4817 j = 1; | |
4818 for (i = 0; i < len; i++, j++) | |
4819 { | |
4820 /* Skip backslash. But why? At least keep it for custom | |
4821 * expansion. */ | |
4822 if (context != EXPAND_USER_DEFINED | |
407 | 4823 && context != EXPAND_USER_LIST |
4824 && fname[i] == '\\' | |
4825 && ++i == len) | |
7 | 4826 break; |
4827 | |
4828 switch (fname[i]) | |
4829 { | |
4830 case '*': retval[j++] = '.'; | |
4831 break; | |
4832 case '~': retval[j++] = '\\'; | |
4833 break; | |
4834 case '?': retval[j] = '.'; | |
4835 continue; | |
4836 case '.': if (context == EXPAND_BUFFERS) | |
4837 retval[j++] = '\\'; | |
4838 break; | |
407 | 4839 case '\\': if (context == EXPAND_USER_DEFINED |
4840 || context == EXPAND_USER_LIST) | |
7 | 4841 retval[j++] = '\\'; |
4842 break; | |
4843 } | |
4844 retval[j] = fname[i]; | |
4845 } | |
4846 retval[j] = NUL; | |
4847 } | |
4848 } | |
4849 } | |
4850 else | |
4851 { | |
4852 retval = alloc(len + 4); | |
4853 if (retval != NULL) | |
4854 { | |
419 | 4855 vim_strncpy(retval, fname, len); |
7 | 4856 |
4857 /* | |
831 | 4858 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4859 * * would become **, which walks the whole tree. | |
7 | 4860 * ~ would be at the start of the file name, but not the tail. |
4861 * $ could be anywhere in the tail. | |
4862 * ` could be anywhere in the file name. | |
1484 | 4863 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4864 */ |
4865 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4866 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
|
4867 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4868 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4869 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4870 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4871 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4872 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4873 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4874 #endif |
7 | 4875 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4876 && !ends_in_star |
7 | 4877 && vim_strchr(tail, '$') == NULL |
4878 && vim_strchr(retval, '`') == NULL) | |
4879 retval[len++] = '*'; | |
1484 | 4880 else if (len > 0 && retval[len - 1] == '$') |
4881 --len; | |
7 | 4882 retval[len] = NUL; |
4883 } | |
4884 } | |
4885 return retval; | |
4886 } | |
4887 | |
4888 /* | |
4889 * Must parse the command line so far to work out what context we are in. | |
4890 * Completion can then be done based on that context. | |
4891 * This routine sets the variables: | |
4892 * xp->xp_pattern The start of the pattern to be expanded within | |
4893 * the command line (ends at the cursor). | |
4894 * xp->xp_context The type of thing to expand. Will be one of: | |
4895 * | |
4896 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4897 * the command line, like an unknown command. Caller | |
4898 * should beep. | |
4899 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4900 * a normal char, rather than for completion. eg | |
4901 * :s/^I/ | |
4902 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4903 * it. | |
4904 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4905 * EXPAND_FILES After command with XFILE set, or after setting | |
4906 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4907 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4908 * when we know only directories are of interest. eg | |
4909 * :set dir=^I | |
714 | 4910 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4911 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4912 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4913 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4914 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4915 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4916 * EXPAND_EVENTS Complete event names | |
4917 * EXPAND_SYNTAX Complete :syntax command arguments | |
4918 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4919 * EXPAND_AUGROUP Complete autocommand group names | |
4920 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4921 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4922 * eg :unmap a^I , :cunab x^I | |
4923 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4924 * eg :call sub^I | |
4925 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4926 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4927 * names in expressions, eg :while s^I | |
4928 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4929 * EXPAND_USER Complete user names |
7 | 4930 */ |
4931 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4932 set_expand_context(expand_T *xp) |
7 | 4933 { |
168 | 4934 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4935 if (ccline.cmdfirstc != ':' |
4936 #ifdef FEAT_EVAL | |
168 | 4937 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4938 && !ccline.input_fn |
7 | 4939 #endif |
4940 ) | |
4941 { | |
4942 xp->xp_context = EXPAND_NOTHING; | |
4943 return; | |
4944 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4945 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4946 } |
4947 | |
4948 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4949 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4950 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4951 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
|
4952 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
|
4953 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4954 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4955 { |
4956 int old_char = NUL; | |
4957 char_u *nextcomm; | |
4958 | |
4959 /* | |
4960 * Avoid a UMR warning from Purify, only save the character if it has been | |
4961 * written before. | |
4962 */ | |
4963 if (col < len) | |
4964 old_char = str[col]; | |
4965 str[col] = NUL; | |
4966 nextcomm = str; | |
168 | 4967 |
4968 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4969 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4970 { |
4971 # ifdef FEAT_CMDL_COMPL | |
168 | 4972 /* pass CMD_SIZE because there is no real command */ |
4973 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4974 # endif |
4975 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4976 else if (use_ccline && ccline.input_fn) |
531 | 4977 { |
4978 xp->xp_context = ccline.xp_context; | |
4979 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4980 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4981 xp->xp_arg = ccline.xp_arg; |
1322 | 4982 # endif |
531 | 4983 } |
168 | 4984 else |
4985 #endif | |
4986 while (nextcomm != NULL) | |
4987 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4988 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4989 /* 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
|
4990 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4991 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4992 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4993 |
7 | 4994 str[col] = old_char; |
4995 } | |
4996 | |
4997 /* | |
4998 * Expand the command line "str" from context "xp". | |
4999 * "xp" must have been set by set_cmd_context(). | |
5000 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
5001 * starts. | |
5002 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
5003 * cursor. | |
5004 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
5005 * key that triggered expansion literally. | |
5006 * Returns EXPAND_OK otherwise. | |
5007 */ | |
5008 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5009 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5010 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5011 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
|
5012 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5013 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5014 char_u ***matches) /* return: array of pointers to matches */ |
7 | 5015 { |
5016 char_u *file_str = NULL; | |
2652 | 5017 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 5018 |
5019 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
5020 { | |
5021 beep_flush(); | |
5022 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
5023 } | |
5024 if (xp->xp_context == EXPAND_NOTHING) | |
5025 { | |
5026 /* Caller can use the character as a normal char instead */ | |
5027 return EXPAND_NOTHING; | |
5028 } | |
5029 | |
5030 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5031 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5032 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5033 if (file_str == NULL) |
5034 return EXPAND_UNSUCCESSFUL; | |
5035 | |
2652 | 5036 if (p_wic) |
5037 options += WILD_ICASE; | |
5038 | |
7 | 5039 /* find all files that match the description */ |
2652 | 5040 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5041 { |
5042 *matchcount = 0; | |
5043 *matches = NULL; | |
5044 } | |
5045 vim_free(file_str); | |
5046 | |
5047 return EXPAND_OK; | |
5048 } | |
5049 | |
5050 #ifdef FEAT_MULTI_LANG | |
5051 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5052 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5053 * 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
|
5054 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5055 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5056 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5057 |
5058 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5059 cleanup_help_tags(int num_file, char_u **file) |
7 | 5060 { |
5061 int i, j; | |
5062 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5063 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5064 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5065 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5066 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
|
5067 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5068 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5069 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5070 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5071 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5072 *p = NUL; |
7 | 5073 |
5074 for (i = 0; i < num_file; ++i) | |
5075 { | |
5076 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
|
5077 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5078 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5079 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5080 { |
5081 /* Sorting on priority means the same item in another language may | |
5082 * be anywhere. Search all items for a match up to the "@en". */ | |
5083 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
|
5084 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
|
5085 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5086 break; |
5087 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5088 /* item only exists with @en, remove it */ |
7 | 5089 file[i][len] = NUL; |
5090 } | |
5091 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5092 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5093 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5094 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
|
5095 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5096 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5097 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5098 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5099 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
|
5100 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5101 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5102 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5103 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5104 } |
7 | 5105 } |
5106 #endif | |
5107 | |
5108 /* | |
5109 * Do the expansion based on xp->xp_context and "pat". | |
5110 */ | |
5111 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5112 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5113 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5114 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5115 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5116 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5117 int options) /* EW_ flags */ |
7 | 5118 { |
5119 #ifdef FEAT_CMDL_COMPL | |
5120 regmatch_T regmatch; | |
5121 #endif | |
5122 int ret; | |
5123 int flags; | |
5124 | |
5125 flags = EW_DIR; /* include directories */ | |
5126 if (options & WILD_LIST_NOTFOUND) | |
5127 flags |= EW_NOTFOUND; | |
5128 if (options & WILD_ADD_SLASH) | |
5129 flags |= EW_ADDSLASH; | |
5130 if (options & WILD_KEEP_ALL) | |
5131 flags |= EW_KEEPALL; | |
5132 if (options & WILD_SILENT) | |
5133 flags |= EW_SILENT; | |
6659 | 5134 if (options & WILD_ALLLINKS) |
5135 flags |= EW_ALLLINKS; | |
7 | 5136 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5137 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5138 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5139 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5140 { |
5141 /* | |
5142 * Expand file or directory names. | |
5143 */ | |
5144 int free_pat = FALSE; | |
5145 int i; | |
5146 | |
5147 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5148 * space */ | |
5149 if (xp->xp_backslash != XP_BS_NONE) | |
5150 { | |
5151 free_pat = TRUE; | |
5152 pat = vim_strsave(pat); | |
5153 for (i = 0; pat[i]; ++i) | |
5154 if (pat[i] == '\\') | |
5155 { | |
5156 if (xp->xp_backslash == XP_BS_THREE | |
5157 && pat[i + 1] == '\\' | |
5158 && pat[i + 2] == '\\' | |
5159 && pat[i + 3] == ' ') | |
1621 | 5160 STRMOVE(pat + i, pat + i + 3); |
7 | 5161 if (xp->xp_backslash == XP_BS_ONE |
5162 && pat[i + 1] == ' ') | |
1621 | 5163 STRMOVE(pat + i, pat + i + 1); |
7 | 5164 } |
5165 } | |
5166 | |
5167 if (xp->xp_context == EXPAND_FILES) | |
5168 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5169 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
|
5170 flags |= (EW_FILE | EW_PATH); |
7 | 5171 else |
5172 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5173 if (options & WILD_ICASE) |
5174 flags |= EW_ICASE; | |
5175 | |
2016 | 5176 /* Expand wildcards, supporting %:h and the like. */ |
5177 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5178 if (free_pat) |
5179 vim_free(pat); | |
5180 return ret; | |
5181 } | |
5182 | |
5183 *file = (char_u **)""; | |
5184 *num_file = 0; | |
5185 if (xp->xp_context == EXPAND_HELP) | |
5186 { | |
1696 | 5187 /* With an empty argument we would get all the help tags, which is |
5188 * very slow. Get matches for "help" instead. */ | |
5189 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5190 num_file, file, FALSE) == OK) | |
7 | 5191 { |
5192 #ifdef FEAT_MULTI_LANG | |
5193 cleanup_help_tags(*num_file, *file); | |
5194 #endif | |
5195 return OK; | |
5196 } | |
5197 return FAIL; | |
5198 } | |
5199 | |
5200 #ifndef FEAT_CMDL_COMPL | |
5201 return FAIL; | |
5202 #else | |
716 | 5203 if (xp->xp_context == EXPAND_SHELLCMD) |
5204 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5205 if (xp->xp_context == EXPAND_OLD_SETTING) |
5206 return ExpandOldSetting(num_file, file); | |
5207 if (xp->xp_context == EXPAND_BUFFERS) | |
5208 return ExpandBufnames(pat, num_file, file, options); | |
5209 if (xp->xp_context == EXPAND_TAGS | |
5210 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5211 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5212 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5213 { |
5214 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5215 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
|
5216 directories); |
2929 | 5217 } |
7 | 5218 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5219 { |
3106 | 5220 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5221 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5222 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5223 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5224 { |
5225 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5226 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5227 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5228 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5229 { |
5230 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
|
5231 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5232 } |
407 | 5233 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5234 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5235 return ExpandUserList(xp, num_file, file); |
407 | 5236 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5237 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5238 return ExpandPackAddDir(pat, num_file, file); |
7 | 5239 |
5240 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5241 if (regmatch.regprog == NULL) | |
5242 return FAIL; | |
5243 | |
5244 /* set ignore-case according to p_ic, p_scs and pat */ | |
5245 regmatch.rm_ic = ignorecase(pat); | |
5246 | |
5247 if (xp->xp_context == EXPAND_SETTINGS | |
5248 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5249 ret = ExpandSettings(xp, ®match, num_file, file); | |
5250 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5251 ret = ExpandMappings(®match, num_file, file); | |
5252 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5253 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5254 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5255 # endif | |
5256 else | |
5257 { | |
5258 static struct expgen | |
5259 { | |
5260 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5261 char_u *((*func)(expand_T *, int)); |
7 | 5262 int ic; |
2849 | 5263 int escaped; |
7 | 5264 } tab[] = |
5265 { | |
2849 | 5266 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5267 {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
|
5268 {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
|
5269 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5270 #ifdef FEAT_CMDHIST |
5271 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5272 #endif | |
7 | 5273 #ifdef FEAT_USR_CMDS |
2849 | 5274 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5275 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5276 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5277 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5278 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5279 #endif |
5280 #ifdef FEAT_EVAL | |
2849 | 5281 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5282 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5283 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5284 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5285 #endif |
5286 #ifdef FEAT_MENU | |
2849 | 5287 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5288 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5289 #endif |
5290 #ifdef FEAT_SYN_HL | |
2849 | 5291 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5292 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5293 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5294 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5295 #endif |
2849 | 5296 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5297 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5298 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5299 #ifdef FEAT_CSCOPE |
2849 | 5300 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5301 #endif |
1868 | 5302 #ifdef FEAT_SIGNS |
2849 | 5303 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5304 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5305 #ifdef FEAT_PROFILE |
2849 | 5306 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5307 #endif |
7 | 5308 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5309 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5310 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5311 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5312 #endif | |
5313 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5314 {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
|
5315 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5316 }; |
5317 int i; | |
5318 | |
5319 /* | |
5320 * Find a context in the table and call the ExpandGeneric() with the | |
5321 * right function to do the expansion. | |
5322 */ | |
5323 ret = FAIL; | |
1880 | 5324 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5325 if (xp->xp_context == tab[i].context) |
5326 { | |
5327 if (tab[i].ic) | |
5328 regmatch.rm_ic = TRUE; | |
2849 | 5329 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5330 tab[i].func, tab[i].escaped); |
7 | 5331 break; |
5332 } | |
5333 } | |
5334 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5335 vim_regfree(regmatch.regprog); |
7 | 5336 |
5337 return ret; | |
5338 #endif /* FEAT_CMDL_COMPL */ | |
5339 } | |
5340 | |
5341 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5342 /* | |
5343 * Expand a list of names. | |
5344 * | |
5345 * Generic function for command line completion. It calls a function to | |
5346 * obtain strings, one by one. The strings are matched against a regexp | |
5347 * program. Matching strings are copied into an array, which is returned. | |
5348 * | |
5349 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5350 */ | |
5351 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5352 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5353 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5354 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5355 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5356 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5357 char_u *((*func)(expand_T *, int)), |
7 | 5358 /* 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
|
5359 int escaped) |
7 | 5360 { |
5361 int i; | |
5362 int count = 0; | |
480 | 5363 int round; |
7 | 5364 char_u *str; |
5365 | |
5366 /* do this loop twice: | |
480 | 5367 * round == 0: count the number of matching names |
5368 * round == 1: copy the matching names into allocated memory | |
7 | 5369 */ |
480 | 5370 for (round = 0; round <= 1; ++round) |
7 | 5371 { |
5372 for (i = 0; ; ++i) | |
5373 { | |
5374 str = (*func)(xp, i); | |
5375 if (str == NULL) /* end of list */ | |
5376 break; | |
5377 if (*str == NUL) /* skip empty strings */ | |
5378 continue; | |
5379 | |
5380 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5381 { | |
480 | 5382 if (round) |
7 | 5383 { |
2849 | 5384 if (escaped) |
5385 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5386 else | |
5387 str = vim_strsave(str); | |
7 | 5388 (*file)[count] = str; |
5389 #ifdef FEAT_MENU | |
5390 if (func == get_menu_names && str != NULL) | |
5391 { | |
5392 /* test for separator added by get_menu_names() */ | |
5393 str += STRLEN(str) - 1; | |
5394 if (*str == '\001') | |
5395 *str = '.'; | |
5396 } | |
5397 #endif | |
5398 } | |
5399 ++count; | |
5400 } | |
5401 } | |
480 | 5402 if (round == 0) |
7 | 5403 { |
5404 if (count == 0) | |
5405 return OK; | |
5406 *num_file = count; | |
5407 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5408 if (*file == NULL) | |
5409 { | |
5410 *file = (char_u **)""; | |
5411 return FAIL; | |
5412 } | |
5413 count = 0; | |
5414 } | |
5415 } | |
480 | 5416 |
828 | 5417 /* Sort the results. Keep menu's in the specified order. */ |
5418 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5419 { |
5420 if (xp->xp_context == EXPAND_EXPRESSION | |
5421 || xp->xp_context == EXPAND_FUNCTIONS | |
5422 || xp->xp_context == EXPAND_USER_FUNC) | |
5423 /* <SNR> functions should be sorted to the end. */ | |
5424 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5425 sort_func_compare); | |
5426 else | |
5427 sort_strings(*file, *num_file); | |
5428 } | |
480 | 5429 |
1322 | 5430 #ifdef FEAT_CMDL_COMPL |
5431 /* Reset the variables used for special highlight names expansion, so that | |
5432 * they don't show up when getting normal highlight names by ID. */ | |
5433 reset_expand_highlight(); | |
5434 #endif | |
5435 | |
7 | 5436 return OK; |
5437 } | |
5438 | |
716 | 5439 /* |
5440 * Complete a shell command. | |
5441 * Returns FAIL or OK; | |
5442 */ | |
5443 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5444 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5445 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
|
5446 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
|
5447 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
|
5448 int flagsarg) /* EW_ flags */ |
716 | 5449 { |
5450 char_u *pat; | |
5451 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5452 char_u *path = NULL; |
716 | 5453 int mustfree = FALSE; |
5454 garray_T ga; | |
5455 char_u *buf = alloc(MAXPATHL); | |
5456 size_t l; | |
5457 char_u *s, *e; | |
5458 int flags = flagsarg; | |
5459 int ret; | |
6695 | 5460 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5461 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5462 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5463 hash_T hash; |
716 | 5464 |
5465 if (buf == NULL) | |
5466 return FAIL; | |
5467 | |
5468 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5469 * space */ | |
5470 pat = vim_strsave(filepat); | |
5471 for (i = 0; pat[i]; ++i) | |
5472 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5473 STRMOVE(pat + i, pat + i + 1); |
716 | 5474 |
6695 | 5475 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5476 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5477 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
|
5478 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5479 path = (char_u *)"."; |
5480 else | |
2630 | 5481 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5482 /* 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
|
5483 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5484 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5485 if (path == NULL) |
5486 path = (char_u *)""; | |
5487 } | |
716 | 5488 |
5489 /* | |
5490 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5491 * collect them in "ga". When "." is not in $PATH also expand for the |
5492 * current directory, to find "subdir/cmd". | |
716 | 5493 */ |
5494 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
|
5495 hash_init(&found_ht); |
6695 | 5496 for (s = path; ; s = e) |
716 | 5497 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5498 #if defined(MSWIN) |
716 | 5499 e = vim_strchr(s, ';'); |
5500 #else | |
5501 e = vim_strchr(s, ':'); | |
5502 #endif | |
5503 if (e == NULL) | |
5504 e = s + STRLEN(s); | |
5505 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5506 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
|
5507 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5508 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
|
5509 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5510 // 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
|
5511 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
|
5512 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
|
5513 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5514 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
|
5515 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5516 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
|
5517 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
|
5518 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5519 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5520 // 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
|
5521 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
|
5522 |
716 | 5523 l = e - s; |
5524 if (l > MAXPATHL - 5) | |
5525 break; | |
5526 vim_strncpy(buf, s, l); | |
5527 add_pathsep(buf); | |
5528 l = STRLEN(buf); | |
5529 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5530 | |
5531 /* Expand matches in one directory of $PATH. */ | |
5532 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5533 if (ret == OK) | |
5534 { | |
5535 if (ga_grow(&ga, *num_file) == FAIL) | |
5536 FreeWild(*num_file, *file); | |
5537 else | |
5538 { | |
5539 for (i = 0; i < *num_file; ++i) | |
5540 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5541 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5542 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5543 if (STRLEN(name) > l) |
716 | 5544 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5545 // 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
|
5546 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5547 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
|
5548 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5549 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5550 // 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
|
5551 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5552 ((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
|
5553 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
|
5554 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5555 } |
716 | 5556 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5557 vim_free(name); |
716 | 5558 } |
5559 vim_free(*file); | |
5560 } | |
5561 } | |
5562 if (*e != NUL) | |
5563 ++e; | |
5564 } | |
5565 *file = ga.ga_data; | |
5566 *num_file = ga.ga_len; | |
5567 | |
5568 vim_free(buf); | |
5569 vim_free(pat); | |
5570 if (mustfree) | |
5571 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5572 hash_clear(&found_ht); |
716 | 5573 return OK; |
5574 } | |
5575 | |
5576 | |
7 | 5577 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5578 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5579 * 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
|
5580 * return the result (either a string or a List). |
7 | 5581 */ |
407 | 5582 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5583 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
|
5584 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
|
5585 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5586 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5587 char_u ***file) |
7 | 5588 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5589 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
|
5590 typval_T args[4]; |
7 | 5591 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
|
5592 char_u *pat = NULL; |
407 | 5593 void *ret; |
13 | 5594 struct cmdline_info save_ccline; |
7 | 5595 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5596 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5597 return NULL; |
7 | 5598 *num_file = 0; |
5599 *file = NULL; | |
5600 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5601 if (ccline.cmdbuff != NULL) |
1518 | 5602 { |
5603 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5604 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5605 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5606 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5607 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
|
5608 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5609 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
|
5610 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
|
5611 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
|
5612 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
|
5613 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
|
5614 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
|
5615 args[3].v_type = VAR_UNKNOWN; |
7 | 5616 |
13 | 5617 /* Save the cmdline, we don't know what the function may do. */ |
5618 save_ccline = ccline; | |
5619 ccline.cmdbuff = NULL; | |
5620 ccline.cmdprompt = NULL; | |
7 | 5621 current_SID = xp->xp_scriptID; |
13 | 5622 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5623 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5624 |
5625 ccline = save_ccline; | |
7 | 5626 current_SID = save_current_SID; |
1518 | 5627 if (ccline.cmdbuff != NULL) |
5628 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5629 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5630 vim_free(pat); |
407 | 5631 return ret; |
5632 } | |
5633 | |
5634 /* | |
5635 * Expand names with a function defined by the user. | |
5636 */ | |
5637 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5638 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5639 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5640 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5641 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5642 char_u ***file) |
407 | 5643 { |
5644 char_u *retstr; | |
5645 char_u *s; | |
5646 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
|
5647 int keep; |
407 | 5648 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
|
5649 int skip; |
407 | 5650 |
5651 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5652 if (retstr == NULL) | |
7 | 5653 return FAIL; |
5654 | |
5655 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5656 for (s = retstr; *s != NUL; s = e) |
7 | 5657 { |
5658 e = vim_strchr(s, '\n'); | |
5659 if (e == NULL) | |
5660 e = s + STRLEN(s); | |
5661 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
|
5662 *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
|
5663 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5664 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
|
5665 *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
|
5666 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5667 if (!skip) |
7 | 5668 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5669 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
|
5670 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5671 ((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
|
5672 ++ga.ga_len; |
7 | 5673 } |
5674 | |
5675 if (*e != NUL) | |
5676 ++e; | |
5677 } | |
407 | 5678 vim_free(retstr); |
5679 *file = ga.ga_data; | |
5680 *num_file = ga.ga_len; | |
5681 return OK; | |
5682 } | |
5683 | |
5684 /* | |
5685 * Expand names with a list returned by a function defined by the user. | |
5686 */ | |
5687 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5688 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5689 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5690 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5691 char_u ***file) |
407 | 5692 { |
5693 list_T *retlist; | |
5694 listitem_T *li; | |
5695 garray_T ga; | |
5696 | |
5697 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5698 if (retlist == NULL) | |
5699 return FAIL; | |
5700 | |
5701 ga_init2(&ga, (int)sizeof(char *), 3); | |
5702 /* Loop over the items in the list. */ | |
5703 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5704 { | |
1917 | 5705 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5706 continue; /* Skip non-string items and empty strings */ | |
407 | 5707 |
5708 if (ga_grow(&ga, 1) == FAIL) | |
5709 break; | |
5710 | |
5711 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5712 vim_strsave(li->li_tv.vval.v_string); |
407 | 5713 ++ga.ga_len; |
5714 } | |
5715 list_unref(retlist); | |
5716 | |
7 | 5717 *file = ga.ga_data; |
5718 *num_file = ga.ga_len; | |
5719 return OK; | |
5720 } | |
5721 #endif | |
5722 | |
5723 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5724 * 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
|
5725 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5726 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5727 * 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
|
5728 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5729 * 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
|
5730 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5731 * "dirnames" is an array with one or more directory names. |
7 | 5732 */ |
5733 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5734 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5735 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5736 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5737 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5738 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5739 char *dirnames[]) |
7 | 5740 { |
5741 char_u *s; | |
5742 char_u *e; | |
5873 | 5743 char_u *match; |
7 | 5744 garray_T ga; |
2929 | 5745 int i; |
5746 int pat_len; | |
7 | 5747 |
5748 *num_file = 0; | |
5749 *file = NULL; | |
2931 | 5750 pat_len = (int)STRLEN(pat); |
2929 | 5751 ga_init2(&ga, (int)sizeof(char *), 10); |
5752 | |
5753 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5754 { |
2929 | 5755 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5756 if (s == NULL) | |
5757 { | |
5758 ga_clear_strings(&ga); | |
5759 return FAIL; | |
5760 } | |
5761 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5762 globpath(p_rtp, s, &ga, 0); |
2929 | 5763 vim_free(s); |
5873 | 5764 } |
5765 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5766 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5767 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
|
5768 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5769 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
|
5770 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5771 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5772 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5773 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5774 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5775 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
|
5776 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5777 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5778 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5779 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5780 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5781 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5782 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
|
5783 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5784 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
|
5785 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5786 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5787 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5788 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5789 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5790 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
|
5791 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5792 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5793 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5794 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5795 |
5873 | 5796 for (i = 0; i < ga.ga_len; ++i) |
5797 { | |
5798 match = ((char_u **)ga.ga_data)[i]; | |
5799 s = match; | |
5800 e = s + STRLEN(s); | |
5801 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5802 { |
5873 | 5803 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5804 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5805 if (s < match || vim_ispathsep(*s)) |
5806 break; | |
5807 ++s; | |
5808 *e = NUL; | |
5809 mch_memmove(match, s, e - s + 1); | |
7 | 5810 } |
5811 } | |
5873 | 5812 |
2929 | 5813 if (ga.ga_len == 0) |
3628 | 5814 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5815 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5816 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5817 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5818 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5819 |
7 | 5820 *file = ga.ga_data; |
5821 *num_file = ga.ga_len; | |
5822 return OK; | |
5823 } | |
5824 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5827 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5828 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5830 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5832 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5833 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5834 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5835 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 int pat_len; |
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 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5843 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5844 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5845 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
|
5846 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5847 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 if (s == NULL) |
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 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5851 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5852 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5853 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
|
5854 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5855 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5856 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5857 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
|
5858 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5859 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
|
5860 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5861 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5862 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
|
5863 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5864 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5865 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5866 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5867 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5868 /* 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
|
5869 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5870 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5871 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5872 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5873 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5874 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5875 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5876 |
7 | 5877 #endif |
5878 | |
5879 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5880 /* | |
5881 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5882 * Adds the matches to "ga". Caller must init "ga". |
7 | 5883 */ |
5873 | 5884 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5885 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5886 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5887 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5888 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5889 int expand_options) |
7 | 5890 { |
5891 expand_T xpc; | |
5892 char_u *buf; | |
5893 int i; | |
5894 int num_p; | |
5895 char_u **p; | |
5896 | |
5897 buf = alloc(MAXPATHL); | |
5898 if (buf == NULL) | |
5873 | 5899 return; |
7 | 5900 |
632 | 5901 ExpandInit(&xpc); |
7 | 5902 xpc.xp_context = EXPAND_FILES; |
632 | 5903 |
7 | 5904 /* Loop over all entries in {path}. */ |
5905 while (*path != NUL) | |
5906 { | |
5907 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5908 copy_option_part(&path, buf, MAXPATHL, ","); | |
5909 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5910 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5911 # 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
|
5912 /* 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
|
5913 * 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
|
5914 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
|
5915 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5916 # else |
7 | 5917 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
|
5918 # endif |
7 | 5919 STRCAT(buf, file); |
1754 | 5920 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5921 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5922 { |
1754 | 5923 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5924 |
5925 if (ga_grow(ga, num_p) == OK) | |
7 | 5926 { |
5927 for (i = 0; i < num_p; ++i) | |
5928 { | |
5873 | 5929 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5930 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5931 ++ga->ga_len; |
7 | 5932 } |
5933 } | |
5873 | 5934 |
7 | 5935 FreeWild(num_p, p); |
5936 } | |
5937 } | |
5938 } | |
5939 | |
5940 vim_free(buf); | |
5941 } | |
5942 | |
5943 #endif | |
5944 | |
5945 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5946 | |
5947 /********************************* | |
5948 * Command line history stuff * | |
5949 *********************************/ | |
5950 | |
5951 /* | |
5952 * Translate a history character to the associated type number. | |
5953 */ | |
5954 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5955 hist_char2type(int c) |
7 | 5956 { |
5957 if (c == ':') | |
5958 return HIST_CMD; | |
5959 if (c == '=') | |
5960 return HIST_EXPR; | |
5961 if (c == '@') | |
5962 return HIST_INPUT; | |
5963 if (c == '>') | |
5964 return HIST_DEBUG; | |
5965 return HIST_SEARCH; /* must be '?' or '/' */ | |
5966 } | |
5967 | |
5968 /* | |
5969 * Table of history names. | |
5970 * These names are used in :history and various hist...() functions. | |
5971 * It is sufficient to give the significant prefix of a history name. | |
5972 */ | |
5973 | |
5974 static char *(history_names[]) = | |
5975 { | |
5976 "cmd", | |
5977 "search", | |
5978 "expr", | |
5979 "input", | |
5980 "debug", | |
5981 NULL | |
5982 }; | |
5983 | |
3503 | 5984 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5985 /* | |
5986 * Function given to ExpandGeneric() to obtain the possible first | |
5987 * arguments of the ":history command. | |
5988 */ | |
5989 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5990 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5991 { |
5992 static char_u compl[2] = { NUL, NUL }; | |
5993 char *short_names = ":=@>?/"; | |
3529 | 5994 int short_names_count = (int)STRLEN(short_names); |
3503 | 5995 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5996 | |
5997 if (idx < short_names_count) | |
5998 { | |
5999 compl[0] = (char_u)short_names[idx]; | |
6000 return compl; | |
6001 } | |
6002 if (idx < short_names_count + history_name_count) | |
6003 return (char_u *)history_names[idx - short_names_count]; | |
6004 if (idx == short_names_count + history_name_count) | |
6005 return (char_u *)"all"; | |
6006 return NULL; | |
6007 } | |
6008 #endif | |
6009 | |
7 | 6010 /* |
6011 * init_history() - Initialize the command line history. | |
6012 * Also used to re-allocate the history when the size changes. | |
6013 */ | |
356 | 6014 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6015 init_history(void) |
7 | 6016 { |
6017 int newlen; /* new length of history table */ | |
6018 histentry_T *temp; | |
6019 int i; | |
6020 int j; | |
6021 int type; | |
6022 | |
6023 /* | |
6024 * If size of history table changed, reallocate it | |
6025 */ | |
6026 newlen = (int)p_hi; | |
6027 if (newlen != hislen) /* history length changed */ | |
6028 { | |
6029 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6030 { | |
6031 if (newlen) | |
6032 { | |
6033 temp = (histentry_T *)lalloc( | |
6034 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6035 if (temp == NULL) /* out of memory! */ | |
6036 { | |
6037 if (type == 0) /* first one: just keep the old length */ | |
6038 { | |
6039 newlen = hislen; | |
6040 break; | |
6041 } | |
6042 /* Already changed one table, now we can only have zero | |
6043 * length for all tables. */ | |
6044 newlen = 0; | |
6045 type = -1; | |
6046 continue; | |
6047 } | |
6048 } | |
6049 else | |
6050 temp = NULL; | |
6051 if (newlen == 0 || temp != NULL) | |
6052 { | |
6053 if (hisidx[type] < 0) /* there are no entries yet */ | |
6054 { | |
6055 for (i = 0; i < newlen; ++i) | |
4258 | 6056 clear_hist_entry(&temp[i]); |
7 | 6057 } |
6058 else if (newlen > hislen) /* array becomes bigger */ | |
6059 { | |
6060 for (i = 0; i <= hisidx[type]; ++i) | |
6061 temp[i] = history[type][i]; | |
6062 j = i; | |
6063 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6064 clear_hist_entry(&temp[i]); |
7 | 6065 for ( ; j < hislen; ++i, ++j) |
6066 temp[i] = history[type][j]; | |
6067 } | |
6068 else /* array becomes smaller or 0 */ | |
6069 { | |
6070 j = hisidx[type]; | |
6071 for (i = newlen - 1; ; --i) | |
6072 { | |
6073 if (i >= 0) /* copy newest entries */ | |
6074 temp[i] = history[type][j]; | |
6075 else /* remove older entries */ | |
6076 vim_free(history[type][j].hisstr); | |
6077 if (--j < 0) | |
6078 j = hislen - 1; | |
6079 if (j == hisidx[type]) | |
6080 break; | |
6081 } | |
6082 hisidx[type] = newlen - 1; | |
6083 } | |
6084 vim_free(history[type]); | |
6085 history[type] = temp; | |
6086 } | |
6087 } | |
6088 hislen = newlen; | |
6089 } | |
6090 } | |
6091 | |
4258 | 6092 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6093 clear_hist_entry(histentry_T *hisptr) |
4258 | 6094 { |
6095 hisptr->hisnum = 0; | |
6096 hisptr->viminfo = FALSE; | |
6097 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6098 hisptr->time_set = 0; |
4258 | 6099 } |
6100 | |
7 | 6101 /* |
6102 * Check if command line 'str' is already in history. | |
6103 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6104 */ | |
6105 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6106 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6107 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6108 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6109 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
|
6110 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6111 int writing) /* ignore entries read from viminfo */ |
7 | 6112 { |
6113 int i; | |
6114 int last_i = -1; | |
2986 | 6115 char_u *p; |
7 | 6116 |
6117 if (hisidx[type] < 0) | |
6118 return FALSE; | |
6119 i = hisidx[type]; | |
6120 do | |
6121 { | |
6122 if (history[type][i].hisstr == NULL) | |
6123 return FALSE; | |
2986 | 6124 |
6125 /* For search history, check that the separator character matches as | |
6126 * well. */ | |
6127 p = history[type][i].hisstr; | |
6128 if (STRCMP(str, p) == 0 | |
4285 | 6129 && !(writing && history[type][i].viminfo) |
2986 | 6130 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6131 { |
6132 if (!move_to_front) | |
6133 return TRUE; | |
6134 last_i = i; | |
6135 break; | |
6136 } | |
6137 if (--i < 0) | |
6138 i = hislen - 1; | |
6139 } while (i != hisidx[type]); | |
6140 | |
6141 if (last_i >= 0) | |
6142 { | |
6143 str = history[type][i].hisstr; | |
6144 while (i != hisidx[type]) | |
6145 { | |
6146 if (++i >= hislen) | |
6147 i = 0; | |
6148 history[type][last_i] = history[type][i]; | |
6149 last_i = i; | |
6150 } | |
4258 | 6151 history[type][i].hisnum = ++hisnum[type]; |
6152 history[type][i].viminfo = FALSE; | |
7 | 6153 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6154 history[type][i].time_set = vim_time(); |
7 | 6155 return TRUE; |
6156 } | |
6157 return FALSE; | |
6158 } | |
6159 | |
6160 /* | |
6161 * Convert history name (from table above) to its HIST_ equivalent. | |
6162 * When "name" is empty, return "cmd" history. | |
6163 * Returns -1 for unknown history name. | |
6164 */ | |
6165 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6166 get_histtype(char_u *name) |
7 | 6167 { |
6168 int i; | |
6169 int len = (int)STRLEN(name); | |
6170 | |
6171 /* No argument: use current history. */ | |
6172 if (len == 0) | |
6173 return hist_char2type(ccline.cmdfirstc); | |
6174 | |
6175 for (i = 0; history_names[i] != NULL; ++i) | |
6176 if (STRNICMP(name, history_names[i], len) == 0) | |
6177 return i; | |
6178 | |
6179 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6180 return hist_char2type(name[0]); | |
6181 | |
6182 return -1; | |
6183 } | |
6184 | |
6185 static int last_maptick = -1; /* last seen maptick */ | |
6186 | |
6187 /* | |
6188 * Add the given string to the given history. If the string is already in the | |
6189 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6190 * values. | |
6191 */ | |
6192 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6193 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6194 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6195 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6196 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
|
6197 int sep) /* separator character used (search hist) */ |
7 | 6198 { |
6199 histentry_T *hisptr; | |
6200 int len; | |
6201 | |
6202 if (hislen == 0) /* no history */ | |
6203 return; | |
6204 | |
5467 | 6205 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6206 return; | |
6207 | |
7 | 6208 /* |
6209 * Searches inside the same mapping overwrite each other, so that only | |
6210 * the last line is kept. Be careful not to remove a line that was moved | |
6211 * down, only lines that were added. | |
6212 */ | |
6213 if (histype == HIST_SEARCH && in_map) | |
6214 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6215 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6216 { |
6217 /* Current line is from the same mapping, remove it */ | |
6218 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6219 vim_free(hisptr->hisstr); | |
4258 | 6220 clear_hist_entry(hisptr); |
7 | 6221 --hisnum[histype]; |
6222 if (--hisidx[HIST_SEARCH] < 0) | |
6223 hisidx[HIST_SEARCH] = hislen - 1; | |
6224 } | |
6225 last_maptick = -1; | |
6226 } | |
4285 | 6227 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6228 { |
6229 if (++hisidx[histype] == hislen) | |
6230 hisidx[histype] = 0; | |
6231 hisptr = &history[histype][hisidx[histype]]; | |
6232 vim_free(hisptr->hisstr); | |
6233 | |
6234 /* Store the separator after the NUL of the string. */ | |
835 | 6235 len = (int)STRLEN(new_entry); |
7 | 6236 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6237 if (hisptr->hisstr != NULL) | |
6238 hisptr->hisstr[len + 1] = sep; | |
6239 | |
6240 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6241 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6242 hisptr->time_set = vim_time(); |
7 | 6243 if (histype == HIST_SEARCH && in_map) |
6244 last_maptick = maptick; | |
6245 } | |
6246 } | |
6247 | |
6248 #if defined(FEAT_EVAL) || defined(PROTO) | |
6249 | |
6250 /* | |
6251 * Get identifier of newest history entry. | |
6252 * "histype" may be one of the HIST_ values. | |
6253 */ | |
6254 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6255 get_history_idx(int histype) |
7 | 6256 { |
6257 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6258 || hisidx[histype] < 0) | |
6259 return -1; | |
6260 | |
6261 return history[histype][hisidx[histype]].hisnum; | |
6262 } | |
6263 | |
531 | 6264 /* |
7 | 6265 * Calculate history index from a number: |
6266 * num > 0: seen as identifying number of a history entry | |
6267 * num < 0: relative position in history wrt newest entry | |
6268 * "histype" may be one of the HIST_ values. | |
6269 */ | |
6270 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6271 calc_hist_idx(int histype, int num) |
7 | 6272 { |
6273 int i; | |
6274 histentry_T *hist; | |
6275 int wrapped = FALSE; | |
6276 | |
6277 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6278 || (i = hisidx[histype]) < 0 || num == 0) | |
6279 return -1; | |
6280 | |
6281 hist = history[histype]; | |
6282 if (num > 0) | |
6283 { | |
6284 while (hist[i].hisnum > num) | |
6285 if (--i < 0) | |
6286 { | |
6287 if (wrapped) | |
6288 break; | |
6289 i += hislen; | |
6290 wrapped = TRUE; | |
6291 } | |
6292 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6293 return i; | |
6294 } | |
6295 else if (-num <= hislen) | |
6296 { | |
6297 i += num + 1; | |
6298 if (i < 0) | |
6299 i += hislen; | |
6300 if (hist[i].hisstr != NULL) | |
6301 return i; | |
6302 } | |
6303 return -1; | |
6304 } | |
6305 | |
6306 /* | |
6307 * Get a history entry by its index. | |
6308 * "histype" may be one of the HIST_ values. | |
6309 */ | |
6310 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6311 get_history_entry(int histype, int idx) |
7 | 6312 { |
6313 idx = calc_hist_idx(histype, idx); | |
6314 if (idx >= 0) | |
6315 return history[histype][idx].hisstr; | |
6316 else | |
6317 return (char_u *)""; | |
6318 } | |
6319 | |
6320 /* | |
6321 * Clear all entries of 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 clr_history(int histype) |
7 | 6326 { |
6327 int i; | |
6328 histentry_T *hisptr; | |
6329 | |
6330 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6331 { | |
6332 hisptr = history[histype]; | |
6333 for (i = hislen; i--;) | |
6334 { | |
6335 vim_free(hisptr->hisstr); | |
4258 | 6336 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6337 hisptr++; |
7 | 6338 } |
6339 hisidx[histype] = -1; /* mark history as cleared */ | |
6340 hisnum[histype] = 0; /* reset identifier counter */ | |
6341 return OK; | |
6342 } | |
6343 return FAIL; | |
6344 } | |
6345 | |
6346 /* | |
6347 * Remove all entries matching {str} from a history. | |
6348 * "histype" may be one of the HIST_ values. | |
6349 */ | |
6350 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6351 del_history_entry(int histype, char_u *str) |
7 | 6352 { |
6353 regmatch_T regmatch; | |
6354 histentry_T *hisptr; | |
6355 int idx; | |
6356 int i; | |
6357 int last; | |
6358 int found = FALSE; | |
6359 | |
6360 regmatch.regprog = NULL; | |
6361 regmatch.rm_ic = FALSE; /* always match case */ | |
6362 if (hislen != 0 | |
6363 && histype >= 0 | |
6364 && histype < HIST_COUNT | |
6365 && *str != NUL | |
6366 && (idx = hisidx[histype]) >= 0 | |
6367 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6368 != NULL) | |
6369 { | |
6370 i = last = idx; | |
6371 do | |
6372 { | |
6373 hisptr = &history[histype][i]; | |
6374 if (hisptr->hisstr == NULL) | |
6375 break; | |
6376 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6377 { | |
6378 found = TRUE; | |
6379 vim_free(hisptr->hisstr); | |
4258 | 6380 clear_hist_entry(hisptr); |
7 | 6381 } |
6382 else | |
6383 { | |
6384 if (i != last) | |
6385 { | |
6386 history[histype][last] = *hisptr; | |
4258 | 6387 clear_hist_entry(hisptr); |
7 | 6388 } |
6389 if (--last < 0) | |
6390 last += hislen; | |
6391 } | |
6392 if (--i < 0) | |
6393 i += hislen; | |
6394 } while (i != idx); | |
6395 if (history[histype][idx].hisstr == NULL) | |
6396 hisidx[histype] = -1; | |
6397 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6398 vim_regfree(regmatch.regprog); |
7 | 6399 return found; |
6400 } | |
6401 | |
6402 /* | |
6403 * Remove an indexed entry from a history. | |
6404 * "histype" may be one of the HIST_ values. | |
6405 */ | |
6406 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6407 del_history_idx(int histype, int idx) |
7 | 6408 { |
6409 int i, j; | |
6410 | |
6411 i = calc_hist_idx(histype, idx); | |
6412 if (i < 0) | |
6413 return FALSE; | |
6414 idx = hisidx[histype]; | |
6415 vim_free(history[histype][i].hisstr); | |
6416 | |
6417 /* When deleting the last added search string in a mapping, reset | |
6418 * last_maptick, so that the last added search string isn't deleted again. | |
6419 */ | |
6420 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6421 last_maptick = -1; | |
6422 | |
6423 while (i != idx) | |
6424 { | |
6425 j = (i + 1) % hislen; | |
6426 history[histype][i] = history[histype][j]; | |
6427 i = j; | |
6428 } | |
4258 | 6429 clear_hist_entry(&history[histype][i]); |
7 | 6430 if (--i < 0) |
6431 i += hislen; | |
6432 hisidx[histype] = i; | |
6433 return TRUE; | |
6434 } | |
6435 | |
6436 #endif /* FEAT_EVAL */ | |
6437 | |
6438 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6439 /* | |
6440 * Very specific function to remove the value in ":set key=val" from the | |
6441 * history. | |
6442 */ | |
6443 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6444 remove_key_from_history(void) |
7 | 6445 { |
6446 char_u *p; | |
6447 int i; | |
6448 | |
6449 i = hisidx[HIST_CMD]; | |
6450 if (i < 0) | |
6451 return; | |
6452 p = history[HIST_CMD][i].hisstr; | |
6453 if (p != NULL) | |
6454 for ( ; *p; ++p) | |
6455 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6456 { | |
6457 p = vim_strchr(p + 3, '='); | |
6458 if (p == NULL) | |
6459 break; | |
6460 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6461 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6462 if (p[i] == '\\' && p[i + 1]) |
6463 ++i; | |
1621 | 6464 STRMOVE(p, p + i); |
7 | 6465 --p; |
6466 } | |
6467 } | |
6468 #endif | |
6469 | |
6470 #endif /* FEAT_CMDHIST */ | |
6471 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6472 #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
|
6473 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 * 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
|
6475 * 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
|
6476 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6478 get_ccline_ptr(void) |
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 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 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
|
6485 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6486 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6487 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6488 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6489 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6490 #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
|
6491 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 * 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
|
6493 * 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
|
6494 * Returns NULL when something is wrong. |
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 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6498 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 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
|
6500 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6501 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6503 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
|
6504 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 |
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 * 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
|
6508 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6509 * 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
|
6510 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6511 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6512 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6513 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6514 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6515 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
|
6516 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6517 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6519 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 } |
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 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 * 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
|
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 1 when failed, 0 when OK. |
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 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6529 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 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
|
6532 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6533 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6534 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6535 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6536 /* 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
|
6537 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6538 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6539 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6541 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6542 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6543 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6544 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6545 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6546 #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
|
6547 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6548 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6549 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6550 * 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
|
6551 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6552 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6553 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6554 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6555 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6556 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
|
6557 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6558 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6559 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6560 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6561 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6562 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6563 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6564 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6565 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6566 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6567 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6568 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6569 |
7 | 6570 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6571 /* | |
6572 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6573 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6574 * Returns OK if parsed successfully, otherwise FAIL. | |
6575 */ | |
6576 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6577 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6578 { |
6579 int len; | |
6580 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6581 varnumber_T num; |
7 | 6582 |
6583 *str = skipwhite(*str); | |
6584 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6585 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6586 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6587 *str += len; |
6588 *num1 = (int)num; | |
6589 first = TRUE; | |
6590 } | |
6591 *str = skipwhite(*str); | |
6592 if (**str == ',') /* parse "to" part of range */ | |
6593 { | |
6594 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6595 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6596 if (len > 0) |
6597 { | |
6598 *num2 = (int)num; | |
6599 *str = skipwhite(*str + len); | |
6600 } | |
6601 else if (!first) /* no number given at all */ | |
6602 return FAIL; | |
6603 } | |
6604 else if (first) /* only one number given */ | |
6605 *num2 = *num1; | |
6606 return OK; | |
6607 } | |
6608 #endif | |
6609 | |
6610 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6611 /* | |
6612 * :history command - print a history | |
6613 */ | |
6614 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6615 ex_history(exarg_T *eap) |
7 | 6616 { |
6617 histentry_T *hist; | |
6618 int histype1 = HIST_CMD; | |
6619 int histype2 = HIST_CMD; | |
6620 int hisidx1 = 1; | |
6621 int hisidx2 = -1; | |
6622 int idx; | |
6623 int i, j, k; | |
6624 char_u *end; | |
6625 char_u *arg = eap->arg; | |
6626 | |
6627 if (hislen == 0) | |
6628 { | |
6629 MSG(_("'history' option is zero")); | |
6630 return; | |
6631 } | |
6632 | |
6633 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6634 { | |
6635 end = arg; | |
6636 while (ASCII_ISALPHA(*end) | |
6637 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6638 end++; | |
6639 i = *end; | |
6640 *end = NUL; | |
6641 histype1 = get_histtype(arg); | |
6642 if (histype1 == -1) | |
6643 { | |
1853 | 6644 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6645 { |
6646 histype1 = 0; | |
6647 histype2 = HIST_COUNT-1; | |
6648 } | |
6649 else | |
6650 { | |
6651 *end = i; | |
6652 EMSG(_(e_trailing)); | |
6653 return; | |
6654 } | |
6655 } | |
6656 else | |
6657 histype2 = histype1; | |
6658 *end = i; | |
6659 } | |
6660 else | |
6661 end = arg; | |
6662 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6663 { | |
6664 EMSG(_(e_trailing)); | |
6665 return; | |
6666 } | |
6667 | |
6668 for (; !got_int && histype1 <= histype2; ++histype1) | |
6669 { | |
6670 STRCPY(IObuff, "\n # "); | |
6671 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6672 MSG_PUTS_TITLE(IObuff); | |
6673 idx = hisidx[histype1]; | |
6674 hist = history[histype1]; | |
6675 j = hisidx1; | |
6676 k = hisidx2; | |
6677 if (j < 0) | |
6678 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6679 if (k < 0) | |
6680 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6681 if (idx >= 0 && j <= k) | |
6682 for (i = idx + 1; !got_int; ++i) | |
6683 { | |
6684 if (i == hislen) | |
6685 i = 0; | |
6686 if (hist[i].hisstr != NULL | |
6687 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6688 { | |
6689 msg_putchar('\n'); | |
6690 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6691 hist[i].hisnum); | |
6692 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6693 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6694 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6695 else |
6696 STRCAT(IObuff, hist[i].hisstr); | |
6697 msg_outtrans(IObuff); | |
6698 out_flush(); | |
6699 } | |
6700 if (i == idx) | |
6701 break; | |
6702 } | |
6703 } | |
6704 } | |
6705 #endif | |
6706 | |
6707 #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
|
6708 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6709 * 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
|
6710 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6711 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
|
6712 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6713 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
|
6714 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6715 static int viminfo_add_at_front = FALSE; |
6716 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6717 static int hist_type2char(int type, int use_question); |
7 | 6718 |
6719 /* | |
6720 * Translate a history type number to the associated character. | |
6721 */ | |
6722 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6723 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6724 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6725 int use_question) /* use '?' instead of '/' */ |
7 | 6726 { |
6727 if (type == HIST_CMD) | |
6728 return ':'; | |
6729 if (type == HIST_SEARCH) | |
6730 { | |
6731 if (use_question) | |
6732 return '?'; | |
6733 else | |
6734 return '/'; | |
6735 } | |
6736 if (type == HIST_EXPR) | |
6737 return '='; | |
6738 return '@'; | |
6739 } | |
6740 | |
6741 /* | |
6742 * Prepare for reading the history from the viminfo file. | |
6743 * This allocates history arrays to store the read history lines. | |
6744 */ | |
6745 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6746 prepare_viminfo_history(int asklen, int writing) |
7 | 6747 { |
6748 int i; | |
6749 int num; | |
6750 int type; | |
6751 int len; | |
6752 | |
6753 init_history(); | |
4285 | 6754 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6755 if (asklen > hislen) |
6756 asklen = hislen; | |
6757 | |
6758 for (type = 0; type < HIST_COUNT; ++type) | |
6759 { | |
4258 | 6760 /* Count the number of empty spaces in the history list. Entries read |
6761 * from viminfo previously are also considered empty. If there are | |
6762 * more spaces available than we request, then fill them up. */ | |
7 | 6763 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6764 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6765 num++; |
6766 len = asklen; | |
6767 if (num > len) | |
6768 len = num; | |
6769 if (len <= 0) | |
6770 viminfo_history[type] = NULL; | |
6771 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6773 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6774 if (viminfo_history[type] == NULL) |
6775 len = 0; | |
6776 viminfo_hislen[type] = len; | |
6777 viminfo_hisidx[type] = 0; | |
6778 } | |
6779 } | |
6780 | |
6781 /* | |
6782 * Accept a line from the viminfo, store it in the history array when it's | |
6783 * new. | |
6784 */ | |
6785 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6786 read_viminfo_history(vir_T *virp, int writing) |
7 | 6787 { |
6788 int type; | |
6789 long_u len; | |
6790 char_u *val; | |
6791 char_u *p; | |
6792 | |
6793 type = hist_char2type(virp->vir_line[0]); | |
6794 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6795 { | |
6796 val = viminfo_readstring(virp, 1, TRUE); | |
6797 if (val != NULL && *val != NUL) | |
6798 { | |
3316 | 6799 int sep = (*val == ' ' ? NUL : *val); |
6800 | |
7 | 6801 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6802 viminfo_add_at_front, sep, writing)) |
7 | 6803 { |
6804 /* Need to re-allocate to append the separator byte. */ | |
6805 len = STRLEN(val); | |
6806 p = lalloc(len + 2, TRUE); | |
6807 if (p != NULL) | |
6808 { | |
6809 if (type == HIST_SEARCH) | |
6810 { | |
6811 /* Search entry: Move the separator from the first | |
6812 * column to after the NUL. */ | |
6813 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6814 p[len] = sep; |
7 | 6815 } |
6816 else | |
6817 { | |
6818 /* Not a search entry: No separator in the viminfo | |
6819 * file, add a NUL separator. */ | |
6820 mch_memmove(p, val, (size_t)len + 1); | |
6821 p[len + 1] = NUL; | |
6822 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6823 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
|
6824 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
|
6825 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
|
6826 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
|
6827 viminfo_hisidx[type]++; |
7 | 6828 } |
6829 } | |
6830 } | |
6831 vim_free(val); | |
6832 } | |
6833 return viminfo_readline(virp); | |
6834 } | |
6835 | |
4285 | 6836 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6837 * 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
|
6838 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6841 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6842 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6843 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6844 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6845 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6846 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6849 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
|
6850 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6851 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6853 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6854 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6855 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6856 || (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
|
6857 || 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
|
6858 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6859 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6860 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6862 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6863 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
|
6864 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6865 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6866 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6868 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
|
6869 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6870 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6871 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6872 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6873 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
|
6874 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6875 /* 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
|
6876 * 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
|
6877 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
|
6878 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6879 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6880 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6881 && (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
|
6882 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6883 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 break; |
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 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6889 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6890 /* 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
|
6891 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6892 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6893 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6894 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6895 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6896 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6897 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6898 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
|
6899 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6900 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6901 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
|
6902 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6903 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6904 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
|
6905 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 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
|
6907 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6908 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6909 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6910 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6911 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6912 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6913 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6914 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6915 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 * 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
|
6917 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 else |
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 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 do |
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 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 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
|
6947 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 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
|
6950 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 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
|
6952 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 idx = hislen - 1; |
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 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 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
|
6958 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6962 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 #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
|
6965 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6968 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 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
|
6970 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 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
|
6975 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
|
6976 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6978 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6979 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 * 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
|
6982 * timestamp; |
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 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6985 merge_history(int type) |
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 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6990 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6991 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6993 /* 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
|
6994 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 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
|
6996 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
|
6997 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
|
6998 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6999 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7000 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 } |
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 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
|
7005 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7007 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7008 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7009 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7010 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7011 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
|
7012 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7013 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7014 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7015 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7017 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7018 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7020 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7021 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7022 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7023 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7024 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7025 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7026 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
|
7027 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7028 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7029 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
|
7030 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
|
7031 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7032 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7033 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7034 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7035 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7036 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7037 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7038 /* |
4285 | 7039 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7040 */ | |
7 | 7041 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7042 finish_viminfo_history(vir_T *virp) |
7 | 7043 { |
7044 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7045 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7046 |
7047 for (type = 0; type < HIST_COUNT; ++type) | |
7048 { | |
7049 if (history[type] == NULL) | |
4283 | 7050 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7051 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7052 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7053 merge_history(type); |
7 | 7054 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7055 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7056 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7057 VIM_CLEAR(viminfo_history[type]); |
4327 | 7058 viminfo_hisidx[type] = 0; |
7 | 7059 } |
7060 } | |
7061 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7062 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7063 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7064 * 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
|
7065 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7066 * 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
|
7067 */ |
7 | 7068 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7069 write_viminfo_history(FILE *fp, int merge) |
7 | 7070 { |
7071 int i; | |
7072 int type; | |
7073 int num_saved; | |
4283 | 7074 int round; |
7 | 7075 |
7076 init_history(); | |
7077 if (hislen == 0) | |
7078 return; | |
7079 for (type = 0; type < HIST_COUNT; ++type) | |
7080 { | |
7081 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7082 if (num_saved == 0) | |
7083 continue; | |
7084 if (num_saved < 0) /* Use default */ | |
7085 num_saved = hislen; | |
7086 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7087 type == HIST_CMD ? _("Command Line") : | |
7088 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7089 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7090 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7091 _("Debug Line")); |
7 | 7092 if (num_saved > hislen) |
7093 num_saved = hislen; | |
4283 | 7094 |
7095 /* | |
7096 * Merge typed and viminfo history: | |
7097 * round 1: history of typed commands. | |
7098 * round 2: history from recently read viminfo. | |
7099 */ | |
7100 for (round = 1; round <= 2; ++round) | |
7101 { | |
4307 | 7102 if (round == 1) |
7103 /* start at newest entry, somewhere in the list */ | |
7104 i = hisidx[type]; | |
7105 else if (viminfo_hisidx[type] > 0) | |
7106 /* start at newest entry, first in the list */ | |
7107 i = 0; | |
7108 else | |
7109 /* empty list */ | |
7110 i = -1; | |
4283 | 7111 if (i >= 0) |
7112 while (num_saved > 0 | |
7113 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7114 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7115 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7116 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7117 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7118 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7119 if (round == 1) |
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 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7122 timestamp = history[type][i].time_set; |
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 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7125 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7126 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7127 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7128 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7129 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7130 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7131 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7132 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7133 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7134 || !history[type][i].viminfo)) |
7 | 7135 { |
4283 | 7136 --num_saved; |
7137 fputc(hist_type2char(type, TRUE), fp); | |
7138 /* For the search history: put the separator in the | |
7139 * second column; use a space if there isn't one. */ | |
7140 if (type == HIST_SEARCH) | |
7141 { | |
7142 c = p[STRLEN(p) + 1]; | |
7143 putc(c == NUL ? ' ' : c, fp); | |
7144 } | |
7145 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7146 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7147 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7148 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7149 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7150 /* 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
|
7151 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7152 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7153 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7154 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7155 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7156 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
|
7157 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7158 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7159 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7160 } |
7 | 7161 } |
4283 | 7162 if (round == 1) |
7163 { | |
7164 /* Decrement index, loop around and stop when back at | |
7165 * the start. */ | |
7166 if (--i < 0) | |
7167 i = hislen - 1; | |
7168 if (i == hisidx[type]) | |
7169 break; | |
7170 } | |
7171 else | |
7172 { | |
7173 /* Increment index. Stop at the end in the while. */ | |
7174 ++i; | |
7175 } | |
7 | 7176 } |
4283 | 7177 } |
4285 | 7178 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7179 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7180 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
|
7181 VIM_CLEAR(viminfo_history[type]); |
4311 | 7182 viminfo_hisidx[type] = 0; |
7 | 7183 } |
7184 } | |
7185 #endif /* FEAT_VIMINFO */ | |
7186 | |
7187 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7188 /* | |
7189 * Write a character at the current cursor+offset position. | |
7190 * It is directly written into the command buffer block. | |
7191 */ | |
7192 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7193 cmd_pchar(int c, int offset) |
7 | 7194 { |
7195 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7196 { | |
7197 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7198 return; | |
7199 } | |
7200 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7201 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7202 } | |
7203 | |
7204 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7205 cmd_gchar(int offset) |
7 | 7206 { |
7207 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7208 { | |
7209 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7210 return NUL; | |
7211 } | |
7212 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7213 } | |
7214 #endif | |
7215 | |
7216 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7217 /* | |
7218 * Open a window on the current command line and history. Allow editing in | |
7219 * the window. Returns when the window is closed. | |
7220 * Returns: | |
7221 * CR if the command is to be executed | |
7222 * Ctrl_C if it is to be abandoned | |
7223 * K_IGNORE if editing continues | |
7224 */ | |
7225 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
|
7226 open_cmdwin(void) |
7 | 7227 { |
7228 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7229 bufref_T old_curbuf; |
7 | 7230 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7231 bufref_T bufref; |
7 | 7232 win_T *wp; |
7233 int i; | |
7234 linenr_T lnum; | |
7235 int histtype; | |
7236 garray_T winsizes; | |
7237 int save_restart_edit = restart_edit; | |
7238 int save_State = State; | |
7239 int save_exmode = exmode_active; | |
510 | 7240 #ifdef FEAT_RIGHTLEFT |
7241 int save_cmdmsg_rl = cmdmsg_rl; | |
7242 #endif | |
6145 | 7243 #ifdef FEAT_FOLDING |
7244 int save_KeyTyped; | |
7245 #endif | |
7 | 7246 |
7247 /* Can't do this recursively. Can't do it when typing a password. */ | |
7248 if (cmdwin_type != 0 | |
7249 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7250 || cmdline_star > 0 | |
7251 # endif | |
7252 ) | |
7253 { | |
7254 beep_flush(); | |
7255 return K_IGNORE; | |
7256 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7257 set_bufref(&old_curbuf, curbuf); |
7 | 7258 |
7259 /* Save current window sizes. */ | |
7260 win_size_save(&winsizes); | |
7261 | |
7262 /* Don't execute autocommands while creating the window. */ | |
1410 | 7263 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7264 |
683 | 7265 /* don't use a new tab page */ |
7266 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
|
7267 cmdmod.noswapfile = 1; |
683 | 7268 |
7 | 7269 /* Create a window for the command-line buffer. */ |
7270 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7271 { | |
7272 beep_flush(); | |
1410 | 7273 unblock_autocmds(); |
7 | 7274 return K_IGNORE; |
7275 } | |
1831 | 7276 cmdwin_type = get_cmdline_type(); |
7 | 7277 |
7278 /* Create the command-line buffer empty. */ | |
1743 | 7279 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7280 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7281 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7282 curbuf->b_p_ma = TRUE; | |
1865 | 7283 #ifdef FEAT_FOLDING |
7284 curwin->w_p_fen = FALSE; | |
7285 #endif | |
7 | 7286 # ifdef FEAT_RIGHTLEFT |
510 | 7287 curwin->w_p_rl = cmdmsg_rl; |
7288 cmdmsg_rl = FALSE; | |
7 | 7289 # endif |
2583 | 7290 RESET_BINDING(curwin); |
7 | 7291 |
7292 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7293 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7294 /* 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
|
7295 ++curbuf_lock; |
7 | 7296 |
510 | 7297 /* Showing the prompt may have set need_wait_return, reset it. */ |
7298 need_wait_return = FALSE; | |
7299 | |
1831 | 7300 histtype = hist_char2type(cmdwin_type); |
7 | 7301 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7302 { | |
7303 if (p_wc == TAB) | |
7304 { | |
7305 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7306 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7307 } | |
7308 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7309 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7310 --curbuf_lock; |
7 | 7311 |
10 | 7312 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7313 * sets 'textwidth' to 78). */ | |
7314 curbuf->b_p_tw = 0; | |
7315 | |
7 | 7316 /* Fill the buffer with the history. */ |
7317 init_history(); | |
7318 if (hislen > 0) | |
7319 { | |
7320 i = hisidx[histtype]; | |
7321 if (i >= 0) | |
7322 { | |
7323 lnum = 0; | |
7324 do | |
7325 { | |
7326 if (++i == hislen) | |
7327 i = 0; | |
7328 if (history[histtype][i].hisstr != NULL) | |
7329 ml_append(lnum++, history[histtype][i].hisstr, | |
7330 (colnr_T)0, FALSE); | |
7331 } | |
7332 while (i != hisidx[histtype]); | |
7333 } | |
7334 } | |
7335 | |
7336 /* Replace the empty last line with the current command-line and put the | |
7337 * cursor there. */ | |
7338 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7339 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7340 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7341 changed_line_abv_curs(); |
7342 invalidate_botline(); | |
743 | 7343 redraw_later(SOME_VALID); |
7 | 7344 |
7345 /* 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
|
7346 save_cmdline(&save_ccline); |
7 | 7347 |
7348 /* No Ex mode here! */ | |
7349 exmode_active = 0; | |
7350 | |
7351 State = NORMAL; | |
7352 # ifdef FEAT_MOUSE | |
7353 setmouse(); | |
7354 # endif | |
7355 | |
7356 /* 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
|
7357 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7358 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7359 stuffcharReadbuff(K_NOP); | |
7 | 7360 |
7361 i = RedrawingDisabled; | |
7362 RedrawingDisabled = 0; | |
7363 | |
7364 /* | |
7365 * Call the main loop until <CR> or CTRL-C is typed. | |
7366 */ | |
7367 cmdwin_result = 0; | |
168 | 7368 main_loop(TRUE, FALSE); |
7 | 7369 |
7370 RedrawingDisabled = i; | |
7371 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7372 # ifdef FEAT_FOLDING |
6145 | 7373 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7374 # endif |
6145 | 7375 |
7 | 7376 /* 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
|
7377 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7378 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7379 # ifdef FEAT_FOLDING |
6145 | 7380 /* Restore KeyTyped in case it is modified by autocommands */ |
7381 KeyTyped = save_KeyTyped; | |
7 | 7382 # endif |
7383 | |
1214 | 7384 /* 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
|
7385 restore_cmdline(&save_ccline); |
7 | 7386 cmdwin_type = 0; |
7387 | |
7388 exmode_active = save_exmode; | |
7389 | |
1612 | 7390 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7391 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7392 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7393 { |
7394 cmdwin_result = Ctrl_C; | |
7395 EMSG(_("E199: Active window or buffer deleted")); | |
7396 } | |
7397 else | |
7398 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7399 # if defined(FEAT_EVAL) |
7 | 7400 /* autocmds may abort script processing */ |
7401 if (aborting() && cmdwin_result != K_IGNORE) | |
7402 cmdwin_result = Ctrl_C; | |
7403 # endif | |
7404 /* Set the new command line from the cmdline buffer. */ | |
7405 vim_free(ccline.cmdbuff); | |
510 | 7406 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7407 { |
510 | 7408 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7409 | |
7410 if (histtype == HIST_CMD) | |
7411 { | |
7412 /* Execute the command directly. */ | |
7413 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7414 cmdwin_result = CAR; | |
7415 } | |
7416 else | |
7417 { | |
7418 /* First need to cancel what we were doing. */ | |
7419 ccline.cmdbuff = NULL; | |
7420 stuffcharReadbuff(':'); | |
7421 stuffReadbuff((char_u *)p); | |
7422 stuffcharReadbuff(CAR); | |
7423 } | |
7 | 7424 } |
7425 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7426 { | |
7427 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7428 cmdwin_result = CAR; | |
7429 } | |
2839 | 7430 else if (cmdwin_result == Ctrl_C) |
7431 { | |
7432 /* :q or :close, don't execute any command | |
7433 * and don't modify the cmd window. */ | |
7434 ccline.cmdbuff = NULL; | |
7435 } | |
7 | 7436 else |
7437 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7438 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
|
7439 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7440 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
|
7441 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
|
7442 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
|
7443 ccline.cmdpos = 0; |
7 | 7444 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
|
7445 } |
7 | 7446 else |
7447 { | |
7448 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7449 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7450 ccline.cmdpos = curwin->w_cursor.col; | |
7451 if (ccline.cmdpos > ccline.cmdlen) | |
7452 ccline.cmdpos = ccline.cmdlen; | |
7453 if (cmdwin_result == K_IGNORE) | |
7454 { | |
7455 set_cmdspos_cursor(); | |
7456 redrawcmd(); | |
7457 } | |
7458 } | |
7459 | |
7460 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7461 block_autocmds(); |
6876 | 7462 # ifdef FEAT_CONCEAL |
7463 /* Avoid command-line window first character being concealed. */ | |
7464 curwin->w_p_cole = 0; | |
7465 # endif | |
7 | 7466 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7467 set_bufref(&bufref, curbuf); |
7 | 7468 win_goto(old_curwin); |
7469 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7470 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7471 /* 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
|
7472 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7473 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7474 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7475 |
7476 /* Restore window sizes. */ | |
7477 win_size_restore(&winsizes); | |
7478 | |
1410 | 7479 unblock_autocmds(); |
7 | 7480 } |
7481 | |
7482 ga_clear(&winsizes); | |
7483 restart_edit = save_restart_edit; | |
510 | 7484 # ifdef FEAT_RIGHTLEFT |
7485 cmdmsg_rl = save_cmdmsg_rl; | |
7486 # endif | |
7 | 7487 |
7488 State = save_State; | |
7489 # ifdef FEAT_MOUSE | |
7490 setmouse(); | |
7491 # endif | |
7492 | |
7493 return cmdwin_result; | |
7494 } | |
7495 #endif /* FEAT_CMDWIN */ | |
7496 | |
7497 /* | |
7498 * Used for commands that either take a simple command string argument, or: | |
7499 * cmd << endmarker | |
7500 * {script} | |
7501 * endmarker | |
7502 * Returns a pointer to allocated memory with {script} or NULL. | |
7503 */ | |
7504 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7505 script_get(exarg_T *eap, char_u *cmd) |
7 | 7506 { |
7507 char_u *theline; | |
7508 char *end_pattern = NULL; | |
7509 char dot[] = "."; | |
7510 garray_T ga; | |
7511 | |
7512 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7513 return NULL; | |
7514 | |
7515 ga_init2(&ga, 1, 0x400); | |
7516 | |
7517 if (cmd[2] != NUL) | |
7518 end_pattern = (char *)skipwhite(cmd + 2); | |
7519 else | |
7520 end_pattern = dot; | |
7521 | |
7522 for (;;) | |
7523 { | |
7524 theline = eap->getline( | |
7525 #ifdef FEAT_EVAL | |
75 | 7526 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7527 #endif |
7528 NUL, eap->cookie, 0); | |
7529 | |
7530 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7531 { |
7532 vim_free(theline); | |
7 | 7533 break; |
1694 | 7534 } |
7 | 7535 |
7536 ga_concat(&ga, theline); | |
7537 ga_append(&ga, '\n'); | |
7538 vim_free(theline); | |
7539 } | |
21 | 7540 ga_append(&ga, NUL); |
7 | 7541 |
7542 return (char_u *)ga.ga_data; | |
7543 } |