Mercurial > vim
annotate src/ex_getln.c @ 14548:806e1a2648c6 v8.1.0287
patch 8.1.0287: MAX is not defined everywhere
commit https://github.com/vim/vim/commit/37b15568c26e669c333903a70422eacc09488f79
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 14 22:08:25 2018 +0200
patch 8.1.0287: MAX is not defined everywhere
Problem: MAX is not defined everywhere.
Solution: Define MAX where needed.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 14 Aug 2018 22:15:05 +0200 |
parents | 35e7ead872db |
children | 2bee637a8edc |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
1718 | 47 /* The current cmdline_info. It is initialized in getcmdline() and after that |
48 * used by other functions. When invoking getcmdline() recursively it needs | |
49 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
50 * TODO: make it local to getcmdline() and pass it around. */ | |
51 static struct cmdline_info ccline; | |
7 | 52 |
53 static int cmd_showtail; /* Only show path tail in lists ? */ | |
54 | |
55 #ifdef FEAT_EVAL | |
56 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
57 #endif | |
58 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
60 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
62 |
7 | 63 #ifdef FEAT_CMDHIST |
64 typedef struct hist_entry | |
65 { | |
66 int hisnum; /* identifying number */ | |
4258 | 67 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 68 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
69 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 70 } histentry_T; |
71 | |
72 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
73 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
74 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
75 /* identifying (unique) number of newest history entry */ | |
76 static int hislen = 0; /* actual length of history tables */ | |
77 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
80 static int in_history(int, char_u *, int, int, int); |
7 | 81 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
82 static int calc_hist_idx(int histype, int num); |
7 | 83 # endif |
84 #endif | |
85 | |
86 #ifdef FEAT_RIGHTLEFT | |
87 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
88 #endif | |
89 | |
90 #ifdef FEAT_FKMAP | |
91 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
92 #endif | |
93 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
117 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
119 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
123 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
129 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
156 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
157 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
159 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
274 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
278 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 { |
14538
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
292 char_u *cmd; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
293 cmdmod_T save_cmdmod = cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
294 char_u *p; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
295 int delim; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
296 char_u *end; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
297 char_u *dummy; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
298 exarg_T ea; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
299 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
300 vim_memset(&ea, 0, sizeof(ea)); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
301 ea.line1 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
302 ea.line2 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
303 ea.cmd = ccline.cmdbuff; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
304 ea.addr_type = ADDR_LINES; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
305 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
306 parse_command_modifiers(&ea, &dummy, TRUE); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
307 cmdmod = save_cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
308 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
309 cmd = skip_range(ea.cmd, NULL); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
310 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
311 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 ; |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
315 if (*skipwhite(p) != NUL |
14522
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
316 && (STRNCMP(cmd, "substitute", p - cmd) == 0 |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
317 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
318 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
14522
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
319 || STRNCMP(cmd, "global", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
320 || STRNCMP(cmd, "vglobal", p - cmd) == 0)) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
321 { |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
322 if (*cmd == 's' && cmd[1] == 'm') |
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
323 p_magic = TRUE; |
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
324 else if (*cmd == 's' && cmd[1] == 'n') |
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
325 p_magic = FALSE; |
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
326 |
14534
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
327 // Check for "global!/". |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
328 if (*cmd == 'g' && *p == '!') |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
329 { |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
330 p++; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
331 if (*skipwhite(p) == NUL) |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
332 return FALSE; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
333 } |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
334 p = skipwhite(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
|
335 delim = *p++; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
336 end = skip_regexp(p, delim, p_magic, NULL); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
337 if (end > p || *end == delim) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
338 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
339 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
340 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
341 // found a non-empty pattern |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
342 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
343 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
344 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
345 // parse the address range |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
346 curwin->w_cursor = is_state->search_start; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
347 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
348 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
349 { |
14530
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
350 // Allow for reverse match. |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
351 if (ea.line2 < ea.line1) |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
352 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
353 search_first_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
354 search_last_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
355 } |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
356 else |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
357 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
358 search_first_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
359 search_last_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
360 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
361 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
362 else if (*cmd == 's') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
363 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
364 // :s defaults to the current line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
365 search_first_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
366 search_last_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
367 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
368 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
369 curwin->w_cursor = save_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
370 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
371 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
372 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
373 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
374 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
375 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
376 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
377 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
378 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
379 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
380 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
381 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
382 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
383 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
|
384 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
|
385 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
386 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
|
387 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
388 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
|
389 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
390 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
|
391 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
392 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
393 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
|
394 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
395 // 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
|
396 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
|
397 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
398 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
399 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
|
400 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
401 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
|
402 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
407 redraw_all_later(SOME_VALID); |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
408 p_magic = is_state->magic_save; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
409 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
410 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
411 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
412 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 * 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
|
414 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
416 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
|
417 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
418 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 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
|
420 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
421 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
|
422 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
423 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
|
424 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
|
425 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
427 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 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
|
430 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
431 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
|
432 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 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
|
434 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
436 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
437 // 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
|
438 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
439 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 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
|
441 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 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
|
444 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
445 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
|
446 // 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
|
447 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
|
448 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
449 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
450 // 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
|
451 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
|
452 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
|
453 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
456 // 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
|
457 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
|
458 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
|
459 && 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
|
460 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
461 // 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
|
462 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
|
463 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
464 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 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
|
466 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
|
467 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 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
|
471 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
472 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
|
473 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 ++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
|
475 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 // 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
|
477 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
|
478 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
492 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
|
493 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
494 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
495 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
|
496 || 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
|
497 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
498 // 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
|
499 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
500 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
|
501 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
502 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
503 // 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
|
504 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 (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
|
507 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
|
508 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
509 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 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
|
511 // 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
|
512 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
|
513 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 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
|
516 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 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
|
518 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 // 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
|
520 // 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
|
521 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
|
522 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
|
523 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 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
|
528 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 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
|
530 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
|
531 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 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
|
533 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
|
534 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
|
535 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 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
|
538 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 // Avoids a flash when typing "foo\|". |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
541 if (!use_last_pat) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
542 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
543 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
|
544 ccline.cmdbuff[skiplen + patlen] = NUL; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
545 if (empty_pattern(ccline.cmdbuff)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
546 set_no_hlsearch(TRUE); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
547 ccline.cmdbuff[skiplen + patlen] = next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
548 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 // 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
|
552 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
|
553 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
|
554 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 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
|
559 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 // 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
|
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 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
|
563 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 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
|
567 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 * 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
|
571 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 * 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
|
573 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 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
|
576 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
|
577 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 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
|
579 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
581 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
|
582 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
588 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
590 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
593 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
|
594 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
595 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
|
596 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
597 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
|
598 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 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
|
600 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
|
601 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 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
|
606 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 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
|
608 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
|
609 // 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
|
610 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 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
|
613 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 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
|
616 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 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
|
618 ++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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 --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
|
626 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
|
627 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 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
|
630 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
|
631 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
|
632 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
|
633 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 // 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
|
635 // 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
|
636 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
|
637 (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
|
638 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 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
|
640 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 // 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
|
642 // 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
|
643 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
|
644 (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
|
645 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 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
|
647 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 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
|
650 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 (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
|
652 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 (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
|
654 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
661 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 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
|
663 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
|
664 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 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
|
668 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
|
669 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 * 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
|
674 * 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
|
675 * 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
|
676 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 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
|
679 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
680 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
|
681 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
682 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
684 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 // 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
|
686 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
|
687 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 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
|
689 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
|
690 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
693 // 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
|
694 // 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
|
695 // 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
|
696 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
|
697 *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
|
698 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
699 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
700 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
|
701 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
|
702 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 // 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
|
704 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
705 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 } |
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 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
712 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
713 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
714 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
715 /* |
7 | 716 * getcmdline() - accept a command line starting with firstc. |
717 * | |
718 * firstc == ':' get ":" command line. | |
719 * firstc == '/' or '?' get search pattern | |
720 * firstc == '=' get expression | |
721 * firstc == '@' get text for input() function | |
722 * firstc == '>' get text for debug mode | |
723 * firstc == NUL get text for :insert command | |
724 * firstc == -1 like NUL, and break on CTRL-C | |
725 * | |
726 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
727 * command line. | |
728 * | |
729 * Careful: getcmdline() can be called recursively! | |
730 * | |
731 * Return pointer to allocated string if there is a commandline, NULL | |
732 * otherwise. | |
733 */ | |
734 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
735 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
736 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
737 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
|
738 int indent) /* indent for inside conditionals */ |
7 | 739 { |
740 int c; | |
741 int i; | |
742 int j; | |
743 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
744 int do_abbr; /* when TRUE check for abbr. */ | |
745 #ifdef FEAT_CMDHIST | |
746 char_u *lookfor = NULL; /* string to match */ | |
747 int hiscnt; /* current history line in use */ | |
748 int histype; /* history type to be used */ | |
749 #endif | |
750 #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
|
751 incsearch_state_T is_state; |
7 | 752 #endif |
753 int did_wild_list = FALSE; /* did wild_list() recently */ | |
754 int wim_index = 0; /* index in wim_flags[] */ | |
755 int res; | |
756 int save_msg_scroll = msg_scroll; | |
757 int save_State = State; /* remember State when called */ | |
758 int some_key_typed = FALSE; /* one of the keys was typed */ | |
759 #ifdef FEAT_MOUSE | |
760 /* mouse drag and release events are ignored, unless they are | |
761 * preceded with a mouse down event */ | |
762 int ignore_drag_release = TRUE; | |
763 #endif | |
764 #ifdef FEAT_EVAL | |
765 int break_ctrl_c = FALSE; | |
766 #endif | |
767 expand_T xpc; | |
768 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
|
769 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 770 /* Everything that may work recursively should save and restore the |
771 * current command line in save_ccline. That includes update_screen(), a | |
772 * custom status line may invoke ":normal". */ | |
773 struct cmdline_info save_ccline; | |
774 #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
|
775 int cmdline_type; |
7 | 776 |
777 #ifdef FEAT_EVAL | |
778 if (firstc == -1) | |
779 { | |
780 firstc = NUL; | |
781 break_ctrl_c = TRUE; | |
782 } | |
783 #endif | |
784 #ifdef FEAT_RIGHTLEFT | |
785 /* start without Hebrew mapping for a command line */ | |
786 if (firstc == ':' || firstc == '=' || firstc == '>') | |
787 cmd_hkmap = 0; | |
788 #endif | |
789 | |
790 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
|
791 |
7 | 792 #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
|
793 init_incsearch_state(&is_state); |
7 | 794 #endif |
795 | |
796 /* | |
797 * set some variables for redrawcmd() | |
798 */ | |
799 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 800 ccline.cmdindent = (firstc > 0 ? indent : 0); |
801 | |
802 /* alloc initial ccline.cmdbuff */ | |
803 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 804 if (ccline.cmdbuff == NULL) |
805 return NULL; /* out of memory */ | |
806 ccline.cmdlen = ccline.cmdpos = 0; | |
807 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
|
808 sb_text_start_cmdline(); |
7 | 809 |
164 | 810 /* autoindent for :insert and :append */ |
811 if (firstc <= 0) | |
812 { | |
6929 | 813 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 814 ccline.cmdbuff[indent] = NUL; |
815 ccline.cmdpos = indent; | |
816 ccline.cmdspos = indent; | |
817 ccline.cmdlen = indent; | |
818 } | |
819 | |
7 | 820 ExpandInit(&xpc); |
1718 | 821 ccline.xpc = &xpc; |
7 | 822 |
823 #ifdef FEAT_RIGHTLEFT | |
824 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
825 && (firstc == '/' || firstc == '?')) | |
826 cmdmsg_rl = TRUE; | |
827 else | |
828 cmdmsg_rl = FALSE; | |
829 #endif | |
830 | |
831 redir_off = TRUE; /* don't redirect the typed command */ | |
832 if (!cmd_silent) | |
833 { | |
834 i = msg_scrolled; | |
835 msg_scrolled = 0; /* avoid wait_return message */ | |
836 gotocmdline(TRUE); | |
837 msg_scrolled += i; | |
838 redrawcmdprompt(); /* draw prompt or indent */ | |
839 set_cmdspos(); | |
840 } | |
841 xpc.xp_context = EXPAND_NOTHING; | |
842 xpc.xp_backslash = XP_BS_NONE; | |
632 | 843 #ifndef BACKSLASH_IN_FILENAME |
844 xpc.xp_shell = FALSE; | |
845 #endif | |
7 | 846 |
531 | 847 #if defined(FEAT_EVAL) |
848 if (ccline.input_fn) | |
849 { | |
850 xpc.xp_context = ccline.xp_context; | |
851 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 852 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 853 xpc.xp_arg = ccline.xp_arg; |
1322 | 854 # endif |
531 | 855 } |
856 #endif | |
857 | |
7 | 858 /* |
859 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
860 * doing ":@0" when register 0 doesn't contain a CR. | |
861 */ | |
862 msg_scroll = FALSE; | |
863 | |
864 State = CMDLINE; | |
865 | |
866 if (firstc == '/' || firstc == '?' || firstc == '@') | |
867 { | |
868 /* Use ":lmap" mappings for search pattern and input(). */ | |
869 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
870 b_im_ptr = &curbuf->b_p_iminsert; | |
871 else | |
872 b_im_ptr = &curbuf->b_p_imsearch; | |
873 if (*b_im_ptr == B_IMODE_LMAP) | |
874 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
875 #ifdef HAVE_INPUT_METHOD |
7 | 876 im_set_active(*b_im_ptr == B_IMODE_IM); |
877 #endif | |
878 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
879 #ifdef HAVE_INPUT_METHOD |
7 | 880 else if (p_imcmdline) |
881 im_set_active(TRUE); | |
882 #endif | |
883 | |
884 #ifdef FEAT_MOUSE | |
885 setmouse(); | |
886 #endif | |
887 #ifdef CURSOR_SHAPE | |
888 ui_cursor_shape(); /* may show different cursor shape */ | |
889 #endif | |
890 | |
571 | 891 /* When inside an autocommand for writing "exiting" may be set and |
892 * terminal mode set to cooked. Need to set raw mode here then. */ | |
893 settmode(TMODE_RAW); | |
894 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
895 /* 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
|
896 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
|
897 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
|
898 |
7 | 899 #ifdef FEAT_CMDHIST |
900 init_history(); | |
901 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
902 histype = hist_char2type(firstc); | |
903 #endif | |
904 | |
905 #ifdef FEAT_DIGRAPHS | |
1868 | 906 do_digraph(-1); /* init digraph typeahead */ |
7 | 907 #endif |
908 | |
5993 | 909 /* If something above caused an error, reset the flags, we do want to type |
910 * and execute commands. Display may be messed up a bit. */ | |
911 if (did_emsg) | |
912 redrawcmd(); | |
913 did_emsg = FALSE; | |
914 got_int = FALSE; | |
915 | |
7 | 916 /* |
917 * Collect the command string, handling editing keys. | |
918 */ | |
919 for (;;) | |
920 { | |
972 | 921 redir_off = TRUE; /* Don't redirect the typed command. |
922 Repeated, because a ":redir" inside | |
923 completion may switch it on. */ | |
7 | 924 #ifdef USE_ON_FLY_SCROLL |
925 dont_scroll = FALSE; /* allow scrolling here */ | |
926 #endif | |
927 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
928 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 |
7 | 933 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 934 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
935 /* 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
|
936 * anything, such as stop completion. */ |
1472 | 937 do |
938 { | |
939 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
|
940 } while (c == K_IGNORE || c == K_NOP); |
1472 | 941 |
7 | 942 if (KeyTyped) |
943 { | |
944 some_key_typed = TRUE; | |
945 #ifdef FEAT_RIGHTLEFT | |
946 if (cmd_hkmap) | |
947 c = hkmap(c); | |
948 # ifdef FEAT_FKMAP | |
949 if (cmd_fkmap) | |
950 c = cmdl_fkmap(c); | |
951 # endif | |
952 if (cmdmsg_rl && !KeyStuffed) | |
953 { | |
954 /* Invert horizontal movements and operations. Only when | |
955 * typed by the user directly, not when the result of a | |
956 * mapping. */ | |
957 switch (c) | |
958 { | |
959 case K_RIGHT: c = K_LEFT; break; | |
960 case K_S_RIGHT: c = K_S_LEFT; break; | |
961 case K_C_RIGHT: c = K_C_LEFT; break; | |
962 case K_LEFT: c = K_RIGHT; break; | |
963 case K_S_LEFT: c = K_S_RIGHT; break; | |
964 case K_C_LEFT: c = K_C_RIGHT; break; | |
965 } | |
966 } | |
967 #endif | |
968 } | |
969 | |
970 /* | |
971 * Ignore got_int when CTRL-C was typed here. | |
972 * Don't ignore it in :global, we really need to break then, e.g., for | |
973 * ":g/pat/normal /pat" (without the <CR>). | |
974 * Don't ignore it for the input() function. | |
975 */ | |
976 if ((c == Ctrl_C | |
977 #ifdef UNIX | |
978 || c == intr_char | |
979 #endif | |
980 ) | |
981 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
982 && firstc != '@' | |
983 #endif | |
984 #ifdef FEAT_EVAL | |
985 && !break_ctrl_c | |
986 #endif | |
987 && !global_busy) | |
988 got_int = FALSE; | |
989 | |
990 #ifdef FEAT_CMDHIST | |
991 /* free old command line when finished moving around in the history | |
992 * list */ | |
993 if (lookfor != NULL | |
180 | 994 && c != K_S_DOWN && c != K_S_UP |
230 | 995 && c != K_DOWN && c != K_UP |
7 | 996 && c != K_PAGEDOWN && c != K_PAGEUP |
997 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 998 && c != K_LEFT && c != K_RIGHT |
7 | 999 && (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
|
1000 VIM_CLEAR(lookfor); |
7 | 1001 #endif |
1002 | |
1003 /* | |
1718 | 1004 * When there are matching completions to select <S-Tab> works like |
1005 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1006 */ |
1718 | 1007 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1008 c = Ctrl_P; |
1009 | |
1010 #ifdef FEAT_WILDMENU | |
1011 /* Special translations for 'wildmenu' */ | |
1012 if (did_wild_list && p_wmnu) | |
1013 { | |
230 | 1014 if (c == K_LEFT) |
7 | 1015 c = Ctrl_P; |
230 | 1016 else if (c == K_RIGHT) |
7 | 1017 c = Ctrl_N; |
1018 } | |
1019 /* Hitting CR after "emenu Name.": complete submenu */ | |
1020 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1021 && ccline.cmdpos > 1 | |
1022 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1023 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1024 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1025 c = K_DOWN; | |
1026 #endif | |
1027 | |
1028 /* free expanded names when finished walking through matches */ | |
1029 if (xpc.xp_numfiles != -1 | |
1030 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1031 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1032 && c != Ctrl_L) | |
1033 { | |
1034 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1035 did_wild_list = FALSE; | |
1036 #ifdef FEAT_WILDMENU | |
230 | 1037 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1038 #endif |
1039 xpc.xp_context = EXPAND_NOTHING; | |
1040 wim_index = 0; | |
1041 #ifdef FEAT_WILDMENU | |
1042 if (p_wmnu && wild_menu_showing != 0) | |
1043 { | |
1044 int skt = KeyTyped; | |
532 | 1045 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1046 |
1047 if (ccline.input_fn) | |
1048 RedrawingDisabled = 0; | |
7 | 1049 |
1050 if (wild_menu_showing == WM_SCROLLED) | |
1051 { | |
1052 /* Entered command line, move it up */ | |
1053 cmdline_row--; | |
1054 redrawcmd(); | |
1055 } | |
1056 else if (save_p_ls != -1) | |
1057 { | |
1058 /* restore 'laststatus' and 'winminheight' */ | |
1059 p_ls = save_p_ls; | |
1060 p_wmh = save_p_wmh; | |
1061 last_status(FALSE); | |
195 | 1062 save_cmdline(&save_ccline); |
7 | 1063 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1064 restore_cmdline(&save_ccline); |
7 | 1065 redrawcmd(); |
1066 save_p_ls = -1; | |
1067 } | |
1068 else | |
1069 { | |
1070 win_redraw_last_status(topframe); | |
1071 redraw_statuslines(); | |
1072 } | |
532 | 1073 KeyTyped = skt; |
1074 wild_menu_showing = 0; | |
531 | 1075 if (ccline.input_fn) |
1076 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1077 } |
1078 #endif | |
1079 } | |
1080 | |
1081 #ifdef FEAT_WILDMENU | |
1082 /* Special translations for 'wildmenu' */ | |
1083 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1084 { | |
1085 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1086 if (c == K_DOWN && ccline.cmdpos > 0 |
1087 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1088 c = p_wc; |
230 | 1089 else if (c == K_UP) |
7 | 1090 { |
1091 /* Hitting <Up>: Remove one submenu name in front of the | |
1092 * cursor */ | |
1093 int found = FALSE; | |
1094 | |
1095 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1096 i = 0; | |
1097 while (--j > 0) | |
1098 { | |
1099 /* check for start of menu name */ | |
1100 if (ccline.cmdbuff[j] == ' ' | |
1101 && ccline.cmdbuff[j - 1] != '\\') | |
1102 { | |
1103 i = j + 1; | |
1104 break; | |
1105 } | |
1106 /* check for start of submenu name */ | |
1107 if (ccline.cmdbuff[j] == '.' | |
1108 && ccline.cmdbuff[j - 1] != '\\') | |
1109 { | |
1110 if (found) | |
1111 { | |
1112 i = j + 1; | |
1113 break; | |
1114 } | |
1115 else | |
1116 found = TRUE; | |
1117 } | |
1118 } | |
1119 if (i > 0) | |
1120 cmdline_del(i); | |
1121 c = p_wc; | |
1122 xpc.xp_context = EXPAND_NOTHING; | |
1123 } | |
1124 } | |
714 | 1125 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1126 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1127 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1128 { |
1129 char_u upseg[5]; | |
1130 | |
1131 upseg[0] = PATHSEP; | |
1132 upseg[1] = '.'; | |
1133 upseg[2] = '.'; | |
1134 upseg[3] = PATHSEP; | |
1135 upseg[4] = NUL; | |
1136 | |
1318 | 1137 if (c == K_DOWN |
1138 && ccline.cmdpos > 0 | |
1139 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1140 && (ccline.cmdpos < 3 | |
1141 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1142 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1143 { | |
1144 /* go down a directory */ | |
1145 c = p_wc; | |
1146 } | |
230 | 1147 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1148 { |
1149 /* If in a direct ancestor, strip off one ../ to go down */ | |
1150 int found = FALSE; | |
1151 | |
1152 j = ccline.cmdpos; | |
1153 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1154 while (--j > i) | |
1155 { | |
39 | 1156 #ifdef FEAT_MBYTE |
1157 if (has_mbyte) | |
1158 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1159 #endif | |
7 | 1160 if (vim_ispathsep(ccline.cmdbuff[j])) |
1161 { | |
1162 found = TRUE; | |
1163 break; | |
1164 } | |
1165 } | |
1166 if (found | |
1167 && ccline.cmdbuff[j - 1] == '.' | |
1168 && ccline.cmdbuff[j - 2] == '.' | |
1169 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1170 { | |
1171 cmdline_del(j - 2); | |
1172 c = p_wc; | |
1173 } | |
1174 } | |
230 | 1175 else if (c == K_UP) |
7 | 1176 { |
1177 /* go up a directory */ | |
1178 int found = FALSE; | |
1179 | |
1180 j = ccline.cmdpos - 1; | |
1181 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1182 while (--j > i) | |
1183 { | |
1184 #ifdef FEAT_MBYTE | |
1185 if (has_mbyte) | |
1186 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1187 #endif | |
1188 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1189 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1190 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1191 ccline.cmdbuff[j + 1]) == NULL |
7 | 1192 #endif |
1193 ) | |
1194 { | |
1195 if (found) | |
1196 { | |
1197 i = j + 1; | |
1198 break; | |
1199 } | |
1200 else | |
1201 found = TRUE; | |
1202 } | |
1203 } | |
1204 | |
1205 if (!found) | |
1206 j = i; | |
1207 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1208 j += 4; | |
1209 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1210 && j == i) | |
1211 j += 3; | |
1212 else | |
1213 j = 0; | |
1214 if (j > 0) | |
1215 { | |
1216 /* TODO this is only for DOS/UNIX systems - need to put in | |
1217 * machine-specific stuff here and in upseg init */ | |
1218 cmdline_del(j); | |
1219 put_on_cmdline(upseg + 1, 3, FALSE); | |
1220 } | |
1221 else if (ccline.cmdpos > i) | |
1222 cmdline_del(i); | |
3204 | 1223 |
1224 /* Now complete in the new directory. Set KeyTyped in case the | |
1225 * Up key came from a mapping. */ | |
7 | 1226 c = p_wc; |
3204 | 1227 KeyTyped = TRUE; |
7 | 1228 } |
1229 } | |
1230 | |
1231 #endif /* FEAT_WILDMENU */ | |
1232 | |
1233 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1234 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1235 if (c == Ctrl_BSL) | |
1236 { | |
1237 ++no_mapping; | |
1238 ++allow_keys; | |
1389 | 1239 c = plain_vgetc(); |
7 | 1240 --no_mapping; |
1241 --allow_keys; | |
3859 | 1242 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1243 * is in a mapping. */ | |
1244 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1245 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1246 { |
1247 vungetc(c); | |
1248 c = Ctrl_BSL; | |
1249 } | |
1250 #ifdef FEAT_EVAL | |
1251 else if (c == 'e') | |
1252 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1253 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1254 int len; |
7 | 1255 |
1256 /* | |
1257 * Replace the command line with the result of an expression. | |
625 | 1258 * Need to save and restore the current command line, to be |
1259 * able to enter a new one... | |
7 | 1260 */ |
1261 if (ccline.cmdpos == ccline.cmdlen) | |
1262 new_cmdpos = 99999; /* keep it at the end */ | |
1263 else | |
1264 new_cmdpos = ccline.cmdpos; | |
95 | 1265 |
1266 save_cmdline(&save_ccline); | |
7 | 1267 c = get_expr_register(); |
95 | 1268 restore_cmdline(&save_ccline); |
7 | 1269 if (c == '=') |
1270 { | |
634 | 1271 /* Need to save and restore ccline. And set "textlock" |
632 | 1272 * to avoid nasty things like going to another buffer when |
1273 * evaluating an expression. */ | |
95 | 1274 save_cmdline(&save_ccline); |
634 | 1275 ++textlock; |
7 | 1276 p = get_expr_line(); |
634 | 1277 --textlock; |
95 | 1278 restore_cmdline(&save_ccline); |
2617 | 1279 |
1280 if (p != NULL) | |
7 | 1281 { |
2617 | 1282 len = (int)STRLEN(p); |
1283 if (realloc_cmdbuff(len + 1) == OK) | |
1284 { | |
1285 ccline.cmdlen = len; | |
1286 STRCPY(ccline.cmdbuff, p); | |
1287 vim_free(p); | |
1288 | |
1289 /* Restore the cursor or use the position set with | |
1290 * set_cmdline_pos(). */ | |
1291 if (new_cmdpos > ccline.cmdlen) | |
1292 ccline.cmdpos = ccline.cmdlen; | |
1293 else | |
1294 ccline.cmdpos = new_cmdpos; | |
1295 | |
1296 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1297 redrawcmd(); | |
1298 goto cmdline_changed; | |
1299 } | |
7 | 1300 } |
1301 } | |
1302 beep_flush(); | |
2636 | 1303 got_int = FALSE; /* don't abandon the command line */ |
1304 did_emsg = FALSE; | |
1305 emsg_on_display = FALSE; | |
1306 redrawcmd(); | |
1307 goto cmdline_not_changed; | |
7 | 1308 } |
1309 #endif | |
1310 else | |
1311 { | |
1312 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1313 restart_edit = 'a'; | |
1314 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1315 in history */ | |
1316 goto returncmd; /* back to Normal mode */ | |
1317 } | |
1318 } | |
1319 | |
1320 #ifdef FEAT_CMDWIN | |
1321 if (c == cedit_key || c == K_CMDWIN) | |
1322 { | |
6211 | 1323 if (ex_normal_busy == 0 && got_int == FALSE) |
1324 { | |
1325 /* | |
1326 * Open a window to edit the command line (and history). | |
1327 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1328 c = open_cmdwin(); |
6211 | 1329 some_key_typed = TRUE; |
1330 } | |
7 | 1331 } |
1332 # ifdef FEAT_DIGRAPHS | |
1333 else | |
1334 # endif | |
1335 #endif | |
1336 #ifdef FEAT_DIGRAPHS | |
1337 c = do_digraph(c); | |
1338 #endif | |
1339 | |
1340 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1341 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1342 { | |
168 | 1343 /* In Ex mode a backslash escapes a newline. */ |
1344 if (exmode_active | |
1345 && c != ESC | |
1318 | 1346 && ccline.cmdpos == ccline.cmdlen |
168 | 1347 && ccline.cmdpos > 0 |
1348 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1349 { | |
1350 if (c == K_KENTER) | |
1351 c = '\n'; | |
1352 } | |
1353 else | |
7 | 1354 { |
168 | 1355 gotesc = FALSE; /* Might have typed ESC previously, don't |
1356 truncate the cmdline now. */ | |
1357 if (ccheck_abbr(c + ABBR_OFF)) | |
1358 goto cmdline_changed; | |
1359 if (!cmd_silent) | |
1360 { | |
1361 windgoto(msg_row, 0); | |
1362 out_flush(); | |
1363 } | |
1364 break; | |
7 | 1365 } |
1366 } | |
1367 | |
1368 /* | |
1369 * Completion for 'wildchar' or 'wildcharm' key. | |
1370 * - hitting <ESC> twice means: abandon command line. | |
1371 * - wildcard expansion is only done when the 'wildchar' key is really | |
1372 * typed, not when it comes from a macro | |
1373 */ | |
1374 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1375 { | |
1376 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1377 { | |
1378 /* if 'wildmode' contains "list" may still need to list */ | |
1379 if (xpc.xp_numfiles > 1 | |
1380 && !did_wild_list | |
1381 && (wim_flags[wim_index] & WIM_LIST)) | |
1382 { | |
1383 (void)showmatches(&xpc, FALSE); | |
1384 redrawcmd(); | |
1385 did_wild_list = TRUE; | |
1386 } | |
1387 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1388 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1389 firstc != '@'); | |
7 | 1390 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1391 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1392 firstc != '@'); | |
7 | 1393 else |
1394 res = OK; /* don't insert 'wildchar' now */ | |
1395 } | |
1396 else /* typed p_wc first time */ | |
1397 { | |
1398 wim_index = 0; | |
1399 j = ccline.cmdpos; | |
1400 /* if 'wildmode' first contains "longest", get longest | |
1401 * common part */ | |
1402 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1403 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1404 firstc != '@'); | |
7 | 1405 else |
3961 | 1406 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1407 firstc != '@'); | |
7 | 1408 |
1409 /* if interrupted while completing, behave like it failed */ | |
1410 if (got_int) | |
1411 { | |
1412 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1413 got_int = FALSE; /* don't abandon the command line */ | |
1414 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1415 #ifdef FEAT_WILDMENU | |
1416 xpc.xp_context = EXPAND_NOTHING; | |
1417 #endif | |
1418 goto cmdline_changed; | |
1419 } | |
1420 | |
1421 /* when more than one match, and 'wildmode' first contains | |
1422 * "list", or no change and 'wildmode' contains "longest,list", | |
1423 * list all matches */ | |
1424 if (res == OK && xpc.xp_numfiles > 1) | |
1425 { | |
1426 /* a "longest" that didn't do anything is skipped (but not | |
1427 * "list:longest") */ | |
1428 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1429 wim_index = 1; | |
1430 if ((wim_flags[wim_index] & WIM_LIST) | |
1431 #ifdef FEAT_WILDMENU | |
1432 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1433 #endif | |
1434 ) | |
1435 { | |
1436 if (!(wim_flags[0] & WIM_LONGEST)) | |
1437 { | |
1438 #ifdef FEAT_WILDMENU | |
1439 int p_wmnu_save = p_wmnu; | |
1440 p_wmnu = 0; | |
1441 #endif | |
3961 | 1442 /* remove match */ |
1443 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1444 #ifdef FEAT_WILDMENU |
1445 p_wmnu = p_wmnu_save; | |
1446 #endif | |
1447 } | |
1448 #ifdef FEAT_WILDMENU | |
1449 (void)showmatches(&xpc, p_wmnu | |
1450 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1451 #else | |
1452 (void)showmatches(&xpc, FALSE); | |
1453 #endif | |
1454 redrawcmd(); | |
1455 did_wild_list = TRUE; | |
1456 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1457 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1458 firstc != '@'); | |
7 | 1459 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1460 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1461 firstc != '@'); | |
7 | 1462 } |
1463 else | |
6949 | 1464 vim_beep(BO_WILD); |
7 | 1465 } |
1466 #ifdef FEAT_WILDMENU | |
1467 else if (xpc.xp_numfiles == -1) | |
1468 xpc.xp_context = EXPAND_NOTHING; | |
1469 #endif | |
1470 } | |
1471 if (wim_index < 3) | |
1472 ++wim_index; | |
1473 if (c == ESC) | |
1474 gotesc = TRUE; | |
1475 if (res == OK) | |
1476 goto cmdline_changed; | |
1477 } | |
1478 | |
1479 gotesc = FALSE; | |
1480 | |
1481 /* <S-Tab> goes to last match, in a clumsy way */ | |
1482 if (c == K_S_TAB && KeyTyped) | |
1483 { | |
3961 | 1484 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1485 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1486 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1487 goto cmdline_changed; |
1488 } | |
1489 | |
1490 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1491 c = NL; | |
1492 | |
1493 do_abbr = TRUE; /* default: check for abbreviation */ | |
1494 | |
1495 /* | |
1496 * Big switch for a typed command line character. | |
1497 */ | |
1498 switch (c) | |
1499 { | |
1500 case K_BS: | |
1501 case Ctrl_H: | |
1502 case K_DEL: | |
1503 case K_KDEL: | |
1504 case Ctrl_W: | |
1505 #ifdef FEAT_FKMAP | |
1506 if (cmd_fkmap && c == K_BS) | |
1507 c = K_DEL; | |
1508 #endif | |
1509 if (c == K_KDEL) | |
1510 c = K_DEL; | |
1511 | |
1512 /* | |
1513 * delete current character is the same as backspace on next | |
1514 * character, except at end of line | |
1515 */ | |
1516 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1517 ++ccline.cmdpos; | |
1518 #ifdef FEAT_MBYTE | |
1519 if (has_mbyte && c == K_DEL) | |
1520 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1521 ccline.cmdbuff + ccline.cmdpos); | |
1522 #endif | |
1523 if (ccline.cmdpos > 0) | |
1524 { | |
1525 char_u *p; | |
1526 | |
1527 j = ccline.cmdpos; | |
1528 p = ccline.cmdbuff + j; | |
1529 #ifdef FEAT_MBYTE | |
1530 if (has_mbyte) | |
1531 { | |
1532 p = mb_prevptr(ccline.cmdbuff, p); | |
1533 if (c == Ctrl_W) | |
1534 { | |
1535 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1536 p = mb_prevptr(ccline.cmdbuff, p); | |
1537 i = mb_get_class(p); | |
1538 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1539 p = mb_prevptr(ccline.cmdbuff, p); | |
1540 if (mb_get_class(p) != i) | |
474 | 1541 p += (*mb_ptr2len)(p); |
7 | 1542 } |
1543 } | |
1544 else | |
1545 #endif | |
1546 if (c == Ctrl_W) | |
1547 { | |
1548 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1549 --p; | |
1550 i = vim_iswordc(p[-1]); | |
1551 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1552 && vim_iswordc(p[-1]) == i) | |
1553 --p; | |
1554 } | |
1555 else | |
1556 --p; | |
1557 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1558 ccline.cmdlen -= j - ccline.cmdpos; | |
1559 i = ccline.cmdpos; | |
1560 while (i < ccline.cmdlen) | |
1561 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1562 | |
1563 /* Truncate at the end, required for multi-byte chars. */ | |
1564 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1565 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1566 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1567 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1568 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
|
1569 /* 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
|
1570 * 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
|
1571 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
|
1572 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1573 #endif |
7 | 1574 redrawcmd(); |
1575 } | |
1576 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1577 && ccline.cmdprompt == NULL && indent == 0) | |
1578 { | |
1579 /* In ex and debug mode it doesn't make sense to return. */ | |
1580 if (exmode_active | |
1581 #ifdef FEAT_EVAL | |
1582 || ccline.cmdfirstc == '>' | |
1583 #endif | |
1584 ) | |
1585 goto cmdline_not_changed; | |
1586 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1587 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1588 if (!cmd_silent) |
1589 { | |
1590 #ifdef FEAT_RIGHTLEFT | |
1591 if (cmdmsg_rl) | |
1592 msg_col = Columns; | |
1593 else | |
1594 #endif | |
1595 msg_col = 0; | |
1596 msg_putchar(' '); /* delete ':' */ | |
1597 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1598 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1599 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
|
1600 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
|
1601 #endif |
7 | 1602 redraw_cmdline = TRUE; |
1603 goto returncmd; /* back to cmd mode */ | |
1604 } | |
1605 goto cmdline_changed; | |
1606 | |
1607 case K_INS: | |
1608 case K_KINS: | |
1609 #ifdef FEAT_FKMAP | |
1610 /* if Farsi mode set, we are in reverse insert mode - | |
1611 Do not change the mode */ | |
1612 if (cmd_fkmap) | |
1613 beep_flush(); | |
1614 else | |
1615 #endif | |
1616 ccline.overstrike = !ccline.overstrike; | |
1617 #ifdef CURSOR_SHAPE | |
1618 ui_cursor_shape(); /* may show different cursor shape */ | |
1619 #endif | |
1620 goto cmdline_not_changed; | |
1621 | |
1622 case Ctrl_HAT: | |
782 | 1623 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1624 { |
1625 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1626 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1627 #ifdef HAVE_INPUT_METHOD |
7 | 1628 im_set_active(FALSE); /* Disable input method */ |
1629 #endif | |
1630 if (b_im_ptr != NULL) | |
1631 { | |
1632 if (State & LANGMAP) | |
1633 *b_im_ptr = B_IMODE_LMAP; | |
1634 else | |
1635 *b_im_ptr = B_IMODE_NONE; | |
1636 } | |
1637 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1638 #ifdef HAVE_INPUT_METHOD |
7 | 1639 else |
1640 { | |
1641 /* There are no ":lmap" mappings, toggle IM. When | |
1642 * 'imdisable' is set don't try getting the status, it's | |
1643 * always off. */ | |
1644 if ((p_imdisable && b_im_ptr != NULL) | |
1645 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1646 { | |
1647 im_set_active(FALSE); /* Disable input method */ | |
1648 if (b_im_ptr != NULL) | |
1649 *b_im_ptr = B_IMODE_NONE; | |
1650 } | |
1651 else | |
1652 { | |
1653 im_set_active(TRUE); /* Enable input method */ | |
1654 if (b_im_ptr != NULL) | |
1655 *b_im_ptr = B_IMODE_IM; | |
1656 } | |
1657 } | |
1658 #endif | |
1659 if (b_im_ptr != NULL) | |
1660 { | |
1661 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1662 set_iminsert_global(); | |
1663 else | |
1664 set_imsearch_global(); | |
1665 } | |
1666 #ifdef CURSOR_SHAPE | |
1667 ui_cursor_shape(); /* may show different cursor shape */ | |
1668 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1669 #if defined(FEAT_KEYMAP) |
7 | 1670 /* Show/unshow value of 'keymap' in status lines later. */ |
1671 status_redraw_curbuf(); | |
1672 #endif | |
1673 goto cmdline_not_changed; | |
1674 | |
1675 /* case '@': only in very old vi */ | |
1676 case Ctrl_U: | |
1677 /* delete all characters left of the cursor */ | |
1678 j = ccline.cmdpos; | |
1679 ccline.cmdlen -= j; | |
1680 i = ccline.cmdpos = 0; | |
1681 while (i < ccline.cmdlen) | |
1682 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1683 /* Truncate at the end, required for multi-byte chars. */ | |
1684 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1685 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1686 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
|
1687 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
|
1688 #endif |
7 | 1689 redrawcmd(); |
1690 goto cmdline_changed; | |
1691 | |
1692 #ifdef FEAT_CLIPBOARD | |
1693 case Ctrl_Y: | |
1694 /* Copy the modeless selection, if there is one. */ | |
1695 if (clip_star.state != SELECT_CLEARED) | |
1696 { | |
1697 if (clip_star.state == SELECT_DONE) | |
1698 clip_copy_modeless_selection(TRUE); | |
1699 goto cmdline_not_changed; | |
1700 } | |
1701 break; | |
1702 #endif | |
1703 | |
1704 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1705 case Ctrl_C: | |
571 | 1706 /* In exmode it doesn't make sense to return. Except when |
161 | 1707 * ":normal" runs out of characters. */ |
1708 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1709 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1710 goto cmdline_not_changed; |
1711 | |
1712 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1713 putting it in history */ | |
1714 goto returncmd; /* back to cmd mode */ | |
1715 | |
1716 case Ctrl_R: /* insert register */ | |
1717 #ifdef USE_ON_FLY_SCROLL | |
1718 dont_scroll = TRUE; /* disallow scrolling here */ | |
1719 #endif | |
1720 putcmdline('"', TRUE); | |
1721 ++no_mapping; | |
1389 | 1722 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1723 if (i == Ctrl_O) |
1724 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1725 if (i == Ctrl_R) | |
1389 | 1726 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
|
1727 extra_char = NUL; |
7 | 1728 --no_mapping; |
1729 #ifdef FEAT_EVAL | |
1730 /* | |
1731 * Insert the result of an expression. | |
1732 * Need to save the current command line, to be able to enter | |
1733 * a new one... | |
1734 */ | |
1735 new_cmdpos = -1; | |
1736 if (c == '=') | |
1737 { | |
1738 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1739 { | |
1740 beep_flush(); | |
1741 c = ESC; | |
1742 } | |
1743 else | |
1744 { | |
95 | 1745 save_cmdline(&save_ccline); |
7 | 1746 c = get_expr_register(); |
95 | 1747 restore_cmdline(&save_ccline); |
7 | 1748 } |
1749 } | |
1750 #endif | |
1751 if (c != ESC) /* use ESC to cancel inserting register */ | |
1752 { | |
1015 | 1753 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1754 |
613 | 1755 #ifdef FEAT_EVAL |
606 | 1756 /* When there was a serious error abort getting the |
1757 * command line. */ | |
1758 if (aborting()) | |
1759 { | |
1760 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1761 putting it in history */ | |
1762 goto returncmd; /* back to cmd mode */ | |
1763 } | |
613 | 1764 #endif |
7 | 1765 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1766 #ifdef FEAT_EVAL | |
1767 if (new_cmdpos >= 0) | |
1768 { | |
1769 /* set_cmdline_pos() was used */ | |
1770 if (new_cmdpos > ccline.cmdlen) | |
1771 ccline.cmdpos = ccline.cmdlen; | |
1772 else | |
1773 ccline.cmdpos = new_cmdpos; | |
1774 } | |
1775 #endif | |
1776 } | |
1777 redrawcmd(); | |
1778 goto cmdline_changed; | |
1779 | |
1780 case Ctrl_D: | |
1781 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1782 break; /* Use ^D as normal char instead */ | |
1783 | |
1784 redrawcmd(); | |
1785 continue; /* don't do incremental search now */ | |
1786 | |
1787 case K_RIGHT: | |
1788 case K_S_RIGHT: | |
1789 case K_C_RIGHT: | |
1790 do | |
1791 { | |
1792 if (ccline.cmdpos >= ccline.cmdlen) | |
1793 break; | |
1794 i = cmdline_charsize(ccline.cmdpos); | |
1795 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1796 break; | |
1797 ccline.cmdspos += i; | |
1798 #ifdef FEAT_MBYTE | |
1799 if (has_mbyte) | |
474 | 1800 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1801 + ccline.cmdpos); |
1802 else | |
1803 #endif | |
1804 ++ccline.cmdpos; | |
1805 } | |
180 | 1806 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1807 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1808 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1809 #ifdef FEAT_MBYTE | |
1810 if (has_mbyte) | |
1811 set_cmdspos_cursor(); | |
1812 #endif | |
1813 goto cmdline_not_changed; | |
1814 | |
1815 case K_LEFT: | |
1816 case K_S_LEFT: | |
1817 case K_C_LEFT: | |
1456 | 1818 if (ccline.cmdpos == 0) |
1819 goto cmdline_not_changed; | |
7 | 1820 do |
1821 { | |
1822 --ccline.cmdpos; | |
1823 #ifdef FEAT_MBYTE | |
1824 if (has_mbyte) /* move to first byte of char */ | |
1825 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1826 ccline.cmdbuff + ccline.cmdpos); | |
1827 #endif | |
1828 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1829 } | |
1456 | 1830 while (ccline.cmdpos > 0 |
1831 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1832 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1833 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1834 #ifdef FEAT_MBYTE | |
1835 if (has_mbyte) | |
1836 set_cmdspos_cursor(); | |
1837 #endif | |
1838 goto cmdline_not_changed; | |
1839 | |
1840 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
|
1841 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1842 goto cmdline_not_changed; |
7 | 1843 |
625 | 1844 #ifdef FEAT_GUI_W32 |
1845 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1846 * cancelled. */ | |
1847 case K_F4: | |
1848 if (mod_mask == MOD_MASK_ALT) | |
1849 { | |
1850 redrawcmd(); /* somehow the cmdline is cleared */ | |
1851 goto cmdline_not_changed; | |
1852 } | |
1853 break; | |
1854 #endif | |
1855 | |
7 | 1856 #ifdef FEAT_MOUSE |
1857 case K_MIDDLEDRAG: | |
1858 case K_MIDDLERELEASE: | |
1859 goto cmdline_not_changed; /* Ignore mouse */ | |
1860 | |
1861 case K_MIDDLEMOUSE: | |
1862 # ifdef FEAT_GUI | |
1863 /* When GUI is active, also paste when 'mouse' is empty */ | |
1864 if (!gui.in_use) | |
1865 # endif | |
1866 if (!mouse_has(MOUSE_COMMAND)) | |
1867 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1868 # ifdef FEAT_CLIPBOARD |
7 | 1869 if (clip_star.available) |
1015 | 1870 cmdline_paste('*', TRUE, TRUE); |
7 | 1871 else |
692 | 1872 # endif |
1015 | 1873 cmdline_paste(0, TRUE, TRUE); |
7 | 1874 redrawcmd(); |
1875 goto cmdline_changed; | |
1876 | |
692 | 1877 # ifdef FEAT_DND |
7 | 1878 case K_DROP: |
1015 | 1879 cmdline_paste('~', TRUE, FALSE); |
7 | 1880 redrawcmd(); |
1881 goto cmdline_changed; | |
692 | 1882 # endif |
7 | 1883 |
1884 case K_LEFTDRAG: | |
1885 case K_LEFTRELEASE: | |
1886 case K_RIGHTDRAG: | |
1887 case K_RIGHTRELEASE: | |
1888 /* Ignore drag and release events when the button-down wasn't | |
1889 * seen before. */ | |
1890 if (ignore_drag_release) | |
1891 goto cmdline_not_changed; | |
1892 /* FALLTHROUGH */ | |
1893 case K_LEFTMOUSE: | |
1894 case K_RIGHTMOUSE: | |
1895 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1896 ignore_drag_release = TRUE; | |
1897 else | |
1898 ignore_drag_release = FALSE; | |
1899 # ifdef FEAT_GUI | |
1900 /* When GUI is active, also move when 'mouse' is empty */ | |
1901 if (!gui.in_use) | |
1902 # endif | |
1903 if (!mouse_has(MOUSE_COMMAND)) | |
1904 goto cmdline_not_changed; /* Ignore mouse */ | |
1905 # ifdef FEAT_CLIPBOARD | |
1906 if (mouse_row < cmdline_row && clip_star.available) | |
1907 { | |
1908 int button, is_click, is_drag; | |
1909 | |
1910 /* | |
1911 * Handle modeless selection. | |
1912 */ | |
1913 button = get_mouse_button(KEY2TERMCAP1(c), | |
1914 &is_click, &is_drag); | |
1915 if (mouse_model_popup() && button == MOUSE_LEFT | |
1916 && (mod_mask & MOD_MASK_SHIFT)) | |
1917 { | |
1918 /* Translate shift-left to right button. */ | |
1919 button = MOUSE_RIGHT; | |
1920 mod_mask &= ~MOD_MASK_SHIFT; | |
1921 } | |
1922 clip_modeless(button, is_click, is_drag); | |
1923 goto cmdline_not_changed; | |
1924 } | |
1925 # endif | |
1926 | |
1927 set_cmdspos(); | |
1928 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1929 ++ccline.cmdpos) | |
1930 { | |
1931 i = cmdline_charsize(ccline.cmdpos); | |
1932 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1933 && mouse_col < ccline.cmdspos % Columns + i) | |
1934 break; | |
692 | 1935 # ifdef FEAT_MBYTE |
7 | 1936 if (has_mbyte) |
1937 { | |
1938 /* Count ">" for double-wide char that doesn't fit. */ | |
1939 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1940 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1941 + ccline.cmdpos) - 1; |
1942 } | |
692 | 1943 # endif |
7 | 1944 ccline.cmdspos += i; |
1945 } | |
1946 goto cmdline_not_changed; | |
1947 | |
1948 /* Mouse scroll wheel: ignored here */ | |
1949 case K_MOUSEDOWN: | |
1950 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1951 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1952 case K_MOUSERIGHT: |
7 | 1953 /* Alternate buttons ignored here */ |
1954 case K_X1MOUSE: | |
1955 case K_X1DRAG: | |
1956 case K_X1RELEASE: | |
1957 case K_X2MOUSE: | |
1958 case K_X2DRAG: | |
1959 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1960 case K_MOUSEMOVE: |
7 | 1961 goto cmdline_not_changed; |
1962 | |
1963 #endif /* FEAT_MOUSE */ | |
1964 | |
1965 #ifdef FEAT_GUI | |
1966 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1967 case K_LEFTRELEASE_NM: | |
1968 goto cmdline_not_changed; | |
1969 | |
1970 case K_VER_SCROLLBAR: | |
540 | 1971 if (msg_scrolled == 0) |
7 | 1972 { |
1973 gui_do_scroll(); | |
1974 redrawcmd(); | |
1975 } | |
1976 goto cmdline_not_changed; | |
1977 | |
1978 case K_HOR_SCROLLBAR: | |
540 | 1979 if (msg_scrolled == 0) |
7 | 1980 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1981 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1982 redrawcmd(); |
1983 } | |
1984 goto cmdline_not_changed; | |
1985 #endif | |
692 | 1986 #ifdef FEAT_GUI_TABLINE |
1987 case K_TABLINE: | |
1988 case K_TABMENU: | |
1989 /* Don't want to change any tabs here. Make sure the same tab | |
1990 * is still selected. */ | |
1991 if (gui_use_tabline()) | |
1992 gui_mch_set_curtab(tabpage_index(curtab)); | |
1993 goto cmdline_not_changed; | |
1994 #endif | |
1995 | |
7 | 1996 case K_SELECT: /* end of Select mode mapping - ignore */ |
1997 goto cmdline_not_changed; | |
1998 | |
1999 case Ctrl_B: /* begin of command line */ | |
2000 case K_HOME: | |
2001 case K_KHOME: | |
2002 case K_S_HOME: | |
2003 case K_C_HOME: | |
2004 ccline.cmdpos = 0; | |
2005 set_cmdspos(); | |
2006 goto cmdline_not_changed; | |
2007 | |
2008 case Ctrl_E: /* end of command line */ | |
2009 case K_END: | |
2010 case K_KEND: | |
2011 case K_S_END: | |
2012 case K_C_END: | |
2013 ccline.cmdpos = ccline.cmdlen; | |
2014 set_cmdspos_cursor(); | |
2015 goto cmdline_not_changed; | |
2016 | |
2017 case Ctrl_A: /* all matches */ | |
3961 | 2018 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2019 break; |
2020 goto cmdline_changed; | |
2021 | |
772 | 2022 case Ctrl_L: |
2023 #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
|
2024 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2025 goto cmdline_not_changed; |
2026 #endif | |
2027 | |
2028 /* completion: longest common part */ | |
3961 | 2029 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2030 break; |
2031 goto cmdline_changed; | |
2032 | |
2033 case Ctrl_N: /* next match */ | |
2034 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2035 if (xpc.xp_numfiles > 0) |
7 | 2036 { |
3961 | 2037 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2038 0, firstc != '@') == FAIL) | |
7 | 2039 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2040 goto cmdline_not_changed; |
7 | 2041 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2042 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2043 /* FALLTHROUGH */ |
7 | 2044 case K_UP: |
2045 case K_DOWN: | |
2046 case K_S_UP: | |
2047 case K_S_DOWN: | |
2048 case K_PAGEUP: | |
2049 case K_KPAGEUP: | |
2050 case K_PAGEDOWN: | |
2051 case K_KPAGEDOWN: | |
2052 if (hislen == 0 || firstc == NUL) /* no history */ | |
2053 goto cmdline_not_changed; | |
2054 | |
2055 i = hiscnt; | |
2056 | |
2057 /* save current command string so it can be restored later */ | |
2058 if (lookfor == NULL) | |
2059 { | |
2060 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2061 goto cmdline_not_changed; | |
2062 lookfor[ccline.cmdpos] = NUL; | |
2063 } | |
2064 | |
2065 j = (int)STRLEN(lookfor); | |
2066 for (;;) | |
2067 { | |
2068 /* one step backwards */ | |
230 | 2069 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2070 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2071 { |
2072 if (hiscnt == hislen) /* first time */ | |
2073 hiscnt = hisidx[histype]; | |
2074 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2075 hiscnt = hislen - 1; | |
2076 else if (hiscnt != hisidx[histype] + 1) | |
2077 --hiscnt; | |
2078 else /* at top of list */ | |
2079 { | |
2080 hiscnt = i; | |
2081 break; | |
2082 } | |
2083 } | |
2084 else /* one step forwards */ | |
2085 { | |
2086 /* on last entry, clear the line */ | |
2087 if (hiscnt == hisidx[histype]) | |
2088 { | |
2089 hiscnt = hislen; | |
2090 break; | |
2091 } | |
2092 | |
2093 /* not on a history line, nothing to do */ | |
2094 if (hiscnt == hislen) | |
2095 break; | |
2096 if (hiscnt == hislen - 1) /* wrap around */ | |
2097 hiscnt = 0; | |
2098 else | |
2099 ++hiscnt; | |
2100 } | |
2101 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2102 { | |
2103 hiscnt = i; | |
2104 break; | |
2105 } | |
230 | 2106 if ((c != K_UP && c != K_DOWN) |
180 | 2107 || hiscnt == i |
7 | 2108 || STRNCMP(history[histype][hiscnt].hisstr, |
2109 lookfor, (size_t)j) == 0) | |
2110 break; | |
2111 } | |
2112 | |
2113 if (hiscnt != i) /* jumped to other entry */ | |
2114 { | |
2115 char_u *p; | |
2116 int len; | |
2117 int old_firstc; | |
2118 | |
2119 vim_free(ccline.cmdbuff); | |
1718 | 2120 xpc.xp_context = EXPAND_NOTHING; |
7 | 2121 if (hiscnt == hislen) |
2122 p = lookfor; /* back to the old one */ | |
2123 else | |
2124 p = history[histype][hiscnt].hisstr; | |
2125 | |
2126 if (histype == HIST_SEARCH | |
2127 && p != lookfor | |
2128 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2129 { | |
2130 /* Correct for the separator character used when | |
2131 * adding the history entry vs the one used now. | |
2132 * First loop: count length. | |
2133 * Second loop: copy the characters. */ | |
2134 for (i = 0; i <= 1; ++i) | |
2135 { | |
2136 len = 0; | |
2137 for (j = 0; p[j] != NUL; ++j) | |
2138 { | |
2139 /* Replace old sep with new sep, unless it is | |
2140 * escaped. */ | |
2141 if (p[j] == old_firstc | |
2142 && (j == 0 || p[j - 1] != '\\')) | |
2143 { | |
2144 if (i > 0) | |
2145 ccline.cmdbuff[len] = firstc; | |
2146 } | |
2147 else | |
2148 { | |
2149 /* Escape new sep, unless it is already | |
2150 * escaped. */ | |
2151 if (p[j] == firstc | |
2152 && (j == 0 || p[j - 1] != '\\')) | |
2153 { | |
2154 if (i > 0) | |
2155 ccline.cmdbuff[len] = '\\'; | |
2156 ++len; | |
2157 } | |
2158 if (i > 0) | |
2159 ccline.cmdbuff[len] = p[j]; | |
2160 } | |
2161 ++len; | |
2162 } | |
2163 if (i == 0) | |
2164 { | |
2165 alloc_cmdbuff(len); | |
2166 if (ccline.cmdbuff == NULL) | |
2167 goto returncmd; | |
2168 } | |
2169 } | |
2170 ccline.cmdbuff[len] = NUL; | |
2171 } | |
2172 else | |
2173 { | |
2174 alloc_cmdbuff((int)STRLEN(p)); | |
2175 if (ccline.cmdbuff == NULL) | |
2176 goto returncmd; | |
2177 STRCPY(ccline.cmdbuff, p); | |
2178 } | |
2179 | |
2180 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2181 redrawcmd(); | |
2182 goto cmdline_changed; | |
2183 } | |
2184 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2185 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2186 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2187 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2188 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2189 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2190 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
|
2191 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
|
2192 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
|
2193 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2194 break; |
7 | 2195 #endif |
2196 | |
2197 case Ctrl_V: | |
2198 case Ctrl_Q: | |
2199 #ifdef FEAT_MOUSE | |
2200 ignore_drag_release = TRUE; | |
2201 #endif | |
2202 putcmdline('^', TRUE); | |
2203 c = get_literal(); /* get next (two) character(s) */ | |
2204 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
|
2205 extra_char = NUL; |
7 | 2206 #ifdef FEAT_MBYTE |
2207 /* may need to remove ^ when composing char was typed */ | |
2208 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2209 { | |
2210 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2211 msg_putchar(' '); | |
2212 cursorcmd(); | |
2213 } | |
2214 #endif | |
2215 break; | |
2216 | |
2217 #ifdef FEAT_DIGRAPHS | |
2218 case Ctrl_K: | |
2219 #ifdef FEAT_MOUSE | |
2220 ignore_drag_release = TRUE; | |
2221 #endif | |
2222 putcmdline('?', TRUE); | |
2223 #ifdef USE_ON_FLY_SCROLL | |
2224 dont_scroll = TRUE; /* disallow scrolling here */ | |
2225 #endif | |
2226 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
|
2227 extra_char = NUL; |
7 | 2228 if (c != NUL) |
2229 break; | |
2230 | |
2231 redrawcmd(); | |
2232 goto cmdline_not_changed; | |
2233 #endif /* FEAT_DIGRAPHS */ | |
2234 | |
2235 #ifdef FEAT_RIGHTLEFT | |
2236 case Ctrl__: /* CTRL-_: switch language mode */ | |
2237 if (!p_ari) | |
2238 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2239 # ifdef FEAT_FKMAP |
7 | 2240 if (p_altkeymap) |
2241 { | |
2242 cmd_fkmap = !cmd_fkmap; | |
2243 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2244 ccline.overstrike = FALSE; | |
2245 } | |
2246 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2247 # endif |
7 | 2248 cmd_hkmap = !cmd_hkmap; |
2249 goto cmdline_not_changed; | |
2250 #endif | |
2251 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2252 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
|
2253 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
|
2254 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
|
2255 |
7 | 2256 default: |
2257 #ifdef UNIX | |
2258 if (c == intr_char) | |
2259 { | |
2260 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2261 putting it in history */ | |
2262 goto returncmd; /* back to Normal mode */ | |
2263 } | |
2264 #endif | |
2265 /* | |
2266 * Normal character with no special meaning. Just set mod_mask | |
2267 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2268 * the string <S-Space>. This should only happen after ^V. | |
2269 */ | |
2270 if (!IS_SPECIAL(c)) | |
2271 mod_mask = 0x0; | |
2272 break; | |
2273 } | |
2274 /* | |
2275 * End of switch on command line character. | |
2276 * We come here if we have a normal character. | |
2277 */ | |
2278 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2279 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2280 #ifdef FEAT_MBYTE |
2281 /* Add ABBR_OFF for characters above 0x100, this is | |
2282 * what check_abbr() expects. */ | |
2283 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2284 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2285 c) || c == Ctrl_RSB)) |
7 | 2286 goto cmdline_changed; |
2287 | |
2288 /* | |
2289 * put the character in the command line | |
2290 */ | |
2291 if (IS_SPECIAL(c) || mod_mask != 0) | |
2292 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2293 else | |
2294 { | |
2295 #ifdef FEAT_MBYTE | |
2296 if (has_mbyte) | |
2297 { | |
2298 j = (*mb_char2bytes)(c, IObuff); | |
2299 IObuff[j] = NUL; /* exclude composing chars */ | |
2300 put_on_cmdline(IObuff, j, TRUE); | |
2301 } | |
2302 else | |
2303 #endif | |
2304 { | |
2305 IObuff[0] = c; | |
2306 put_on_cmdline(IObuff, 1, TRUE); | |
2307 } | |
2308 } | |
2309 goto cmdline_changed; | |
2310 | |
2311 /* | |
2312 * This part implements incremental searches for "/" and "?" | |
2313 * Jump to cmdline_not_changed when a character has been read but the command | |
2314 * line did not change. Then we only search and redraw if something changed in | |
2315 * the past. | |
2316 * Jump to cmdline_changed when the command line did change. | |
2317 * (Sorry for the goto's, I know it is ugly). | |
2318 */ | |
2319 cmdline_not_changed: | |
2320 #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
|
2321 if (!is_state.incsearch_postponed) |
7 | 2322 continue; |
2323 #endif | |
2324 | |
2325 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
|
2326 /* 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
|
2327 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
|
2328 |
7 | 2329 #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
|
2330 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2331 #endif |
2332 | |
2333 #ifdef FEAT_RIGHTLEFT | |
2334 if (cmdmsg_rl | |
2335 # ifdef FEAT_ARABIC | |
534 | 2336 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2337 # endif |
2338 ) | |
2339 /* Always redraw the whole command line to fix shaping and | |
3374 | 2340 * right-left typing. Not efficient, but it works. |
2341 * Do it only when there are no characters left to read | |
2342 * to avoid useless intermediate redraws. */ | |
2343 if (vpeekc() == NUL) | |
2344 redrawcmd(); | |
7 | 2345 #endif |
2346 } | |
2347 | |
2348 returncmd: | |
2349 | |
2350 #ifdef FEAT_RIGHTLEFT | |
2351 cmdmsg_rl = FALSE; | |
2352 #endif | |
2353 | |
2354 #ifdef FEAT_FKMAP | |
2355 cmd_fkmap = 0; | |
2356 #endif | |
2357 | |
2358 ExpandCleanup(&xpc); | |
1718 | 2359 ccline.xpc = NULL; |
7 | 2360 |
2361 #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
|
2362 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2363 #endif |
2364 | |
2365 if (ccline.cmdbuff != NULL) | |
2366 { | |
2367 /* | |
2368 * Put line in history buffer (":" and "=" only when it was typed). | |
2369 */ | |
2370 #ifdef FEAT_CMDHIST | |
2371 if (ccline.cmdlen && firstc != NUL | |
2372 && (some_key_typed || histype == HIST_SEARCH)) | |
2373 { | |
2374 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2375 histype == HIST_SEARCH ? firstc : NUL); | |
2376 if (firstc == ':') | |
2377 { | |
2378 vim_free(new_last_cmdline); | |
2379 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2380 } | |
2381 } | |
2382 #endif | |
2383 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2384 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
|
2385 abandon_cmdline(); |
7 | 2386 } |
2387 | |
2388 /* | |
2389 * If the screen was shifted up, redraw the whole screen (later). | |
2390 * If the line is too long, clear it, so ruler and shown command do | |
2391 * not get printed in the middle of it. | |
2392 */ | |
2393 msg_check(); | |
2394 msg_scroll = save_msg_scroll; | |
2395 redir_off = FALSE; | |
2396 | |
2397 /* When the command line was typed, no need for a wait-return prompt. */ | |
2398 if (some_key_typed) | |
2399 need_wait_return = FALSE; | |
2400 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2401 /* 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
|
2402 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
|
2403 |
7 | 2404 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2405 #ifdef HAVE_INPUT_METHOD |
7 | 2406 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2407 im_save_status(b_im_ptr); | |
2408 im_set_active(FALSE); | |
2409 #endif | |
2410 #ifdef FEAT_MOUSE | |
2411 setmouse(); | |
2412 #endif | |
2413 #ifdef CURSOR_SHAPE | |
2414 ui_cursor_shape(); /* may show different cursor shape */ | |
2415 #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
|
2416 sb_text_end_cmdline(); |
7 | 2417 |
95 | 2418 { |
2419 char_u *p = ccline.cmdbuff; | |
2420 | |
2421 /* Make ccline empty, getcmdline() may try to use it. */ | |
2422 ccline.cmdbuff = NULL; | |
2423 return p; | |
2424 } | |
7 | 2425 } |
2426 | |
2427 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2428 /* | |
2429 * Get a command line with a prompt. | |
2430 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2431 * f_input() when evaluating an expression from CTRL-R =). | |
2432 * Returns the command line in allocated memory, or NULL. | |
2433 */ | |
2434 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2435 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2436 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2437 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2438 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2439 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2440 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2441 { |
2442 char_u *s; | |
2443 struct cmdline_info save_ccline; | |
2444 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
|
2445 int msg_silent_save = msg_silent; |
7 | 2446 |
95 | 2447 save_cmdline(&save_ccline); |
7 | 2448 ccline.cmdprompt = prompt; |
2449 ccline.cmdattr = attr; | |
531 | 2450 # ifdef FEAT_EVAL |
2451 ccline.xp_context = xp_context; | |
2452 ccline.xp_arg = xp_arg; | |
2453 ccline.input_fn = (firstc == '@'); | |
2454 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2455 msg_silent = 0; |
7 | 2456 s = getcmdline(firstc, 1L, 0); |
95 | 2457 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2458 msg_silent = msg_silent_save; |
3020 | 2459 /* Restore msg_col, the prompt from input() may have changed it. |
2460 * But only if called recursively and the commandline is therefore being | |
2461 * restored to an old one; if not, the input() prompt stays on the screen, | |
2462 * so we need its modified msg_col left intact. */ | |
2463 if (ccline.cmdbuff != NULL) | |
2464 msg_col = msg_col_save; | |
7 | 2465 |
2466 return s; | |
2467 } | |
2468 #endif | |
2469 | |
632 | 2470 /* |
634 | 2471 * Return TRUE when the text must not be changed and we can't switch to |
2472 * another window or buffer. Used when editing the command line, evaluating | |
2473 * 'balloonexpr', etc. | |
632 | 2474 */ |
2475 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2476 text_locked(void) |
632 | 2477 { |
2478 #ifdef FEAT_CMDWIN | |
2479 if (cmdwin_type != 0) | |
2480 return TRUE; | |
2481 #endif | |
634 | 2482 return textlock != 0; |
632 | 2483 } |
2484 | |
2485 /* | |
2486 * Give an error message for a command that isn't allowed while the cmdline | |
2487 * window is open or editing the cmdline in another way. | |
2488 */ | |
2489 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2490 text_locked_msg(void) |
632 | 2491 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2492 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2493 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2494 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2495 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2496 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2497 { |
632 | 2498 #ifdef FEAT_CMDWIN |
2499 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2500 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2501 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2502 return e_secure; |
632 | 2503 } |
2504 | |
819 | 2505 /* |
1834 | 2506 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2507 * and give an error message. | |
819 | 2508 */ |
2509 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2510 curbuf_locked(void) |
819 | 2511 { |
2512 if (curbuf_lock > 0) | |
2513 { | |
2514 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2515 return TRUE; | |
2516 } | |
1834 | 2517 return allbuf_locked(); |
2518 } | |
2519 | |
2520 /* | |
2521 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2522 * message. | |
2523 */ | |
2524 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2525 allbuf_locked(void) |
1834 | 2526 { |
2527 if (allbuf_lock > 0) | |
2528 { | |
2529 EMSG(_("E811: Not allowed to change buffer information now")); | |
2530 return TRUE; | |
2531 } | |
819 | 2532 return FALSE; |
2533 } | |
2534 | |
7 | 2535 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2536 cmdline_charsize(int idx) |
7 | 2537 { |
2538 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2539 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2540 return 1; | |
2541 #endif | |
2542 return ptr2cells(ccline.cmdbuff + idx); | |
2543 } | |
2544 | |
2545 /* | |
2546 * Compute the offset of the cursor on the command line for the prompt and | |
2547 * indent. | |
2548 */ | |
2549 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2550 set_cmdspos(void) |
7 | 2551 { |
531 | 2552 if (ccline.cmdfirstc != NUL) |
7 | 2553 ccline.cmdspos = 1 + ccline.cmdindent; |
2554 else | |
2555 ccline.cmdspos = 0 + ccline.cmdindent; | |
2556 } | |
2557 | |
2558 /* | |
2559 * Compute the screen position for the cursor on the command line. | |
2560 */ | |
2561 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2562 set_cmdspos_cursor(void) |
7 | 2563 { |
2564 int i, m, c; | |
2565 | |
2566 set_cmdspos(); | |
2567 if (KeyTyped) | |
534 | 2568 { |
7 | 2569 m = Columns * Rows; |
534 | 2570 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2571 m = MAXCOL; | |
2572 } | |
7 | 2573 else |
2574 m = MAXCOL; | |
2575 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2576 { | |
2577 c = cmdline_charsize(i); | |
2578 #ifdef FEAT_MBYTE | |
2579 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2580 if (has_mbyte) | |
2581 correct_cmdspos(i, c); | |
2582 #endif | |
1612 | 2583 /* If the cmdline doesn't fit, show cursor on last visible char. |
2584 * Don't move the cursor itself, so we can still append. */ | |
7 | 2585 if ((ccline.cmdspos += c) >= m) |
2586 { | |
2587 ccline.cmdspos -= c; | |
2588 break; | |
2589 } | |
2590 #ifdef FEAT_MBYTE | |
2591 if (has_mbyte) | |
474 | 2592 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2593 #endif |
2594 } | |
2595 } | |
2596 | |
2597 #ifdef FEAT_MBYTE | |
2598 /* | |
2599 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2600 * character that doesn't fit, so that a ">" must be displayed. | |
2601 */ | |
2602 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2603 correct_cmdspos(int idx, int cells) |
7 | 2604 { |
474 | 2605 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2606 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2607 && ccline.cmdspos % Columns + cells > Columns) | |
2608 ccline.cmdspos++; | |
2609 } | |
2610 #endif | |
2611 | |
2612 /* | |
2613 * Get an Ex command line for the ":" command. | |
2614 */ | |
2615 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2616 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2617 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2618 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2619 int indent) /* indent for inside conditionals */ |
7 | 2620 { |
2621 /* When executing a register, remove ':' that's in front of each line. */ | |
2622 if (exec_from_reg && vpeekc() == ':') | |
2623 (void)vgetc(); | |
2624 return getcmdline(c, 1L, indent); | |
2625 } | |
2626 | |
2627 /* | |
2628 * Get an Ex command line for Ex mode. | |
2629 * In Ex mode we only use the OS supplied line editing features and no | |
2630 * mappings or abbreviations. | |
168 | 2631 * Returns a string in allocated memory or NULL. |
7 | 2632 */ |
2633 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2634 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2635 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2636 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2637 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2638 int indent) /* indent for inside conditionals */ |
7 | 2639 { |
168 | 2640 garray_T line_ga; |
2641 char_u *pend; | |
2642 int startcol = 0; | |
1329 | 2643 int c1 = 0; |
168 | 2644 int escaped = FALSE; /* CTRL-V typed */ |
2645 int vcol = 0; | |
2646 char_u *p; | |
1329 | 2647 int prev_char; |
5966 | 2648 int len; |
7 | 2649 |
2650 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2651 * confuses the system function that computes tabstops. */ | |
2652 cursor_on(); | |
2653 | |
2654 /* always start in column 0; write a newline if necessary */ | |
2655 compute_cmdrow(); | |
168 | 2656 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2657 msg_putchar('\n'); |
168 | 2658 if (promptc == ':') |
7 | 2659 { |
164 | 2660 /* indent that is only displayed, not in the line itself */ |
168 | 2661 if (p_prompt) |
2662 msg_putchar(':'); | |
7 | 2663 while (indent-- > 0) |
2664 msg_putchar(' '); | |
2665 startcol = msg_col; | |
2666 } | |
2667 | |
2668 ga_init2(&line_ga, 1, 30); | |
2669 | |
164 | 2670 /* autoindent for :insert and :append is in the line itself */ |
168 | 2671 if (promptc <= 0) |
164 | 2672 { |
2673 vcol = indent; | |
2674 while (indent >= 8) | |
2675 { | |
2676 ga_append(&line_ga, TAB); | |
2677 msg_puts((char_u *)" "); | |
2678 indent -= 8; | |
2679 } | |
2680 while (indent-- > 0) | |
2681 { | |
2682 ga_append(&line_ga, ' '); | |
2683 msg_putchar(' '); | |
2684 } | |
2685 } | |
168 | 2686 ++no_mapping; |
2687 ++allow_keys; | |
164 | 2688 |
7 | 2689 /* |
2690 * Get the line, one character at a time. | |
2691 */ | |
2692 got_int = FALSE; | |
168 | 2693 while (!got_int) |
7 | 2694 { |
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
|
2695 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
|
2696 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
|
2697 |
7 | 2698 if (ga_grow(&line_ga, 40) == FAIL) |
2699 break; | |
2700 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2701 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2702 * 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
|
2703 */ |
1329 | 2704 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
|
2705 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2706 /* 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
|
2707 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
|
2708 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
|
2709 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2710 c1 = vgetc(); |
7 | 2711 |
2712 /* | |
168 | 2713 * Handle line editing. |
2714 * Previously this was left to the system, putting the terminal in | |
2715 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2716 */ |
168 | 2717 if (got_int) |
2718 { | |
2719 msg_putchar('\n'); | |
2720 break; | |
2721 } | |
2722 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2723 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
|
2724 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2725 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
|
2726 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
|
2727 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2728 |
168 | 2729 if (!escaped) |
7 | 2730 { |
168 | 2731 /* CR typed means "enter", which is NL */ |
2732 if (c1 == '\r') | |
2733 c1 = '\n'; | |
2734 | |
2735 if (c1 == BS || c1 == K_BS | |
2736 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2737 { |
168 | 2738 if (line_ga.ga_len > 0) |
2739 { | |
5966 | 2740 #ifdef FEAT_MBYTE |
2741 if (has_mbyte) | |
2742 { | |
2743 p = (char_u *)line_ga.ga_data; | |
2744 p[line_ga.ga_len] = NUL; | |
2745 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2746 line_ga.ga_len -= len; | |
2747 } | |
2748 else | |
2749 #endif | |
2750 --line_ga.ga_len; | |
168 | 2751 goto redraw; |
2752 } | |
2753 continue; | |
7 | 2754 } |
2755 | |
168 | 2756 if (c1 == Ctrl_U) |
7 | 2757 { |
168 | 2758 msg_col = startcol; |
2759 msg_clr_eos(); | |
2760 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
|
2761 goto redraw; |
168 | 2762 } |
2763 | |
2764 if (c1 == Ctrl_T) | |
2765 { | |
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
|
2766 sw = get_sw_value(curbuf); |
168 | 2767 p = (char_u *)line_ga.ga_data; |
2768 p[line_ga.ga_len] = NUL; | |
5995 | 2769 indent = get_indent_str(p, 8, FALSE); |
3740 | 2770 indent += sw - indent % sw; |
168 | 2771 add_indent: |
5995 | 2772 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2773 { |
7009 | 2774 (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
|
2775 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
|
2776 s = skipwhite(p); |
168 | 2777 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2778 *s = ' '; | |
2779 ++line_ga.ga_len; | |
7 | 2780 } |
168 | 2781 redraw: |
2782 /* redraw the line */ | |
2783 msg_col = startcol; | |
2784 vcol = 0; | |
5966 | 2785 p = (char_u *)line_ga.ga_data; |
2786 p[line_ga.ga_len] = NUL; | |
2787 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2788 { |
168 | 2789 if (*p == TAB) |
7 | 2790 { |
168 | 2791 do |
7 | 2792 { |
168 | 2793 msg_putchar(' '); |
2794 } while (++vcol % 8); | |
5966 | 2795 ++p; |
7 | 2796 } |
168 | 2797 else |
164 | 2798 { |
5966 | 2799 len = MB_PTR2LEN(p); |
2800 msg_outtrans_len(p, len); | |
2801 vcol += ptr2cells(p); | |
2802 p += len; | |
7 | 2803 } |
2804 } | |
168 | 2805 msg_clr_eos(); |
1329 | 2806 windgoto(msg_row, msg_col); |
168 | 2807 continue; |
2808 } | |
2809 | |
2810 if (c1 == Ctrl_D) | |
2811 { | |
2812 /* Delete one shiftwidth. */ | |
2813 p = (char_u *)line_ga.ga_data; | |
2814 if (prev_char == '0' || prev_char == '^') | |
7 | 2815 { |
168 | 2816 if (prev_char == '^') |
2817 ex_keep_indent = TRUE; | |
2818 indent = 0; | |
2819 p[--line_ga.ga_len] = NUL; | |
7 | 2820 } |
2821 else | |
2822 { | |
168 | 2823 p[line_ga.ga_len] = NUL; |
5995 | 2824 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
|
2825 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
|
2826 { |
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 --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
|
2828 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
|
2829 } |
168 | 2830 } |
5995 | 2831 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2832 { |
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
|
2833 s = skipwhite(p); |
168 | 2834 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2835 --line_ga.ga_len; | |
7 | 2836 } |
168 | 2837 goto add_indent; |
2838 } | |
2839 | |
2840 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2841 { | |
2842 escaped = TRUE; | |
2843 continue; | |
7 | 2844 } |
168 | 2845 |
2846 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2847 if (IS_SPECIAL(c1)) | |
2848 continue; | |
7 | 2849 } |
168 | 2850 |
2851 if (IS_SPECIAL(c1)) | |
2852 c1 = '?'; | |
5966 | 2853 #ifdef FEAT_MBYTE |
2854 if (has_mbyte) | |
2855 len = (*mb_char2bytes)(c1, | |
2856 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2857 else | |
2858 #endif | |
2859 { | |
2860 len = 1; | |
2861 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2862 } | |
168 | 2863 if (c1 == '\n') |
2864 msg_putchar('\n'); | |
2865 else if (c1 == TAB) | |
2866 { | |
2867 /* Don't use chartabsize(), 'ts' can be different */ | |
2868 do | |
2869 { | |
2870 msg_putchar(' '); | |
2871 } while (++vcol % 8); | |
2872 } | |
7 | 2873 else |
2874 { | |
168 | 2875 msg_outtrans_len( |
5966 | 2876 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2877 vcol += char2cells(c1); |
7 | 2878 } |
5966 | 2879 line_ga.ga_len += len; |
168 | 2880 escaped = FALSE; |
2881 | |
2882 windgoto(msg_row, msg_col); | |
164 | 2883 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2884 |
2590 | 2885 /* We are done when a NL is entered, but not when it comes after an |
2886 * odd number of backslashes, that results in a NUL. */ | |
2887 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2888 { |
2590 | 2889 int bcount = 0; |
2890 | |
2891 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2892 ++bcount; | |
2893 | |
2894 if (bcount > 0) | |
2895 { | |
2896 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2897 * "\NL", etc. */ | |
2898 line_ga.ga_len -= (bcount + 1) / 2; | |
2899 pend -= (bcount + 1) / 2; | |
2900 pend[-1] = '\n'; | |
2901 } | |
2902 | |
2903 if ((bcount & 1) == 0) | |
2904 { | |
2905 --line_ga.ga_len; | |
2906 --pend; | |
2907 *pend = NUL; | |
2908 break; | |
2909 } | |
7 | 2910 } |
2911 } | |
2912 | |
168 | 2913 --no_mapping; |
2914 --allow_keys; | |
2915 | |
7 | 2916 /* make following messages go to the next line */ |
2917 msg_didout = FALSE; | |
2918 msg_col = 0; | |
2919 if (msg_row < Rows - 1) | |
2920 ++msg_row; | |
2921 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2922 | |
2923 if (got_int) | |
2924 ga_clear(&line_ga); | |
2925 | |
2926 return (char_u *)line_ga.ga_data; | |
2927 } | |
2928 | |
502 | 2929 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2930 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2931 /* |
2932 * Return TRUE if ccline.overstrike is on. | |
2933 */ | |
2934 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2935 cmdline_overstrike(void) |
7 | 2936 { |
2937 return ccline.overstrike; | |
2938 } | |
2939 | |
2940 /* | |
2941 * Return TRUE if the cursor is at the end of the cmdline. | |
2942 */ | |
2943 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2944 cmdline_at_end(void) |
7 | 2945 { |
2946 return (ccline.cmdpos >= ccline.cmdlen); | |
2947 } | |
2948 #endif | |
2949 | |
574 | 2950 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2951 /* |
2952 * Return the virtual column number at the current cursor position. | |
2953 * This is used by the IM code to obtain the start of the preedit string. | |
2954 */ | |
2955 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2956 cmdline_getvcol_cursor(void) |
7 | 2957 { |
2958 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2959 return MAXCOL; | |
2960 | |
2961 # ifdef FEAT_MBYTE | |
2962 if (has_mbyte) | |
2963 { | |
2964 colnr_T col; | |
2965 int i = 0; | |
2966 | |
2967 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2968 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2969 |
2970 return col; | |
2971 } | |
2972 else | |
2973 # endif | |
2974 return ccline.cmdpos; | |
2975 } | |
2976 #endif | |
2977 | |
2978 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2979 /* | |
2980 * If part of the command line is an IM preedit string, redraw it with | |
2981 * IM feedback attributes. The cursor position is restored after drawing. | |
2982 */ | |
2983 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2984 redrawcmd_preedit(void) |
7 | 2985 { |
2986 if ((State & CMDLINE) | |
2987 && xic != NULL | |
976 | 2988 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2989 && !p_imdisable |
2990 && im_is_preediting()) | |
2991 { | |
2992 int cmdpos = 0; | |
2993 int cmdspos; | |
2994 int old_row; | |
2995 int old_col; | |
2996 colnr_T col; | |
2997 | |
2998 old_row = msg_row; | |
2999 old_col = msg_col; | |
531 | 3000 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3001 |
3002 # ifdef FEAT_MBYTE | |
3003 if (has_mbyte) | |
3004 { | |
3005 for (col = 0; col < preedit_start_col | |
3006 && cmdpos < ccline.cmdlen; ++col) | |
3007 { | |
3008 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3009 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3010 } |
3011 } | |
3012 else | |
3013 # endif | |
3014 { | |
3015 cmdspos += preedit_start_col; | |
3016 cmdpos += preedit_start_col; | |
3017 } | |
3018 | |
3019 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3020 msg_col = cmdspos % (int)Columns; | |
3021 if (msg_row >= Rows) | |
3022 msg_row = Rows - 1; | |
3023 | |
3024 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3025 { | |
3026 int char_len; | |
3027 int char_attr; | |
3028 | |
3029 char_attr = im_get_feedback_attr(col); | |
3030 if (char_attr < 0) | |
3031 break; /* end of preedit string */ | |
3032 | |
3033 # ifdef FEAT_MBYTE | |
3034 if (has_mbyte) | |
474 | 3035 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3036 else |
3037 # endif | |
3038 char_len = 1; | |
3039 | |
3040 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3041 cmdpos += char_len; | |
3042 } | |
3043 | |
3044 msg_row = old_row; | |
3045 msg_col = old_col; | |
3046 } | |
3047 } | |
3048 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3049 | |
3050 /* | |
3051 * Allocate a new command line buffer. | |
3052 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3053 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3054 */ | |
3055 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3056 alloc_cmdbuff(int len) |
7 | 3057 { |
3058 /* | |
3059 * give some extra space to avoid having to allocate all the time | |
3060 */ | |
3061 if (len < 80) | |
3062 len = 100; | |
3063 else | |
3064 len += 20; | |
3065 | |
3066 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3067 ccline.cmdbufflen = len; | |
3068 } | |
3069 | |
3070 /* | |
3071 * Re-allocate the command line to length len + something extra. | |
3072 * return FAIL for failure, OK otherwise | |
3073 */ | |
3074 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3075 realloc_cmdbuff(int len) |
7 | 3076 { |
3077 char_u *p; | |
3078 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3079 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3080 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
|
3081 |
7 | 3082 p = ccline.cmdbuff; |
3083 alloc_cmdbuff(len); /* will get some more */ | |
3084 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3085 { | |
3086 ccline.cmdbuff = p; /* keep the old one */ | |
3087 return FAIL; | |
3088 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3089 /* 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
|
3090 * 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
|
3091 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
|
3092 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3093 vim_free(p); |
1718 | 3094 |
3095 if (ccline.xpc != NULL | |
3096 && ccline.xpc->xp_pattern != NULL | |
3097 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3098 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3099 { | |
1754 | 3100 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3101 |
3102 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3103 * to point into the newly allocated memory. */ | |
3104 if (i >= 0 && i <= ccline.cmdlen) | |
3105 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3106 } | |
3107 | |
7 | 3108 return OK; |
3109 } | |
3110 | |
359 | 3111 #if defined(FEAT_ARABIC) || defined(PROTO) |
3112 static char_u *arshape_buf = NULL; | |
3113 | |
3114 # if defined(EXITFREE) || defined(PROTO) | |
3115 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3116 free_cmdline_buf(void) |
359 | 3117 { |
3118 vim_free(arshape_buf); | |
3119 } | |
3120 # endif | |
3121 #endif | |
3122 | |
7 | 3123 /* |
3124 * Draw part of the cmdline at the current cursor position. But draw stars | |
3125 * when cmdline_star is TRUE. | |
3126 */ | |
3127 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3128 draw_cmdline(int start, int len) |
7 | 3129 { |
3130 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3131 int i; | |
3132 | |
3133 if (cmdline_star > 0) | |
3134 for (i = 0; i < len; ++i) | |
3135 { | |
3136 msg_putchar('*'); | |
3137 # ifdef FEAT_MBYTE | |
3138 if (has_mbyte) | |
474 | 3139 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3140 # endif |
3141 } | |
3142 else | |
3143 #endif | |
3144 #ifdef FEAT_ARABIC | |
3145 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3146 { | |
3147 static int buflen = 0; | |
3148 char_u *p; | |
3149 int j; | |
3150 int newlen = 0; | |
3151 int mb_l; | |
719 | 3152 int pc, pc1 = 0; |
7 | 3153 int prev_c = 0; |
3154 int prev_c1 = 0; | |
714 | 3155 int u8c; |
3156 int u8cc[MAX_MCO]; | |
7 | 3157 int nc = 0; |
3158 | |
3159 /* | |
3160 * Do arabic shaping into a temporary buffer. This is very | |
3161 * inefficient! | |
3162 */ | |
507 | 3163 if (len * 2 + 2 > buflen) |
7 | 3164 { |
3165 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3166 * alloc()/free() calls. */ | |
359 | 3167 vim_free(arshape_buf); |
507 | 3168 buflen = len * 2 + 2; |
359 | 3169 arshape_buf = alloc(buflen); |
3170 if (arshape_buf == NULL) | |
7 | 3171 return; /* out of memory */ |
3172 } | |
3173 | |
507 | 3174 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3175 { | |
3176 /* Prepend a space to draw the leading composing char on. */ | |
3177 arshape_buf[0] = ' '; | |
3178 newlen = 1; | |
3179 } | |
3180 | |
7 | 3181 for (j = start; j < start + len; j += mb_l) |
3182 { | |
3183 p = ccline.cmdbuff + j; | |
714 | 3184 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3185 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3186 if (ARABIC_CHAR(u8c)) |
3187 { | |
3188 /* Do Arabic shaping. */ | |
3189 if (cmdmsg_rl) | |
3190 { | |
3191 /* displaying from right to left */ | |
3192 pc = prev_c; | |
3193 pc1 = prev_c1; | |
714 | 3194 prev_c1 = u8cc[0]; |
7 | 3195 if (j + mb_l >= start + len) |
3196 nc = NUL; | |
3197 else | |
3198 nc = utf_ptr2char(p + mb_l); | |
3199 } | |
3200 else | |
3201 { | |
3202 /* displaying from left to right */ | |
3203 if (j + mb_l >= start + len) | |
3204 pc = NUL; | |
3205 else | |
714 | 3206 { |
3207 int pcc[MAX_MCO]; | |
3208 | |
3209 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3210 start + len - j - mb_l); |
714 | 3211 pc1 = pcc[0]; |
3212 } | |
7 | 3213 nc = prev_c; |
3214 } | |
3215 prev_c = u8c; | |
3216 | |
714 | 3217 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3218 |
359 | 3219 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3220 if (u8cc[0] != 0) |
7 | 3221 { |
714 | 3222 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3223 if (u8cc[1] != 0) | |
3224 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3225 arshape_buf + newlen); |
7 | 3226 } |
3227 } | |
3228 else | |
3229 { | |
3230 prev_c = u8c; | |
359 | 3231 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3232 newlen += mb_l; |
3233 } | |
3234 } | |
3235 | |
359 | 3236 msg_outtrans_len(arshape_buf, newlen); |
7 | 3237 } |
3238 else | |
3239 #endif | |
3240 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3241 } | |
3242 | |
3243 /* | |
3244 * Put a character on the command line. Shifts the following text to the | |
3245 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3246 * "c" must be printable (fit in one display cell)! | |
3247 */ | |
3248 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3249 putcmdline(int c, int shift) |
7 | 3250 { |
3251 if (cmd_silent) | |
3252 return; | |
3253 msg_no_more = TRUE; | |
3254 msg_putchar(c); | |
3255 if (shift) | |
3256 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3257 msg_no_more = FALSE; | |
3258 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3259 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3260 extra_char_shift = shift; |
7 | 3261 } |
3262 | |
3263 /* | |
3264 * Undo a putcmdline(c, FALSE). | |
3265 */ | |
3266 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3267 unputcmdline(void) |
7 | 3268 { |
3269 if (cmd_silent) | |
3270 return; | |
3271 msg_no_more = TRUE; | |
3272 if (ccline.cmdlen == ccline.cmdpos) | |
3273 msg_putchar(' '); | |
3558 | 3274 #ifdef FEAT_MBYTE |
3275 else if (has_mbyte) | |
3276 draw_cmdline(ccline.cmdpos, | |
3277 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3278 #endif | |
7 | 3279 else |
3280 draw_cmdline(ccline.cmdpos, 1); | |
3281 msg_no_more = FALSE; | |
3282 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3283 extra_char = NUL; |
7 | 3284 } |
3285 | |
3286 /* | |
3287 * Put the given string, of the given length, onto the command line. | |
3288 * If len is -1, then STRLEN() is used to calculate the length. | |
3289 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3290 * part will be redrawn, otherwise it will not. If this function is called | |
3291 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3292 * called afterwards. | |
3293 */ | |
3294 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3295 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3296 { |
3297 int retval; | |
3298 int i; | |
3299 int m; | |
3300 int c; | |
3301 | |
3302 if (len < 0) | |
3303 len = (int)STRLEN(str); | |
3304 | |
3305 /* Check if ccline.cmdbuff needs to be longer */ | |
3306 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
|
3307 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3308 else |
3309 retval = OK; | |
3310 if (retval == OK) | |
3311 { | |
3312 if (!ccline.overstrike) | |
3313 { | |
3314 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3315 ccline.cmdbuff + ccline.cmdpos, | |
3316 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3317 ccline.cmdlen += len; | |
3318 } | |
3319 else | |
3320 { | |
3321 #ifdef FEAT_MBYTE | |
3322 if (has_mbyte) | |
3323 { | |
3324 /* Count nr of characters in the new string. */ | |
3325 m = 0; | |
474 | 3326 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3327 ++m; |
3328 /* Count nr of bytes in cmdline that are overwritten by these | |
3329 * characters. */ | |
3330 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3331 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3332 --m; |
3333 if (i < ccline.cmdlen) | |
3334 { | |
3335 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3336 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3337 ccline.cmdlen += ccline.cmdpos + len - i; | |
3338 } | |
3339 else | |
3340 ccline.cmdlen = ccline.cmdpos + len; | |
3341 } | |
3342 else | |
3343 #endif | |
3344 if (ccline.cmdpos + len > ccline.cmdlen) | |
3345 ccline.cmdlen = ccline.cmdpos + len; | |
3346 } | |
3347 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3348 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3349 | |
3350 #ifdef FEAT_MBYTE | |
3351 if (enc_utf8) | |
3352 { | |
3353 /* When the inserted text starts with a composing character, | |
3354 * backup to the character before it. There could be two of them. | |
3355 */ | |
3356 i = 0; | |
3357 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3358 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3359 { | |
3360 i = (*mb_head_off)(ccline.cmdbuff, | |
3361 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3362 ccline.cmdpos -= i; | |
3363 len += i; | |
3364 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3365 } | |
3366 # ifdef FEAT_ARABIC | |
3367 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3368 { | |
3369 /* Check the previous character for Arabic combining pair. */ | |
3370 i = (*mb_head_off)(ccline.cmdbuff, | |
3371 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3372 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3373 + ccline.cmdpos - i), c)) | |
3374 { | |
3375 ccline.cmdpos -= i; | |
3376 len += i; | |
3377 } | |
3378 else | |
3379 i = 0; | |
3380 } | |
3381 # endif | |
3382 if (i != 0) | |
3383 { | |
3384 /* Also backup the cursor position. */ | |
3385 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3386 ccline.cmdspos -= i; | |
3387 msg_col -= i; | |
3388 if (msg_col < 0) | |
3389 { | |
3390 msg_col += Columns; | |
3391 --msg_row; | |
3392 } | |
3393 } | |
3394 } | |
3395 #endif | |
3396 | |
3397 if (redraw && !cmd_silent) | |
3398 { | |
3399 msg_no_more = TRUE; | |
3400 i = cmdline_row; | |
3114 | 3401 cursorcmd(); |
7 | 3402 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3403 /* Avoid clearing the rest of the line too often. */ | |
3404 if (cmdline_row != i || ccline.overstrike) | |
3405 msg_clr_eos(); | |
3406 msg_no_more = FALSE; | |
3407 } | |
3408 #ifdef FEAT_FKMAP | |
3409 /* | |
3410 * If we are in Farsi command mode, the character input must be in | |
3411 * Insert mode. So do not advance the cmdpos. | |
3412 */ | |
3413 if (!cmd_fkmap) | |
3414 #endif | |
3415 { | |
3416 if (KeyTyped) | |
534 | 3417 { |
7 | 3418 m = Columns * Rows; |
534 | 3419 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3420 m = MAXCOL; | |
3421 } | |
7 | 3422 else |
3423 m = MAXCOL; | |
3424 for (i = 0; i < len; ++i) | |
3425 { | |
3426 c = cmdline_charsize(ccline.cmdpos); | |
3427 #ifdef FEAT_MBYTE | |
3428 /* count ">" for a double-wide char that doesn't fit. */ | |
3429 if (has_mbyte) | |
3430 correct_cmdspos(ccline.cmdpos, c); | |
3431 #endif | |
1612 | 3432 /* Stop cursor at the end of the screen, but do increment the |
3433 * insert position, so that entering a very long command | |
3434 * works, even though you can't see it. */ | |
3435 if (ccline.cmdspos + c < m) | |
3436 ccline.cmdspos += c; | |
7 | 3437 #ifdef FEAT_MBYTE |
3438 if (has_mbyte) | |
3439 { | |
474 | 3440 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3441 if (c > len - i - 1) |
3442 c = len - i - 1; | |
3443 ccline.cmdpos += c; | |
3444 i += c; | |
3445 } | |
3446 #endif | |
3447 ++ccline.cmdpos; | |
3448 } | |
3449 } | |
3450 } | |
3451 if (redraw) | |
3452 msg_check(); | |
3453 return retval; | |
3454 } | |
3455 | |
95 | 3456 static struct cmdline_info prev_ccline; |
3457 static int prev_ccline_used = FALSE; | |
3458 | |
3459 /* | |
3460 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3461 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3462 * available globally in prev_ccline. | |
3463 */ | |
3464 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3465 save_cmdline(struct cmdline_info *ccp) |
95 | 3466 { |
3467 if (!prev_ccline_used) | |
3468 { | |
3469 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3470 prev_ccline_used = TRUE; | |
3471 } | |
3472 *ccp = prev_ccline; | |
3473 prev_ccline = ccline; | |
3474 ccline.cmdbuff = NULL; | |
3475 ccline.cmdprompt = NULL; | |
1718 | 3476 ccline.xpc = NULL; |
95 | 3477 } |
3478 | |
3479 /* | |
1214 | 3480 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3481 */ |
3482 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3483 restore_cmdline(struct cmdline_info *ccp) |
95 | 3484 { |
3485 ccline = prev_ccline; | |
3486 prev_ccline = *ccp; | |
3487 } | |
3488 | |
849 | 3489 #if defined(FEAT_EVAL) || defined(PROTO) |
3490 /* | |
3491 * Save the command line into allocated memory. Returns a pointer to be | |
3492 * passed to restore_cmdline_alloc() later. | |
3493 * Returns NULL when failed. | |
3494 */ | |
3495 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3496 save_cmdline_alloc(void) |
849 | 3497 { |
3498 struct cmdline_info *p; | |
3499 | |
3500 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3501 if (p != NULL) | |
3502 save_cmdline(p); | |
3503 return (char_u *)p; | |
3504 } | |
3505 | |
3506 /* | |
3507 * Restore the command line from the return value of save_cmdline_alloc(). | |
3508 */ | |
3509 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3510 restore_cmdline_alloc(char_u *p) |
849 | 3511 { |
3512 if (p != NULL) | |
3513 { | |
3514 restore_cmdline((struct cmdline_info *)p); | |
3515 vim_free(p); | |
3516 } | |
3517 } | |
3518 #endif | |
3519 | |
15 | 3520 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3521 * 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
|
3522 * Used by CTRL-R command in command-line mode. |
15 | 3523 * insert_reg() can't be used here, because special characters from the |
3524 * register contents will be interpreted as commands. | |
3525 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3526 * Return FAIL for failure, OK otherwise. |
15 | 3527 */ |
3528 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3529 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3530 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3531 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
|
3532 int remcr) /* remove trailing CR */ |
15 | 3533 { |
3534 long i; | |
3535 char_u *arg; | |
772 | 3536 char_u *p; |
15 | 3537 int allocated; |
3538 struct cmdline_info save_ccline; | |
3539 | |
3540 /* check for valid regname; also accept special characters for CTRL-R in | |
3541 * the command line */ | |
3542 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
|
3543 && 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
|
3544 && !valid_yank_reg(regname, FALSE)) |
15 | 3545 return FAIL; |
3546 | |
3547 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3548 * CTRL-C to break the loop. */ | |
3549 line_breakcheck(); | |
3550 if (got_int) | |
3551 return FAIL; | |
3552 | |
3553 #ifdef FEAT_CLIPBOARD | |
3554 regname = may_get_selection(regname); | |
3555 #endif | |
3556 | |
634 | 3557 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3558 * things like going to another buffer when evaluating an expression. */ |
95 | 3559 save_cmdline(&save_ccline); |
634 | 3560 ++textlock; |
15 | 3561 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3562 --textlock; |
95 | 3563 restore_cmdline(&save_ccline); |
15 | 3564 |
3565 if (i) | |
3566 { | |
3567 /* Got the value of a special register in "arg". */ | |
3568 if (arg == NULL) | |
3569 return FAIL; | |
772 | 3570 |
3571 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3572 * part of the word. */ | |
3573 p = arg; | |
3574 if (p_is && regname == Ctrl_W) | |
3575 { | |
3576 char_u *w; | |
3577 int len; | |
3578 | |
3579 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3580 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3581 { |
3582 #ifdef FEAT_MBYTE | |
3583 if (has_mbyte) | |
3584 { | |
3585 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3586 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3587 break; | |
3588 w -= len; | |
3589 } | |
3590 else | |
3591 #endif | |
3592 { | |
3593 if (!vim_iswordc(w[-1])) | |
3594 break; | |
3595 --w; | |
3596 } | |
3597 } | |
2937 | 3598 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3599 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3600 p += len; | |
3601 } | |
3602 | |
3603 cmdline_paste_str(p, literally); | |
15 | 3604 if (allocated) |
3605 vim_free(arg); | |
3606 return OK; | |
3607 } | |
3608 | |
1015 | 3609 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3610 } |
3611 | |
3612 /* | |
3613 * Put a string on the command line. | |
3614 * When "literally" is TRUE, insert literally. | |
3615 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3616 * line. | |
3617 */ | |
3618 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3619 cmdline_paste_str(char_u *s, int literally) |
15 | 3620 { |
3621 int c, cv; | |
3622 | |
3623 if (literally) | |
3624 put_on_cmdline(s, -1, TRUE); | |
3625 else | |
3626 while (*s != NUL) | |
3627 { | |
3628 cv = *s; | |
3629 if (cv == Ctrl_V && s[1]) | |
3630 ++s; | |
3631 #ifdef FEAT_MBYTE | |
3632 if (has_mbyte) | |
1606 | 3633 c = mb_cptr2char_adv(&s); |
15 | 3634 else |
3635 #endif | |
3636 c = *s++; | |
3628 | 3637 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3638 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3639 #ifdef UNIX |
3640 || c == intr_char | |
3641 #endif | |
3642 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3643 stuffcharReadbuff(Ctrl_V); | |
3644 stuffcharReadbuff(c); | |
3645 } | |
3646 } | |
3647 | |
7 | 3648 #ifdef FEAT_WILDMENU |
3649 /* | |
3650 * Delete characters on the command line, from "from" to the current | |
3651 * position. | |
3652 */ | |
3653 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3654 cmdline_del(int from) |
7 | 3655 { |
3656 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3657 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3658 ccline.cmdlen -= ccline.cmdpos - from; | |
3659 ccline.cmdpos = from; | |
3660 } | |
3661 #endif | |
3662 | |
3663 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3664 * 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
|
3665 * 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
|
3666 * overwritten. |
7 | 3667 */ |
3668 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3669 redrawcmdline(void) |
7 | 3670 { |
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
|
3671 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
|
3672 } |
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
|
3673 |
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
|
3674 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
|
3675 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
|
3676 { |
7 | 3677 if (cmd_silent) |
3678 return; | |
3679 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
|
3680 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
|
3681 compute_cmdrow(); |
7 | 3682 redrawcmd(); |
3683 cursorcmd(); | |
3684 } | |
3685 | |
3686 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3687 redrawcmdprompt(void) |
7 | 3688 { |
3689 int i; | |
3690 | |
3691 if (cmd_silent) | |
3692 return; | |
531 | 3693 if (ccline.cmdfirstc != NUL) |
7 | 3694 msg_putchar(ccline.cmdfirstc); |
3695 if (ccline.cmdprompt != NULL) | |
3696 { | |
3697 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3698 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3699 /* do the reverse of set_cmdspos() */ | |
531 | 3700 if (ccline.cmdfirstc != NUL) |
7 | 3701 --ccline.cmdindent; |
3702 } | |
3703 else | |
3704 for (i = ccline.cmdindent; i > 0; --i) | |
3705 msg_putchar(' '); | |
3706 } | |
3707 | |
3708 /* | |
3709 * Redraw what is currently on the command line. | |
3710 */ | |
3711 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3712 redrawcmd(void) |
7 | 3713 { |
3714 if (cmd_silent) | |
3715 return; | |
3716 | |
683 | 3717 /* when 'incsearch' is set there may be no command line while redrawing */ |
3718 if (ccline.cmdbuff == NULL) | |
3719 { | |
3720 windgoto(cmdline_row, 0); | |
3721 msg_clr_eos(); | |
3722 return; | |
3723 } | |
3724 | |
7 | 3725 msg_start(); |
3726 redrawcmdprompt(); | |
3727 | |
3728 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3729 msg_no_more = TRUE; | |
3730 draw_cmdline(0, ccline.cmdlen); | |
3731 msg_clr_eos(); | |
3732 msg_no_more = FALSE; | |
3733 | |
3734 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
|
3735 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
|
3736 putcmdline(extra_char, extra_char_shift); |
7 | 3737 |
3738 /* | |
3739 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3740 * in cmdline mode we can reset them now. | |
3741 */ | |
3742 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3743 | |
3744 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3745 * in cmdline mode */ | |
3746 skip_redraw = FALSE; | |
3747 } | |
3748 | |
3749 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3750 compute_cmdrow(void) |
7 | 3751 { |
540 | 3752 if (exmode_active || msg_scrolled != 0) |
7 | 3753 cmdline_row = Rows - 1; |
3754 else | |
3755 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
|
3756 + lastwin->w_status_height; |
7 | 3757 } |
3758 | |
3759 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3760 cursorcmd(void) |
7 | 3761 { |
3762 if (cmd_silent) | |
3763 return; | |
3764 | |
3765 #ifdef FEAT_RIGHTLEFT | |
3766 if (cmdmsg_rl) | |
3767 { | |
3768 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3769 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3770 if (msg_row <= 0) | |
3771 msg_row = Rows - 1; | |
3772 } | |
3773 else | |
3774 #endif | |
3775 { | |
3776 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3777 msg_col = ccline.cmdspos % (int)Columns; | |
3778 if (msg_row >= Rows) | |
3779 msg_row = Rows - 1; | |
3780 } | |
3781 | |
3782 windgoto(msg_row, msg_col); | |
3783 #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
|
3784 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
|
3785 redrawcmd_preedit(); |
7 | 3786 #endif |
3787 #ifdef MCH_CURSOR_SHAPE | |
3788 mch_update_cursor(); | |
3789 #endif | |
3790 } | |
3791 | |
3792 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3793 gotocmdline(int clr) |
7 | 3794 { |
3795 msg_start(); | |
3796 #ifdef FEAT_RIGHTLEFT | |
3797 if (cmdmsg_rl) | |
3798 msg_col = Columns - 1; | |
3799 else | |
3800 #endif | |
3801 msg_col = 0; /* always start in column 0 */ | |
3802 if (clr) /* clear the bottom line(s) */ | |
3803 msg_clr_eos(); /* will reset clear_cmdline */ | |
3804 windgoto(cmdline_row, 0); | |
3805 } | |
3806 | |
3807 /* | |
3808 * Check the word in front of the cursor for an abbreviation. | |
3809 * Called when the non-id character "c" has been entered. | |
3810 * When an abbreviation is recognized it is removed from the text with | |
3811 * backspaces and the replacement string is inserted, followed by "c". | |
3812 */ | |
3813 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3814 ccheck_abbr(int c) |
7 | 3815 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3816 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3817 |
7 | 3818 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3819 return FALSE; | |
3820 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3821 /* 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
|
3822 * 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
|
3823 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
|
3824 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3825 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
|
3826 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3827 && 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
|
3828 && 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
|
3829 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3830 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3831 /* 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
|
3832 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3833 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3834 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3835 } |
3836 | |
3164 | 3837 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3838 static int | |
3839 #ifdef __BORLANDC__ | |
3840 _RTLENTRYF | |
3841 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3842 sort_func_compare(const void *s1, const void *s2) |
3164 | 3843 { |
3844 char_u *p1 = *(char_u **)s1; | |
3845 char_u *p2 = *(char_u **)s2; | |
3846 | |
3847 if (*p1 != '<' && *p2 == '<') return -1; | |
3848 if (*p1 == '<' && *p2 != '<') return 1; | |
3849 return STRCMP(p1, p2); | |
3850 } | |
3851 #endif | |
3852 | |
7 | 3853 /* |
3854 * Return FAIL if this is not an appropriate context in which to do | |
3855 * completion of anything, return OK if it is (even if there are no matches). | |
3856 * For the caller, this means that the character is just passed through like a | |
3857 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3858 */ | |
3859 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3860 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3861 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3862 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3863 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3864 int escape) /* if TRUE, escape the returned matches */ |
7 | 3865 { |
3866 int i, j; | |
3867 char_u *p1; | |
3868 char_u *p2; | |
3869 int difflen; | |
3870 int v; | |
3871 | |
3872 if (xp->xp_numfiles == -1) | |
3873 { | |
3874 set_expand_context(xp); | |
3875 cmd_showtail = expand_showtail(xp); | |
3876 } | |
3877 | |
3878 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3879 { | |
3880 beep_flush(); | |
3881 return OK; /* Something illegal on command line */ | |
3882 } | |
3883 if (xp->xp_context == EXPAND_NOTHING) | |
3884 { | |
3885 /* Caller can use the character as a normal char instead */ | |
3886 return FAIL; | |
3887 } | |
3888 | |
3889 MSG_PUTS("..."); /* show that we are busy */ | |
3890 out_flush(); | |
3891 | |
3892 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3893 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3894 |
3895 if (type == WILD_NEXT || type == WILD_PREV) | |
3896 { | |
3897 /* | |
3898 * Get next/previous match for a previous expanded pattern. | |
3899 */ | |
3900 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3901 } | |
3902 else | |
3903 { | |
3904 /* | |
3905 * Translate string into pattern and expand it. | |
3906 */ | |
1965 | 3907 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3908 xp->xp_context)) == NULL) | |
7 | 3909 p2 = NULL; |
3910 else | |
3911 { | |
2652 | 3912 int use_options = options | |
3961 | 3913 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3914 if (escape) | |
3915 use_options |= WILD_ESCAPE; | |
2652 | 3916 |
3917 if (p_wic) | |
3918 use_options += WILD_ICASE; | |
1965 | 3919 p2 = ExpandOne(xp, p1, |
3920 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3921 use_options, type); |
7 | 3922 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3923 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3924 if (p2 != NULL && type == WILD_LONGEST) |
3925 { | |
1965 | 3926 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3927 if (ccline.cmdbuff[i + j] == '*' |
3928 || ccline.cmdbuff[i + j] == '?') | |
3929 break; | |
3930 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
|
3931 VIM_CLEAR(p2); |
7 | 3932 } |
3933 } | |
3934 } | |
3935 | |
3936 if (p2 != NULL && !got_int) | |
3937 { | |
1965 | 3938 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
|
3939 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3940 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3941 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3942 xp->xp_pattern = ccline.cmdbuff + i; |
3943 } | |
3944 else | |
3945 v = OK; | |
3946 if (v == OK) | |
3947 { | |
323 | 3948 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3949 &ccline.cmdbuff[ccline.cmdpos], | |
3950 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3951 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3952 ccline.cmdlen += difflen; |
3953 ccline.cmdpos += difflen; | |
3954 } | |
3955 } | |
3956 vim_free(p2); | |
3957 | |
3958 redrawcmd(); | |
33 | 3959 cursorcmd(); |
7 | 3960 |
3961 /* When expanding a ":map" command and no matches are found, assume that | |
3962 * the key is supposed to be inserted literally */ | |
3963 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3964 return FAIL; | |
3965 | |
3966 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3967 beep_flush(); | |
3968 else if (xp->xp_numfiles == 1) | |
3969 /* free expanded pattern */ | |
3970 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3971 | |
3972 return OK; | |
3973 } | |
3974 | |
3975 /* | |
3976 * Do wildcard expansion on the string 'str'. | |
3977 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3978 * Return a pointer to allocated memory containing the new string. |
7 | 3979 * Return NULL for failure. |
3980 * | |
1412 | 3981 * "orig" is the originally expanded string, copied to allocated memory. It |
3982 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3983 * WILD_PREV "orig" should be NULL. | |
3984 * | |
838 | 3985 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3986 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3987 * |
3988 * mode = WILD_FREE: just free previously expanded matches | |
3989 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3990 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3991 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3992 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3993 * mode = WILD_ALL: return all matches concatenated | |
3994 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3995 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3996 * |
3997 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3998 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3999 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4000 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4001 * options = WILD_ADD_SLASH: add a slash after directory names | |
4002 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4003 * options = WILD_SILENT: don't print warning messages | |
4004 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4005 * options = WILD_ICASE: ignore case for files |
7 | 4006 * |
4007 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4008 */ | |
4009 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4010 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4011 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4012 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4013 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
|
4014 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4015 int mode) |
7 | 4016 { |
4017 char_u *ss = NULL; | |
4018 static int findex; | |
4019 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4020 int orig_saved = FALSE; |
7 | 4021 int i; |
4022 long_u len; | |
4023 int non_suf_match; /* number without matching suffix */ | |
4024 | |
4025 /* | |
4026 * first handle the case of using an old match | |
4027 */ | |
4028 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4029 { | |
4030 if (xp->xp_numfiles > 0) | |
4031 { | |
4032 if (mode == WILD_PREV) | |
4033 { | |
4034 if (findex == -1) | |
4035 findex = xp->xp_numfiles; | |
4036 --findex; | |
4037 } | |
4038 else /* mode == WILD_NEXT */ | |
4039 ++findex; | |
4040 | |
4041 /* | |
4042 * When wrapping around, return the original string, set findex to | |
4043 * -1. | |
4044 */ | |
4045 if (findex < 0) | |
4046 { | |
4047 if (orig_save == NULL) | |
4048 findex = xp->xp_numfiles - 1; | |
4049 else | |
4050 findex = -1; | |
4051 } | |
4052 if (findex >= xp->xp_numfiles) | |
4053 { | |
4054 if (orig_save == NULL) | |
4055 findex = 0; | |
4056 else | |
4057 findex = -1; | |
4058 } | |
4059 #ifdef FEAT_WILDMENU | |
4060 if (p_wmnu) | |
4061 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4062 findex, cmd_showtail); | |
4063 #endif | |
4064 if (findex == -1) | |
4065 return vim_strsave(orig_save); | |
4066 return vim_strsave(xp->xp_files[findex]); | |
4067 } | |
4068 else | |
4069 return NULL; | |
4070 } | |
4071 | |
1412 | 4072 /* free old names */ |
7 | 4073 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4074 { | |
4075 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4076 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
|
4077 VIM_CLEAR(orig_save); |
7 | 4078 } |
4079 findex = 0; | |
4080 | |
4081 if (mode == WILD_FREE) /* only release file name */ | |
4082 return NULL; | |
4083 | |
4084 if (xp->xp_numfiles == -1) | |
4085 { | |
4086 vim_free(orig_save); | |
4087 orig_save = orig; | |
1432 | 4088 orig_saved = TRUE; |
7 | 4089 |
4090 /* | |
4091 * Do the expansion. | |
4092 */ | |
4093 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4094 options) == FAIL) | |
4095 { | |
4096 #ifdef FNAME_ILLEGAL | |
4097 /* Illegal file name has been silently skipped. But when there | |
4098 * are wildcards, the real problem is that there was no match, | |
4099 * causing the pattern to be added, which has illegal characters. | |
4100 */ | |
4101 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4102 EMSG2(_(e_nomatch2), str); | |
4103 #endif | |
4104 } | |
4105 else if (xp->xp_numfiles == 0) | |
4106 { | |
4107 if (!(options & WILD_SILENT)) | |
4108 EMSG2(_(e_nomatch2), str); | |
4109 } | |
4110 else | |
4111 { | |
4112 /* Escape the matches for use on the command line. */ | |
4113 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4114 | |
4115 /* | |
4116 * Check for matching suffixes in file names. | |
4117 */ | |
3398 | 4118 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4119 && mode != WILD_LONGEST) | |
7 | 4120 { |
4121 if (xp->xp_numfiles) | |
4122 non_suf_match = xp->xp_numfiles; | |
4123 else | |
4124 non_suf_match = 1; | |
4125 if ((xp->xp_context == EXPAND_FILES | |
4126 || xp->xp_context == EXPAND_DIRECTORIES) | |
4127 && xp->xp_numfiles > 1) | |
4128 { | |
4129 /* | |
4130 * More than one match; check suffix. | |
4131 * The files will have been sorted on matching suffix in | |
4132 * expand_wildcards, only need to check the first two. | |
4133 */ | |
4134 non_suf_match = 0; | |
4135 for (i = 0; i < 2; ++i) | |
4136 if (match_suffix(xp->xp_files[i])) | |
4137 ++non_suf_match; | |
4138 } | |
4139 if (non_suf_match != 1) | |
4140 { | |
4141 /* Can we ever get here unless it's while expanding | |
4142 * interactively? If not, we can get rid of this all | |
4143 * together. Don't really want to wait for this message | |
4144 * (and possibly have to hit return to continue!). | |
4145 */ | |
4146 if (!(options & WILD_SILENT)) | |
4147 EMSG(_(e_toomany)); | |
4148 else if (!(options & WILD_NO_BEEP)) | |
4149 beep_flush(); | |
4150 } | |
4151 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4152 ss = vim_strsave(xp->xp_files[0]); | |
4153 } | |
4154 } | |
4155 } | |
4156 | |
4157 /* Find longest common part */ | |
4158 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4159 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4160 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4161 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4162 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4163 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4164 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4165 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4166 if (has_mbyte) |
7 | 4167 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4168 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
|
4169 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
|
4170 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4171 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4172 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4173 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
|
4174 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
|
4175 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4176 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4177 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4178 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
|
4179 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4180 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4181 ci = xp->xp_files[i][len]; |
4242 | 4182 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4183 || xp->xp_context == EXPAND_FILES |
714 | 4184 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4185 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4186 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4187 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4188 break; |
4189 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4190 else if (c0 != ci) |
7 | 4191 break; |
4192 } | |
4193 if (i < xp->xp_numfiles) | |
4194 { | |
4195 if (!(options & WILD_NO_BEEP)) | |
6949 | 4196 vim_beep(BO_WILD); |
7 | 4197 break; |
4198 } | |
4199 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4200 |
7 | 4201 ss = alloc((unsigned)len + 1); |
4202 if (ss) | |
419 | 4203 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4204 findex = -1; /* next p_wc gets first one */ |
4205 } | |
4206 | |
4207 /* Concatenate all matching names */ | |
4208 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4209 { | |
4210 len = 0; | |
4211 for (i = 0; i < xp->xp_numfiles; ++i) | |
4212 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4213 ss = lalloc(len, TRUE); | |
4214 if (ss != NULL) | |
4215 { | |
4216 *ss = NUL; | |
4217 for (i = 0; i < xp->xp_numfiles; ++i) | |
4218 { | |
4219 STRCAT(ss, xp->xp_files[i]); | |
4220 if (i != xp->xp_numfiles - 1) | |
4221 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4222 } | |
4223 } | |
4224 } | |
4225 | |
4226 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4227 ExpandCleanup(xp); | |
4228 | |
1412 | 4229 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4230 if (!orig_saved) |
1412 | 4231 vim_free(orig); |
4232 | |
7 | 4233 return ss; |
4234 } | |
4235 | |
4236 /* | |
4237 * Prepare an expand structure for use. | |
4238 */ | |
4239 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4240 ExpandInit(expand_T *xp) |
7 | 4241 { |
1718 | 4242 xp->xp_pattern = NULL; |
1965 | 4243 xp->xp_pattern_len = 0; |
7 | 4244 xp->xp_backslash = XP_BS_NONE; |
632 | 4245 #ifndef BACKSLASH_IN_FILENAME |
4246 xp->xp_shell = FALSE; | |
4247 #endif | |
7 | 4248 xp->xp_numfiles = -1; |
4249 xp->xp_files = NULL; | |
632 | 4250 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4251 xp->xp_arg = NULL; | |
4252 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4253 xp->xp_line = NULL; |
7 | 4254 } |
4255 | |
4256 /* | |
4257 * Cleanup an expand structure after use. | |
4258 */ | |
4259 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4260 ExpandCleanup(expand_T *xp) |
7 | 4261 { |
4262 if (xp->xp_numfiles >= 0) | |
4263 { | |
4264 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4265 xp->xp_numfiles = -1; | |
4266 } | |
4267 } | |
4268 | |
4269 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4270 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4271 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4272 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4273 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4274 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4275 int options) |
7 | 4276 { |
4277 int i; | |
4278 char_u *p; | |
4279 | |
4280 /* | |
4281 * May change home directory back to "~" | |
4282 */ | |
4283 if (options & WILD_HOME_REPLACE) | |
4284 tilde_replace(str, numfiles, files); | |
4285 | |
4286 if (options & WILD_ESCAPE) | |
4287 { | |
4288 if (xp->xp_context == EXPAND_FILES | |
2778 | 4289 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4290 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4291 || xp->xp_context == EXPAND_BUFFERS |
4292 || xp->xp_context == EXPAND_DIRECTORIES) | |
4293 { | |
4294 /* | |
4295 * Insert a backslash into a file name before a space, \, %, # | |
4296 * and wildmatch characters, except '~'. | |
4297 */ | |
4298 for (i = 0; i < numfiles; ++i) | |
4299 { | |
4300 /* for ":set path=" we need to escape spaces twice */ | |
4301 if (xp->xp_backslash == XP_BS_THREE) | |
4302 { | |
4303 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4304 if (p != NULL) | |
4305 { | |
4306 vim_free(files[i]); | |
4307 files[i] = p; | |
719 | 4308 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4309 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4310 if (p != NULL) | |
4311 { | |
4312 vim_free(files[i]); | |
4313 files[i] = p; | |
4314 } | |
4315 #endif | |
4316 } | |
4317 } | |
1589 | 4318 #ifdef BACKSLASH_IN_FILENAME |
4319 p = vim_strsave_fnameescape(files[i], FALSE); | |
4320 #else | |
1586 | 4321 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4322 #endif |
7 | 4323 if (p != NULL) |
4324 { | |
4325 vim_free(files[i]); | |
4326 files[i] = p; | |
4327 } | |
4328 | |
4329 /* If 'str' starts with "\~", replace "~" at start of | |
4330 * files[i] with "\~". */ | |
4331 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4332 escape_fname(&files[i]); |
7 | 4333 } |
4334 xp->xp_backslash = XP_BS_NONE; | |
435 | 4335 |
4336 /* If the first file starts with a '+' escape it. Otherwise it | |
4337 * could be seen as "+cmd". */ | |
4338 if (*files[0] == '+') | |
4339 escape_fname(&files[0]); | |
7 | 4340 } |
4341 else if (xp->xp_context == EXPAND_TAGS) | |
4342 { | |
4343 /* | |
4344 * Insert a backslash before characters in a tag name that | |
4345 * would terminate the ":tag" command. | |
4346 */ | |
4347 for (i = 0; i < numfiles; ++i) | |
4348 { | |
4349 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4350 if (p != NULL) | |
4351 { | |
4352 vim_free(files[i]); | |
4353 files[i] = p; | |
4354 } | |
4355 } | |
4356 } | |
4357 } | |
4358 } | |
4359 | |
4360 /* | |
1586 | 4361 * Escape special characters in "fname" for when used as a file name argument |
4362 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4363 * Returns the result in allocated memory. | |
4364 */ | |
4365 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4366 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4367 { |
1685 | 4368 char_u *p; |
1586 | 4369 #ifdef BACKSLASH_IN_FILENAME |
4370 char_u buf[20]; | |
4371 int j = 0; | |
4372 | |
5481 | 4373 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4374 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4375 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4376 buf[j++] = *p; |
4377 buf[j] = NUL; | |
1700 | 4378 p = vim_strsave_escaped(fname, buf); |
1586 | 4379 #else |
1685 | 4380 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4381 if (shell && csh_like_shell() && p != NULL) | |
4382 { | |
4383 char_u *s; | |
4384 | |
4385 /* For csh and similar shells need to put two backslashes before '!'. | |
4386 * One is taken by Vim, one by the shell. */ | |
4387 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4388 vim_free(p); | |
4389 p = s; | |
4390 } | |
1700 | 4391 #endif |
4392 | |
4393 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4394 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4395 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4396 escape_fname(&p); |
4397 | |
1685 | 4398 return p; |
1586 | 4399 } |
4400 | |
4401 /* | |
435 | 4402 * Put a backslash before the file name in "pp", which is in allocated memory. |
4403 */ | |
4404 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4405 escape_fname(char_u **pp) |
435 | 4406 { |
4407 char_u *p; | |
4408 | |
4409 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4410 if (p != NULL) | |
4411 { | |
4412 p[0] = '\\'; | |
4413 STRCPY(p + 1, *pp); | |
4414 vim_free(*pp); | |
4415 *pp = p; | |
4416 } | |
4417 } | |
4418 | |
4419 /* | |
7 | 4420 * For each file name in files[num_files]: |
4421 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4422 */ | |
4423 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4424 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4425 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4426 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4427 char_u **files) |
7 | 4428 { |
4429 int i; | |
4430 char_u *p; | |
4431 | |
4432 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4433 { | |
4434 for (i = 0; i < num_files; ++i) | |
4435 { | |
4436 p = home_replace_save(NULL, files[i]); | |
4437 if (p != NULL) | |
4438 { | |
4439 vim_free(files[i]); | |
4440 files[i] = p; | |
4441 } | |
4442 } | |
4443 } | |
4444 } | |
4445 | |
4446 /* | |
4447 * Show all matches for completion on the command line. | |
4448 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4449 * be inserted like a normal character. | |
4450 */ | |
4451 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4452 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4453 { |
4454 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4455 int num_files; | |
4456 char_u **files_found; | |
4457 int i, j, k; | |
4458 int maxlen; | |
4459 int lines; | |
4460 int columns; | |
4461 char_u *p; | |
4462 int lastlen; | |
4463 int attr; | |
4464 int showtail; | |
4465 | |
4466 if (xp->xp_numfiles == -1) | |
4467 { | |
4468 set_expand_context(xp); | |
4469 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4470 &num_files, &files_found); | |
4471 showtail = expand_showtail(xp); | |
4472 if (i != EXPAND_OK) | |
4473 return i; | |
4474 | |
4475 } | |
4476 else | |
4477 { | |
4478 num_files = xp->xp_numfiles; | |
4479 files_found = xp->xp_files; | |
4480 showtail = cmd_showtail; | |
4481 } | |
4482 | |
4483 #ifdef FEAT_WILDMENU | |
4484 if (!wildmenu) | |
4485 { | |
4486 #endif | |
4487 msg_didany = FALSE; /* lines_left will be set */ | |
4488 msg_start(); /* prepare for paging */ | |
4489 msg_putchar('\n'); | |
4490 out_flush(); | |
4491 cmdline_row = msg_row; | |
4492 msg_didany = FALSE; /* lines_left will be set again */ | |
4493 msg_start(); /* prepare for paging */ | |
4494 #ifdef FEAT_WILDMENU | |
4495 } | |
4496 #endif | |
4497 | |
4498 if (got_int) | |
4499 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4500 #ifdef FEAT_WILDMENU | |
4501 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
|
4502 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4503 #endif |
4504 else | |
4505 { | |
4506 /* find the length of the longest file name */ | |
4507 maxlen = 0; | |
4508 for (i = 0; i < num_files; ++i) | |
4509 { | |
4510 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4511 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4512 || xp->xp_context == EXPAND_BUFFERS)) |
4513 { | |
4514 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4515 j = vim_strsize(NameBuff); | |
4516 } | |
4517 else | |
4518 j = vim_strsize(L_SHOWFILE(i)); | |
4519 if (j > maxlen) | |
4520 maxlen = j; | |
4521 } | |
4522 | |
4523 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4524 lines = num_files; | |
4525 else | |
4526 { | |
4527 /* compute the number of columns and lines for the listing */ | |
4528 maxlen += 2; /* two spaces between file names */ | |
4529 columns = ((int)Columns + 2) / maxlen; | |
4530 if (columns < 1) | |
4531 columns = 1; | |
4532 lines = (num_files + columns - 1) / columns; | |
4533 } | |
4534 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4535 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4536 |
4537 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4538 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4539 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4540 msg_clr_eos(); |
4541 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
|
4542 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4543 } |
4544 | |
4545 /* list the files line by line */ | |
4546 for (i = 0; i < lines; ++i) | |
4547 { | |
4548 lastlen = 999; | |
4549 for (k = i; k < num_files; k += lines) | |
4550 { | |
4551 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4552 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4553 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4554 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4555 msg_advance(maxlen + 1); | |
4556 msg_puts(p); | |
4557 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
|
4558 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4559 break; |
4560 } | |
4561 for (j = maxlen - lastlen; --j >= 0; ) | |
4562 msg_putchar(' '); | |
4563 if (xp->xp_context == EXPAND_FILES | |
714 | 4564 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4565 || xp->xp_context == EXPAND_BUFFERS) |
4566 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4567 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4568 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4569 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4570 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4571 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4572 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4573 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4574 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4575 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4576 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
|
4577 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4578 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4579 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4580 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4581 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4582 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4583 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4584 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4585 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4586 j = mch_isdir(files_found[k]); |
7 | 4587 if (showtail) |
4588 p = L_SHOWFILE(k); | |
4589 else | |
4590 { | |
4591 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4592 TRUE); | |
4593 p = NameBuff; | |
4594 } | |
4595 } | |
4596 else | |
4597 { | |
4598 j = FALSE; | |
4599 p = L_SHOWFILE(k); | |
4600 } | |
4601 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4602 } | |
4603 if (msg_col > 0) /* when not wrapped around */ | |
4604 { | |
4605 msg_clr_eos(); | |
4606 msg_putchar('\n'); | |
4607 } | |
4608 out_flush(); /* show one line at a time */ | |
4609 if (got_int) | |
4610 { | |
4611 got_int = FALSE; | |
4612 break; | |
4613 } | |
4614 } | |
4615 | |
4616 /* | |
4617 * we redraw the command below the lines that we have just listed | |
4618 * This is a bit tricky, but it saves a lot of screen updating. | |
4619 */ | |
4620 cmdline_row = msg_row; /* will put it back later */ | |
4621 } | |
4622 | |
4623 if (xp->xp_numfiles == -1) | |
4624 FreeWild(num_files, files_found); | |
4625 | |
4626 return EXPAND_OK; | |
4627 } | |
4628 | |
4629 /* | |
4630 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4631 * Find tail of file name path, but ignore trailing "/". | |
4632 */ | |
4633 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4634 sm_gettail(char_u *s) |
7 | 4635 { |
4636 char_u *p; | |
4637 char_u *t = s; | |
4638 int had_sep = FALSE; | |
4639 | |
4640 for (p = s; *p != NUL; ) | |
4641 { | |
4642 if (vim_ispathsep(*p) | |
4643 #ifdef BACKSLASH_IN_FILENAME | |
4644 && !rem_backslash(p) | |
4645 #endif | |
4646 ) | |
4647 had_sep = TRUE; | |
4648 else if (had_sep) | |
4649 { | |
4650 t = p; | |
4651 had_sep = FALSE; | |
4652 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4653 MB_PTR_ADV(p); |
7 | 4654 } |
4655 return t; | |
4656 } | |
4657 | |
4658 /* | |
4659 * Return TRUE if we only need to show the tail of completion matches. | |
4660 * When not completing file names or there is a wildcard in the path FALSE is | |
4661 * returned. | |
4662 */ | |
4663 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4664 expand_showtail(expand_T *xp) |
7 | 4665 { |
4666 char_u *s; | |
4667 char_u *end; | |
4668 | |
4669 /* When not completing file names a "/" may mean something different. */ | |
714 | 4670 if (xp->xp_context != EXPAND_FILES |
4671 && xp->xp_context != EXPAND_SHELLCMD | |
4672 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4673 return FALSE; |
4674 | |
4675 end = gettail(xp->xp_pattern); | |
4676 if (end == xp->xp_pattern) /* there is no path separator */ | |
4677 return FALSE; | |
4678 | |
4679 for (s = xp->xp_pattern; s < end; s++) | |
4680 { | |
4681 /* Skip escaped wildcards. Only when the backslash is not a path | |
4682 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4683 if (rem_backslash(s)) | |
4684 ++s; | |
4685 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4686 return FALSE; | |
4687 } | |
4688 return TRUE; | |
4689 } | |
4690 | |
4691 /* | |
4692 * Prepare a string for expansion. | |
4693 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4694 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4695 * When expanding other names: The string will be used with regcomp(). Copy |
4696 * the name into allocated memory and prepend "^". | |
4697 */ | |
4698 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4699 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4700 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4701 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4702 int context) /* EXPAND_FILES etc. */ |
7 | 4703 { |
4704 char_u *retval; | |
4705 int i, j; | |
4706 int new_len; | |
4707 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4708 int ends_in_star; |
7 | 4709 |
714 | 4710 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4711 && context != EXPAND_FILES_IN_PATH |
714 | 4712 && context != EXPAND_SHELLCMD |
4713 && context != EXPAND_DIRECTORIES) | |
7 | 4714 { |
4715 /* | |
4716 * Matching will be done internally (on something other than files). | |
4717 * So we convert the file-matching-type wildcards into our kind for | |
4718 * use with vim_regcomp(). First work out how long it will be: | |
4719 */ | |
4720 | |
4721 /* For help tags the translation is done in find_help_tags(). | |
4722 * For a tag pattern starting with "/" no translation is needed. */ | |
4723 if (context == EXPAND_HELP | |
4724 || context == EXPAND_COLORS | |
4725 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4726 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4727 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4728 || 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
|
4729 || ((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
|
4730 || 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
|
4731 && fname[0] == '/')) |
7 | 4732 retval = vim_strnsave(fname, len); |
4733 else | |
4734 { | |
4735 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4736 for (i = 0; i < len; i++) | |
4737 { | |
4738 if (fname[i] == '*' || fname[i] == '~') | |
4739 new_len++; /* '*' needs to be replaced by ".*" | |
4740 '~' needs to be replaced by "\~" */ | |
4741 | |
4742 /* Buffer names are like file names. "." should be literal */ | |
4743 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4744 new_len++; /* "." becomes "\." */ | |
4745 | |
4746 /* Custom expansion takes care of special things, match | |
4747 * backslashes literally (perhaps also for other types?) */ | |
634 | 4748 if ((context == EXPAND_USER_DEFINED |
4749 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4750 new_len++; /* '\' becomes "\\" */ |
4751 } | |
4752 retval = alloc(new_len); | |
4753 if (retval != NULL) | |
4754 { | |
4755 retval[0] = '^'; | |
4756 j = 1; | |
4757 for (i = 0; i < len; i++, j++) | |
4758 { | |
4759 /* Skip backslash. But why? At least keep it for custom | |
4760 * expansion. */ | |
4761 if (context != EXPAND_USER_DEFINED | |
407 | 4762 && context != EXPAND_USER_LIST |
4763 && fname[i] == '\\' | |
4764 && ++i == len) | |
7 | 4765 break; |
4766 | |
4767 switch (fname[i]) | |
4768 { | |
4769 case '*': retval[j++] = '.'; | |
4770 break; | |
4771 case '~': retval[j++] = '\\'; | |
4772 break; | |
4773 case '?': retval[j] = '.'; | |
4774 continue; | |
4775 case '.': if (context == EXPAND_BUFFERS) | |
4776 retval[j++] = '\\'; | |
4777 break; | |
407 | 4778 case '\\': if (context == EXPAND_USER_DEFINED |
4779 || context == EXPAND_USER_LIST) | |
7 | 4780 retval[j++] = '\\'; |
4781 break; | |
4782 } | |
4783 retval[j] = fname[i]; | |
4784 } | |
4785 retval[j] = NUL; | |
4786 } | |
4787 } | |
4788 } | |
4789 else | |
4790 { | |
4791 retval = alloc(len + 4); | |
4792 if (retval != NULL) | |
4793 { | |
419 | 4794 vim_strncpy(retval, fname, len); |
7 | 4795 |
4796 /* | |
831 | 4797 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4798 * * would become **, which walks the whole tree. | |
7 | 4799 * ~ would be at the start of the file name, but not the tail. |
4800 * $ could be anywhere in the tail. | |
4801 * ` could be anywhere in the file name. | |
1484 | 4802 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4803 */ |
4804 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4805 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
|
4806 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4807 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4808 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4809 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4810 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4811 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4812 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4813 #endif |
7 | 4814 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4815 && !ends_in_star |
7 | 4816 && vim_strchr(tail, '$') == NULL |
4817 && vim_strchr(retval, '`') == NULL) | |
4818 retval[len++] = '*'; | |
1484 | 4819 else if (len > 0 && retval[len - 1] == '$') |
4820 --len; | |
7 | 4821 retval[len] = NUL; |
4822 } | |
4823 } | |
4824 return retval; | |
4825 } | |
4826 | |
4827 /* | |
4828 * Must parse the command line so far to work out what context we are in. | |
4829 * Completion can then be done based on that context. | |
4830 * This routine sets the variables: | |
4831 * xp->xp_pattern The start of the pattern to be expanded within | |
4832 * the command line (ends at the cursor). | |
4833 * xp->xp_context The type of thing to expand. Will be one of: | |
4834 * | |
4835 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4836 * the command line, like an unknown command. Caller | |
4837 * should beep. | |
4838 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4839 * a normal char, rather than for completion. eg | |
4840 * :s/^I/ | |
4841 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4842 * it. | |
4843 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4844 * EXPAND_FILES After command with XFILE set, or after setting | |
4845 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4846 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4847 * when we know only directories are of interest. eg | |
4848 * :set dir=^I | |
714 | 4849 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4850 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4851 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4852 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4853 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4854 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4855 * EXPAND_EVENTS Complete event names | |
4856 * EXPAND_SYNTAX Complete :syntax command arguments | |
4857 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4858 * EXPAND_AUGROUP Complete autocommand group names | |
4859 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4860 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4861 * eg :unmap a^I , :cunab x^I | |
4862 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4863 * eg :call sub^I | |
4864 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4865 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4866 * names in expressions, eg :while s^I | |
4867 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4868 * EXPAND_USER Complete user names |
7 | 4869 */ |
4870 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4871 set_expand_context(expand_T *xp) |
7 | 4872 { |
168 | 4873 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4874 if (ccline.cmdfirstc != ':' |
4875 #ifdef FEAT_EVAL | |
168 | 4876 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4877 && !ccline.input_fn |
7 | 4878 #endif |
4879 ) | |
4880 { | |
4881 xp->xp_context = EXPAND_NOTHING; | |
4882 return; | |
4883 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4884 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4885 } |
4886 | |
4887 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4888 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4889 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4890 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
|
4891 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
|
4892 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4893 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4894 { |
4895 int old_char = NUL; | |
4896 char_u *nextcomm; | |
4897 | |
4898 /* | |
4899 * Avoid a UMR warning from Purify, only save the character if it has been | |
4900 * written before. | |
4901 */ | |
4902 if (col < len) | |
4903 old_char = str[col]; | |
4904 str[col] = NUL; | |
4905 nextcomm = str; | |
168 | 4906 |
4907 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4908 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4909 { |
4910 # ifdef FEAT_CMDL_COMPL | |
168 | 4911 /* pass CMD_SIZE because there is no real command */ |
4912 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4913 # endif |
4914 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4915 else if (use_ccline && ccline.input_fn) |
531 | 4916 { |
4917 xp->xp_context = ccline.xp_context; | |
4918 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4919 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4920 xp->xp_arg = ccline.xp_arg; |
1322 | 4921 # endif |
531 | 4922 } |
168 | 4923 else |
4924 #endif | |
4925 while (nextcomm != NULL) | |
4926 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4927 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4928 /* 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
|
4929 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4930 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4931 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4932 |
7 | 4933 str[col] = old_char; |
4934 } | |
4935 | |
4936 /* | |
4937 * Expand the command line "str" from context "xp". | |
4938 * "xp" must have been set by set_cmd_context(). | |
4939 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4940 * starts. | |
4941 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4942 * cursor. | |
4943 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4944 * key that triggered expansion literally. | |
4945 * Returns EXPAND_OK otherwise. | |
4946 */ | |
4947 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4948 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4949 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4950 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
|
4951 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4952 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4953 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4954 { |
4955 char_u *file_str = NULL; | |
2652 | 4956 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4957 |
4958 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4959 { | |
4960 beep_flush(); | |
4961 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4962 } | |
4963 if (xp->xp_context == EXPAND_NOTHING) | |
4964 { | |
4965 /* Caller can use the character as a normal char instead */ | |
4966 return EXPAND_NOTHING; | |
4967 } | |
4968 | |
4969 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4970 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4971 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4972 if (file_str == NULL) |
4973 return EXPAND_UNSUCCESSFUL; | |
4974 | |
2652 | 4975 if (p_wic) |
4976 options += WILD_ICASE; | |
4977 | |
7 | 4978 /* find all files that match the description */ |
2652 | 4979 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4980 { |
4981 *matchcount = 0; | |
4982 *matches = NULL; | |
4983 } | |
4984 vim_free(file_str); | |
4985 | |
4986 return EXPAND_OK; | |
4987 } | |
4988 | |
4989 #ifdef FEAT_MULTI_LANG | |
4990 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4991 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4992 * 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
|
4993 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4994 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4995 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4996 |
4997 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4998 cleanup_help_tags(int num_file, char_u **file) |
7 | 4999 { |
5000 int i, j; | |
5001 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5002 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5003 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5004 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5005 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
|
5006 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5007 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5008 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5009 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5010 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5011 *p = NUL; |
7 | 5012 |
5013 for (i = 0; i < num_file; ++i) | |
5014 { | |
5015 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
|
5016 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5017 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5018 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5019 { |
5020 /* Sorting on priority means the same item in another language may | |
5021 * be anywhere. Search all items for a match up to the "@en". */ | |
5022 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
|
5023 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
|
5024 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5025 break; |
5026 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5027 /* item only exists with @en, remove it */ |
7 | 5028 file[i][len] = NUL; |
5029 } | |
5030 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5031 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5032 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5033 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
|
5034 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5035 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5036 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5037 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5038 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
|
5039 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5040 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5041 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5042 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5043 } |
7 | 5044 } |
5045 #endif | |
5046 | |
5047 /* | |
5048 * Do the expansion based on xp->xp_context and "pat". | |
5049 */ | |
5050 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5051 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5052 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5053 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5054 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5055 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5056 int options) /* EW_ flags */ |
7 | 5057 { |
5058 #ifdef FEAT_CMDL_COMPL | |
5059 regmatch_T regmatch; | |
5060 #endif | |
5061 int ret; | |
5062 int flags; | |
5063 | |
5064 flags = EW_DIR; /* include directories */ | |
5065 if (options & WILD_LIST_NOTFOUND) | |
5066 flags |= EW_NOTFOUND; | |
5067 if (options & WILD_ADD_SLASH) | |
5068 flags |= EW_ADDSLASH; | |
5069 if (options & WILD_KEEP_ALL) | |
5070 flags |= EW_KEEPALL; | |
5071 if (options & WILD_SILENT) | |
5072 flags |= EW_SILENT; | |
6659 | 5073 if (options & WILD_ALLLINKS) |
5074 flags |= EW_ALLLINKS; | |
7 | 5075 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5076 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5077 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5078 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5079 { |
5080 /* | |
5081 * Expand file or directory names. | |
5082 */ | |
5083 int free_pat = FALSE; | |
5084 int i; | |
5085 | |
5086 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5087 * space */ | |
5088 if (xp->xp_backslash != XP_BS_NONE) | |
5089 { | |
5090 free_pat = TRUE; | |
5091 pat = vim_strsave(pat); | |
5092 for (i = 0; pat[i]; ++i) | |
5093 if (pat[i] == '\\') | |
5094 { | |
5095 if (xp->xp_backslash == XP_BS_THREE | |
5096 && pat[i + 1] == '\\' | |
5097 && pat[i + 2] == '\\' | |
5098 && pat[i + 3] == ' ') | |
1621 | 5099 STRMOVE(pat + i, pat + i + 3); |
7 | 5100 if (xp->xp_backslash == XP_BS_ONE |
5101 && pat[i + 1] == ' ') | |
1621 | 5102 STRMOVE(pat + i, pat + i + 1); |
7 | 5103 } |
5104 } | |
5105 | |
5106 if (xp->xp_context == EXPAND_FILES) | |
5107 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5108 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
|
5109 flags |= (EW_FILE | EW_PATH); |
7 | 5110 else |
5111 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5112 if (options & WILD_ICASE) |
5113 flags |= EW_ICASE; | |
5114 | |
2016 | 5115 /* Expand wildcards, supporting %:h and the like. */ |
5116 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5117 if (free_pat) |
5118 vim_free(pat); | |
5119 return ret; | |
5120 } | |
5121 | |
5122 *file = (char_u **)""; | |
5123 *num_file = 0; | |
5124 if (xp->xp_context == EXPAND_HELP) | |
5125 { | |
1696 | 5126 /* With an empty argument we would get all the help tags, which is |
5127 * very slow. Get matches for "help" instead. */ | |
5128 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5129 num_file, file, FALSE) == OK) | |
7 | 5130 { |
5131 #ifdef FEAT_MULTI_LANG | |
5132 cleanup_help_tags(*num_file, *file); | |
5133 #endif | |
5134 return OK; | |
5135 } | |
5136 return FAIL; | |
5137 } | |
5138 | |
5139 #ifndef FEAT_CMDL_COMPL | |
5140 return FAIL; | |
5141 #else | |
716 | 5142 if (xp->xp_context == EXPAND_SHELLCMD) |
5143 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5144 if (xp->xp_context == EXPAND_OLD_SETTING) |
5145 return ExpandOldSetting(num_file, file); | |
5146 if (xp->xp_context == EXPAND_BUFFERS) | |
5147 return ExpandBufnames(pat, num_file, file, options); | |
5148 if (xp->xp_context == EXPAND_TAGS | |
5149 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5150 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5151 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5152 { |
5153 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5154 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
|
5155 directories); |
2929 | 5156 } |
7 | 5157 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5158 { |
3106 | 5159 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5160 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5161 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5162 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5163 { |
5164 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5165 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5166 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5167 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5168 { |
5169 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
|
5170 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5171 } |
407 | 5172 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5173 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5174 return ExpandUserList(xp, num_file, file); |
407 | 5175 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5176 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5177 return ExpandPackAddDir(pat, num_file, file); |
7 | 5178 |
5179 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5180 if (regmatch.regprog == NULL) | |
5181 return FAIL; | |
5182 | |
5183 /* set ignore-case according to p_ic, p_scs and pat */ | |
5184 regmatch.rm_ic = ignorecase(pat); | |
5185 | |
5186 if (xp->xp_context == EXPAND_SETTINGS | |
5187 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5188 ret = ExpandSettings(xp, ®match, num_file, file); | |
5189 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5190 ret = ExpandMappings(®match, num_file, file); | |
5191 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5192 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5193 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5194 # endif | |
5195 else | |
5196 { | |
5197 static struct expgen | |
5198 { | |
5199 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5200 char_u *((*func)(expand_T *, int)); |
7 | 5201 int ic; |
2849 | 5202 int escaped; |
7 | 5203 } tab[] = |
5204 { | |
2849 | 5205 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5206 {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
|
5207 {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
|
5208 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5209 #ifdef FEAT_CMDHIST |
5210 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5211 #endif | |
7 | 5212 #ifdef FEAT_USR_CMDS |
2849 | 5213 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5214 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5215 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5216 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5217 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5218 #endif |
5219 #ifdef FEAT_EVAL | |
2849 | 5220 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5221 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5222 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5223 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5224 #endif |
5225 #ifdef FEAT_MENU | |
2849 | 5226 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5227 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5228 #endif |
5229 #ifdef FEAT_SYN_HL | |
2849 | 5230 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5231 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5232 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5233 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5234 #endif |
2849 | 5235 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5236 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5237 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5238 #ifdef FEAT_CSCOPE |
2849 | 5239 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5240 #endif |
1868 | 5241 #ifdef FEAT_SIGNS |
2849 | 5242 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5243 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5244 #ifdef FEAT_PROFILE |
2849 | 5245 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5246 #endif |
7 | 5247 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5248 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5249 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5250 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5251 #endif | |
5252 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5253 {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
|
5254 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5255 }; |
5256 int i; | |
5257 | |
5258 /* | |
5259 * Find a context in the table and call the ExpandGeneric() with the | |
5260 * right function to do the expansion. | |
5261 */ | |
5262 ret = FAIL; | |
1880 | 5263 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5264 if (xp->xp_context == tab[i].context) |
5265 { | |
5266 if (tab[i].ic) | |
5267 regmatch.rm_ic = TRUE; | |
2849 | 5268 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5269 tab[i].func, tab[i].escaped); |
7 | 5270 break; |
5271 } | |
5272 } | |
5273 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5274 vim_regfree(regmatch.regprog); |
7 | 5275 |
5276 return ret; | |
5277 #endif /* FEAT_CMDL_COMPL */ | |
5278 } | |
5279 | |
5280 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5281 /* | |
5282 * Expand a list of names. | |
5283 * | |
5284 * Generic function for command line completion. It calls a function to | |
5285 * obtain strings, one by one. The strings are matched against a regexp | |
5286 * program. Matching strings are copied into an array, which is returned. | |
5287 * | |
5288 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5289 */ | |
5290 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5291 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5292 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5293 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5294 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5295 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5296 char_u *((*func)(expand_T *, int)), |
7 | 5297 /* 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
|
5298 int escaped) |
7 | 5299 { |
5300 int i; | |
5301 int count = 0; | |
480 | 5302 int round; |
7 | 5303 char_u *str; |
5304 | |
5305 /* do this loop twice: | |
480 | 5306 * round == 0: count the number of matching names |
5307 * round == 1: copy the matching names into allocated memory | |
7 | 5308 */ |
480 | 5309 for (round = 0; round <= 1; ++round) |
7 | 5310 { |
5311 for (i = 0; ; ++i) | |
5312 { | |
5313 str = (*func)(xp, i); | |
5314 if (str == NULL) /* end of list */ | |
5315 break; | |
5316 if (*str == NUL) /* skip empty strings */ | |
5317 continue; | |
5318 | |
5319 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5320 { | |
480 | 5321 if (round) |
7 | 5322 { |
2849 | 5323 if (escaped) |
5324 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5325 else | |
5326 str = vim_strsave(str); | |
7 | 5327 (*file)[count] = str; |
5328 #ifdef FEAT_MENU | |
5329 if (func == get_menu_names && str != NULL) | |
5330 { | |
5331 /* test for separator added by get_menu_names() */ | |
5332 str += STRLEN(str) - 1; | |
5333 if (*str == '\001') | |
5334 *str = '.'; | |
5335 } | |
5336 #endif | |
5337 } | |
5338 ++count; | |
5339 } | |
5340 } | |
480 | 5341 if (round == 0) |
7 | 5342 { |
5343 if (count == 0) | |
5344 return OK; | |
5345 *num_file = count; | |
5346 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5347 if (*file == NULL) | |
5348 { | |
5349 *file = (char_u **)""; | |
5350 return FAIL; | |
5351 } | |
5352 count = 0; | |
5353 } | |
5354 } | |
480 | 5355 |
828 | 5356 /* Sort the results. Keep menu's in the specified order. */ |
5357 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5358 { |
5359 if (xp->xp_context == EXPAND_EXPRESSION | |
5360 || xp->xp_context == EXPAND_FUNCTIONS | |
5361 || xp->xp_context == EXPAND_USER_FUNC) | |
5362 /* <SNR> functions should be sorted to the end. */ | |
5363 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5364 sort_func_compare); | |
5365 else | |
5366 sort_strings(*file, *num_file); | |
5367 } | |
480 | 5368 |
1322 | 5369 #ifdef FEAT_CMDL_COMPL |
5370 /* Reset the variables used for special highlight names expansion, so that | |
5371 * they don't show up when getting normal highlight names by ID. */ | |
5372 reset_expand_highlight(); | |
5373 #endif | |
5374 | |
7 | 5375 return OK; |
5376 } | |
5377 | |
716 | 5378 /* |
5379 * Complete a shell command. | |
5380 * Returns FAIL or OK; | |
5381 */ | |
5382 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5383 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5384 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
|
5385 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
|
5386 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
|
5387 int flagsarg) /* EW_ flags */ |
716 | 5388 { |
5389 char_u *pat; | |
5390 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5391 char_u *path = NULL; |
716 | 5392 int mustfree = FALSE; |
5393 garray_T ga; | |
5394 char_u *buf = alloc(MAXPATHL); | |
5395 size_t l; | |
5396 char_u *s, *e; | |
5397 int flags = flagsarg; | |
5398 int ret; | |
6695 | 5399 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5400 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5401 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5402 hash_T hash; |
716 | 5403 |
5404 if (buf == NULL) | |
5405 return FAIL; | |
5406 | |
5407 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5408 * space */ | |
5409 pat = vim_strsave(filepat); | |
5410 for (i = 0; pat[i]; ++i) | |
5411 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5412 STRMOVE(pat + i, pat + i + 1); |
716 | 5413 |
6695 | 5414 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5415 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5416 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
|
5417 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5418 path = (char_u *)"."; |
5419 else | |
2630 | 5420 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5421 /* 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
|
5422 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5423 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5424 if (path == NULL) |
5425 path = (char_u *)""; | |
5426 } | |
716 | 5427 |
5428 /* | |
5429 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5430 * collect them in "ga". When "." is not in $PATH also expand for the |
5431 * current directory, to find "subdir/cmd". | |
716 | 5432 */ |
5433 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
|
5434 hash_init(&found_ht); |
6695 | 5435 for (s = path; ; s = e) |
716 | 5436 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5437 #if defined(MSWIN) |
716 | 5438 e = vim_strchr(s, ';'); |
5439 #else | |
5440 e = vim_strchr(s, ':'); | |
5441 #endif | |
5442 if (e == NULL) | |
5443 e = s + STRLEN(s); | |
5444 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5445 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
|
5446 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5447 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
|
5448 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5449 // 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
|
5450 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
|
5451 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
|
5452 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5453 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
|
5454 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5455 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
|
5456 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
|
5457 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5458 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5459 // 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
|
5460 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
|
5461 |
716 | 5462 l = e - s; |
5463 if (l > MAXPATHL - 5) | |
5464 break; | |
5465 vim_strncpy(buf, s, l); | |
5466 add_pathsep(buf); | |
5467 l = STRLEN(buf); | |
5468 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5469 | |
5470 /* Expand matches in one directory of $PATH. */ | |
5471 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5472 if (ret == OK) | |
5473 { | |
5474 if (ga_grow(&ga, *num_file) == FAIL) | |
5475 FreeWild(*num_file, *file); | |
5476 else | |
5477 { | |
5478 for (i = 0; i < *num_file; ++i) | |
5479 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5480 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5481 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5482 if (STRLEN(name) > l) |
716 | 5483 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5484 // 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
|
5485 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5486 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
|
5487 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5488 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5489 // 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
|
5490 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5491 ((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
|
5492 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
|
5493 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5494 } |
716 | 5495 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5496 vim_free(name); |
716 | 5497 } |
5498 vim_free(*file); | |
5499 } | |
5500 } | |
5501 if (*e != NUL) | |
5502 ++e; | |
5503 } | |
5504 *file = ga.ga_data; | |
5505 *num_file = ga.ga_len; | |
5506 | |
5507 vim_free(buf); | |
5508 vim_free(pat); | |
5509 if (mustfree) | |
5510 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5511 hash_clear(&found_ht); |
716 | 5512 return OK; |
5513 } | |
5514 | |
5515 | |
7 | 5516 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5517 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5518 * 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
|
5519 * return the result (either a string or a List). |
7 | 5520 */ |
407 | 5521 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5522 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
|
5523 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
|
5524 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5525 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5526 char_u ***file) |
7 | 5527 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5528 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
|
5529 typval_T args[4]; |
7 | 5530 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
|
5531 char_u *pat = NULL; |
407 | 5532 void *ret; |
13 | 5533 struct cmdline_info save_ccline; |
7 | 5534 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5535 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5536 return NULL; |
7 | 5537 *num_file = 0; |
5538 *file = NULL; | |
5539 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5540 if (ccline.cmdbuff != NULL) |
1518 | 5541 { |
5542 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5543 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5544 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5545 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5546 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
|
5547 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5548 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
|
5549 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
|
5550 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
|
5551 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
|
5552 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
|
5553 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
|
5554 args[3].v_type = VAR_UNKNOWN; |
7 | 5555 |
13 | 5556 /* Save the cmdline, we don't know what the function may do. */ |
5557 save_ccline = ccline; | |
5558 ccline.cmdbuff = NULL; | |
5559 ccline.cmdprompt = NULL; | |
7 | 5560 current_SID = xp->xp_scriptID; |
13 | 5561 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5562 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5563 |
5564 ccline = save_ccline; | |
7 | 5565 current_SID = save_current_SID; |
1518 | 5566 if (ccline.cmdbuff != NULL) |
5567 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5568 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5569 vim_free(pat); |
407 | 5570 return ret; |
5571 } | |
5572 | |
5573 /* | |
5574 * Expand names with a function defined by the user. | |
5575 */ | |
5576 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5577 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5578 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5579 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5580 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5581 char_u ***file) |
407 | 5582 { |
5583 char_u *retstr; | |
5584 char_u *s; | |
5585 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
|
5586 int keep; |
407 | 5587 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
|
5588 int skip; |
407 | 5589 |
5590 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5591 if (retstr == NULL) | |
7 | 5592 return FAIL; |
5593 | |
5594 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5595 for (s = retstr; *s != NUL; s = e) |
7 | 5596 { |
5597 e = vim_strchr(s, '\n'); | |
5598 if (e == NULL) | |
5599 e = s + STRLEN(s); | |
5600 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
|
5601 *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
|
5602 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5603 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
|
5604 *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
|
5605 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5606 if (!skip) |
7 | 5607 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5608 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
|
5609 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5610 ((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
|
5611 ++ga.ga_len; |
7 | 5612 } |
5613 | |
5614 if (*e != NUL) | |
5615 ++e; | |
5616 } | |
407 | 5617 vim_free(retstr); |
5618 *file = ga.ga_data; | |
5619 *num_file = ga.ga_len; | |
5620 return OK; | |
5621 } | |
5622 | |
5623 /* | |
5624 * Expand names with a list returned by a function defined by the user. | |
5625 */ | |
5626 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5627 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5628 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5629 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5630 char_u ***file) |
407 | 5631 { |
5632 list_T *retlist; | |
5633 listitem_T *li; | |
5634 garray_T ga; | |
5635 | |
5636 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5637 if (retlist == NULL) | |
5638 return FAIL; | |
5639 | |
5640 ga_init2(&ga, (int)sizeof(char *), 3); | |
5641 /* Loop over the items in the list. */ | |
5642 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5643 { | |
1917 | 5644 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5645 continue; /* Skip non-string items and empty strings */ | |
407 | 5646 |
5647 if (ga_grow(&ga, 1) == FAIL) | |
5648 break; | |
5649 | |
5650 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5651 vim_strsave(li->li_tv.vval.v_string); |
407 | 5652 ++ga.ga_len; |
5653 } | |
5654 list_unref(retlist); | |
5655 | |
7 | 5656 *file = ga.ga_data; |
5657 *num_file = ga.ga_len; | |
5658 return OK; | |
5659 } | |
5660 #endif | |
5661 | |
5662 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5663 * 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
|
5664 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5665 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5666 * 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
|
5667 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5668 * 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
|
5669 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5670 * "dirnames" is an array with one or more directory names. |
7 | 5671 */ |
5672 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5673 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5674 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5675 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5676 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5677 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5678 char *dirnames[]) |
7 | 5679 { |
5680 char_u *s; | |
5681 char_u *e; | |
5873 | 5682 char_u *match; |
7 | 5683 garray_T ga; |
2929 | 5684 int i; |
5685 int pat_len; | |
7 | 5686 |
5687 *num_file = 0; | |
5688 *file = NULL; | |
2931 | 5689 pat_len = (int)STRLEN(pat); |
2929 | 5690 ga_init2(&ga, (int)sizeof(char *), 10); |
5691 | |
5692 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5693 { |
2929 | 5694 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5695 if (s == NULL) | |
5696 { | |
5697 ga_clear_strings(&ga); | |
5698 return FAIL; | |
5699 } | |
5700 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5701 globpath(p_rtp, s, &ga, 0); |
2929 | 5702 vim_free(s); |
5873 | 5703 } |
5704 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5705 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5706 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
|
5707 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5708 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
|
5709 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5711 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5712 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5713 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5714 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
|
5715 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5716 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5717 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5718 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5719 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5720 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5721 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
|
5722 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5723 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
|
5724 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5725 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5726 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5727 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5728 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5729 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
|
5730 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5731 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5732 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5733 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5734 |
5873 | 5735 for (i = 0; i < ga.ga_len; ++i) |
5736 { | |
5737 match = ((char_u **)ga.ga_data)[i]; | |
5738 s = match; | |
5739 e = s + STRLEN(s); | |
5740 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5741 { |
5873 | 5742 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5743 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5744 if (s < match || vim_ispathsep(*s)) |
5745 break; | |
5746 ++s; | |
5747 *e = NUL; | |
5748 mch_memmove(match, s, e - s + 1); | |
7 | 5749 } |
5750 } | |
5873 | 5751 |
2929 | 5752 if (ga.ga_len == 0) |
3628 | 5753 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5754 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5755 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5756 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5757 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5758 |
7 | 5759 *file = ga.ga_data; |
5760 *num_file = ga.ga_len; | |
5761 return OK; | |
5762 } | |
5763 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5764 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5765 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5766 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5767 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5768 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5769 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5770 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5771 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5772 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5773 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5774 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5775 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5776 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5777 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5778 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5779 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5780 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5781 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5782 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5783 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5784 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
|
5785 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5786 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5787 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5788 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5789 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5790 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5791 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5792 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
|
5793 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5794 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5795 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5796 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
|
5797 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5798 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
|
5799 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5800 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5801 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
|
5802 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5803 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5804 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5805 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5806 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5807 /* 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
|
5808 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5809 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5810 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5811 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5815 |
7 | 5816 #endif |
5817 | |
5818 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5819 /* | |
5820 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5821 * Adds the matches to "ga". Caller must init "ga". |
7 | 5822 */ |
5873 | 5823 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5824 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5825 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5826 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5827 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5828 int expand_options) |
7 | 5829 { |
5830 expand_T xpc; | |
5831 char_u *buf; | |
5832 int i; | |
5833 int num_p; | |
5834 char_u **p; | |
5835 | |
5836 buf = alloc(MAXPATHL); | |
5837 if (buf == NULL) | |
5873 | 5838 return; |
7 | 5839 |
632 | 5840 ExpandInit(&xpc); |
7 | 5841 xpc.xp_context = EXPAND_FILES; |
632 | 5842 |
7 | 5843 /* Loop over all entries in {path}. */ |
5844 while (*path != NUL) | |
5845 { | |
5846 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5847 copy_option_part(&path, buf, MAXPATHL, ","); | |
5848 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5849 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5850 # 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
|
5851 /* 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
|
5852 * 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
|
5853 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
|
5854 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5855 # else |
7 | 5856 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
|
5857 # endif |
7 | 5858 STRCAT(buf, file); |
1754 | 5859 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5860 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5861 { |
1754 | 5862 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5863 |
5864 if (ga_grow(ga, num_p) == OK) | |
7 | 5865 { |
5866 for (i = 0; i < num_p; ++i) | |
5867 { | |
5873 | 5868 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5869 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5870 ++ga->ga_len; |
7 | 5871 } |
5872 } | |
5873 | 5873 |
7 | 5874 FreeWild(num_p, p); |
5875 } | |
5876 } | |
5877 } | |
5878 | |
5879 vim_free(buf); | |
5880 } | |
5881 | |
5882 #endif | |
5883 | |
5884 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5885 | |
5886 /********************************* | |
5887 * Command line history stuff * | |
5888 *********************************/ | |
5889 | |
5890 /* | |
5891 * Translate a history character to the associated type number. | |
5892 */ | |
5893 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5894 hist_char2type(int c) |
7 | 5895 { |
5896 if (c == ':') | |
5897 return HIST_CMD; | |
5898 if (c == '=') | |
5899 return HIST_EXPR; | |
5900 if (c == '@') | |
5901 return HIST_INPUT; | |
5902 if (c == '>') | |
5903 return HIST_DEBUG; | |
5904 return HIST_SEARCH; /* must be '?' or '/' */ | |
5905 } | |
5906 | |
5907 /* | |
5908 * Table of history names. | |
5909 * These names are used in :history and various hist...() functions. | |
5910 * It is sufficient to give the significant prefix of a history name. | |
5911 */ | |
5912 | |
5913 static char *(history_names[]) = | |
5914 { | |
5915 "cmd", | |
5916 "search", | |
5917 "expr", | |
5918 "input", | |
5919 "debug", | |
5920 NULL | |
5921 }; | |
5922 | |
3503 | 5923 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5924 /* | |
5925 * Function given to ExpandGeneric() to obtain the possible first | |
5926 * arguments of the ":history command. | |
5927 */ | |
5928 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5929 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5930 { |
5931 static char_u compl[2] = { NUL, NUL }; | |
5932 char *short_names = ":=@>?/"; | |
3529 | 5933 int short_names_count = (int)STRLEN(short_names); |
3503 | 5934 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5935 | |
5936 if (idx < short_names_count) | |
5937 { | |
5938 compl[0] = (char_u)short_names[idx]; | |
5939 return compl; | |
5940 } | |
5941 if (idx < short_names_count + history_name_count) | |
5942 return (char_u *)history_names[idx - short_names_count]; | |
5943 if (idx == short_names_count + history_name_count) | |
5944 return (char_u *)"all"; | |
5945 return NULL; | |
5946 } | |
5947 #endif | |
5948 | |
7 | 5949 /* |
5950 * init_history() - Initialize the command line history. | |
5951 * Also used to re-allocate the history when the size changes. | |
5952 */ | |
356 | 5953 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5954 init_history(void) |
7 | 5955 { |
5956 int newlen; /* new length of history table */ | |
5957 histentry_T *temp; | |
5958 int i; | |
5959 int j; | |
5960 int type; | |
5961 | |
5962 /* | |
5963 * If size of history table changed, reallocate it | |
5964 */ | |
5965 newlen = (int)p_hi; | |
5966 if (newlen != hislen) /* history length changed */ | |
5967 { | |
5968 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5969 { | |
5970 if (newlen) | |
5971 { | |
5972 temp = (histentry_T *)lalloc( | |
5973 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5974 if (temp == NULL) /* out of memory! */ | |
5975 { | |
5976 if (type == 0) /* first one: just keep the old length */ | |
5977 { | |
5978 newlen = hislen; | |
5979 break; | |
5980 } | |
5981 /* Already changed one table, now we can only have zero | |
5982 * length for all tables. */ | |
5983 newlen = 0; | |
5984 type = -1; | |
5985 continue; | |
5986 } | |
5987 } | |
5988 else | |
5989 temp = NULL; | |
5990 if (newlen == 0 || temp != NULL) | |
5991 { | |
5992 if (hisidx[type] < 0) /* there are no entries yet */ | |
5993 { | |
5994 for (i = 0; i < newlen; ++i) | |
4258 | 5995 clear_hist_entry(&temp[i]); |
7 | 5996 } |
5997 else if (newlen > hislen) /* array becomes bigger */ | |
5998 { | |
5999 for (i = 0; i <= hisidx[type]; ++i) | |
6000 temp[i] = history[type][i]; | |
6001 j = i; | |
6002 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6003 clear_hist_entry(&temp[i]); |
7 | 6004 for ( ; j < hislen; ++i, ++j) |
6005 temp[i] = history[type][j]; | |
6006 } | |
6007 else /* array becomes smaller or 0 */ | |
6008 { | |
6009 j = hisidx[type]; | |
6010 for (i = newlen - 1; ; --i) | |
6011 { | |
6012 if (i >= 0) /* copy newest entries */ | |
6013 temp[i] = history[type][j]; | |
6014 else /* remove older entries */ | |
6015 vim_free(history[type][j].hisstr); | |
6016 if (--j < 0) | |
6017 j = hislen - 1; | |
6018 if (j == hisidx[type]) | |
6019 break; | |
6020 } | |
6021 hisidx[type] = newlen - 1; | |
6022 } | |
6023 vim_free(history[type]); | |
6024 history[type] = temp; | |
6025 } | |
6026 } | |
6027 hislen = newlen; | |
6028 } | |
6029 } | |
6030 | |
4258 | 6031 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6032 clear_hist_entry(histentry_T *hisptr) |
4258 | 6033 { |
6034 hisptr->hisnum = 0; | |
6035 hisptr->viminfo = FALSE; | |
6036 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6037 hisptr->time_set = 0; |
4258 | 6038 } |
6039 | |
7 | 6040 /* |
6041 * Check if command line 'str' is already in history. | |
6042 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6043 */ | |
6044 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6045 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6046 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6047 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6048 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
|
6049 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6050 int writing) /* ignore entries read from viminfo */ |
7 | 6051 { |
6052 int i; | |
6053 int last_i = -1; | |
2986 | 6054 char_u *p; |
7 | 6055 |
6056 if (hisidx[type] < 0) | |
6057 return FALSE; | |
6058 i = hisidx[type]; | |
6059 do | |
6060 { | |
6061 if (history[type][i].hisstr == NULL) | |
6062 return FALSE; | |
2986 | 6063 |
6064 /* For search history, check that the separator character matches as | |
6065 * well. */ | |
6066 p = history[type][i].hisstr; | |
6067 if (STRCMP(str, p) == 0 | |
4285 | 6068 && !(writing && history[type][i].viminfo) |
2986 | 6069 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6070 { |
6071 if (!move_to_front) | |
6072 return TRUE; | |
6073 last_i = i; | |
6074 break; | |
6075 } | |
6076 if (--i < 0) | |
6077 i = hislen - 1; | |
6078 } while (i != hisidx[type]); | |
6079 | |
6080 if (last_i >= 0) | |
6081 { | |
6082 str = history[type][i].hisstr; | |
6083 while (i != hisidx[type]) | |
6084 { | |
6085 if (++i >= hislen) | |
6086 i = 0; | |
6087 history[type][last_i] = history[type][i]; | |
6088 last_i = i; | |
6089 } | |
4258 | 6090 history[type][i].hisnum = ++hisnum[type]; |
6091 history[type][i].viminfo = FALSE; | |
7 | 6092 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6093 history[type][i].time_set = vim_time(); |
7 | 6094 return TRUE; |
6095 } | |
6096 return FALSE; | |
6097 } | |
6098 | |
6099 /* | |
6100 * Convert history name (from table above) to its HIST_ equivalent. | |
6101 * When "name" is empty, return "cmd" history. | |
6102 * Returns -1 for unknown history name. | |
6103 */ | |
6104 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6105 get_histtype(char_u *name) |
7 | 6106 { |
6107 int i; | |
6108 int len = (int)STRLEN(name); | |
6109 | |
6110 /* No argument: use current history. */ | |
6111 if (len == 0) | |
6112 return hist_char2type(ccline.cmdfirstc); | |
6113 | |
6114 for (i = 0; history_names[i] != NULL; ++i) | |
6115 if (STRNICMP(name, history_names[i], len) == 0) | |
6116 return i; | |
6117 | |
6118 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6119 return hist_char2type(name[0]); | |
6120 | |
6121 return -1; | |
6122 } | |
6123 | |
6124 static int last_maptick = -1; /* last seen maptick */ | |
6125 | |
6126 /* | |
6127 * Add the given string to the given history. If the string is already in the | |
6128 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6129 * values. | |
6130 */ | |
6131 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6132 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6133 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6134 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6135 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
|
6136 int sep) /* separator character used (search hist) */ |
7 | 6137 { |
6138 histentry_T *hisptr; | |
6139 int len; | |
6140 | |
6141 if (hislen == 0) /* no history */ | |
6142 return; | |
6143 | |
5467 | 6144 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6145 return; | |
6146 | |
7 | 6147 /* |
6148 * Searches inside the same mapping overwrite each other, so that only | |
6149 * the last line is kept. Be careful not to remove a line that was moved | |
6150 * down, only lines that were added. | |
6151 */ | |
6152 if (histype == HIST_SEARCH && in_map) | |
6153 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6154 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6155 { |
6156 /* Current line is from the same mapping, remove it */ | |
6157 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6158 vim_free(hisptr->hisstr); | |
4258 | 6159 clear_hist_entry(hisptr); |
7 | 6160 --hisnum[histype]; |
6161 if (--hisidx[HIST_SEARCH] < 0) | |
6162 hisidx[HIST_SEARCH] = hislen - 1; | |
6163 } | |
6164 last_maptick = -1; | |
6165 } | |
4285 | 6166 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6167 { |
6168 if (++hisidx[histype] == hislen) | |
6169 hisidx[histype] = 0; | |
6170 hisptr = &history[histype][hisidx[histype]]; | |
6171 vim_free(hisptr->hisstr); | |
6172 | |
6173 /* Store the separator after the NUL of the string. */ | |
835 | 6174 len = (int)STRLEN(new_entry); |
7 | 6175 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6176 if (hisptr->hisstr != NULL) | |
6177 hisptr->hisstr[len + 1] = sep; | |
6178 | |
6179 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6180 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6181 hisptr->time_set = vim_time(); |
7 | 6182 if (histype == HIST_SEARCH && in_map) |
6183 last_maptick = maptick; | |
6184 } | |
6185 } | |
6186 | |
6187 #if defined(FEAT_EVAL) || defined(PROTO) | |
6188 | |
6189 /* | |
6190 * Get identifier of newest history entry. | |
6191 * "histype" may be one of the HIST_ values. | |
6192 */ | |
6193 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6194 get_history_idx(int histype) |
7 | 6195 { |
6196 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6197 || hisidx[histype] < 0) | |
6198 return -1; | |
6199 | |
6200 return history[histype][hisidx[histype]].hisnum; | |
6201 } | |
6202 | |
531 | 6203 /* |
7 | 6204 * Calculate history index from a number: |
6205 * num > 0: seen as identifying number of a history entry | |
6206 * num < 0: relative position in history wrt newest entry | |
6207 * "histype" may be one of the HIST_ values. | |
6208 */ | |
6209 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6210 calc_hist_idx(int histype, int num) |
7 | 6211 { |
6212 int i; | |
6213 histentry_T *hist; | |
6214 int wrapped = FALSE; | |
6215 | |
6216 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6217 || (i = hisidx[histype]) < 0 || num == 0) | |
6218 return -1; | |
6219 | |
6220 hist = history[histype]; | |
6221 if (num > 0) | |
6222 { | |
6223 while (hist[i].hisnum > num) | |
6224 if (--i < 0) | |
6225 { | |
6226 if (wrapped) | |
6227 break; | |
6228 i += hislen; | |
6229 wrapped = TRUE; | |
6230 } | |
6231 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6232 return i; | |
6233 } | |
6234 else if (-num <= hislen) | |
6235 { | |
6236 i += num + 1; | |
6237 if (i < 0) | |
6238 i += hislen; | |
6239 if (hist[i].hisstr != NULL) | |
6240 return i; | |
6241 } | |
6242 return -1; | |
6243 } | |
6244 | |
6245 /* | |
6246 * Get a history entry by its index. | |
6247 * "histype" may be one of the HIST_ values. | |
6248 */ | |
6249 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6250 get_history_entry(int histype, int idx) |
7 | 6251 { |
6252 idx = calc_hist_idx(histype, idx); | |
6253 if (idx >= 0) | |
6254 return history[histype][idx].hisstr; | |
6255 else | |
6256 return (char_u *)""; | |
6257 } | |
6258 | |
6259 /* | |
6260 * Clear all entries of a history. | |
6261 * "histype" may be one of the HIST_ values. | |
6262 */ | |
6263 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6264 clr_history(int histype) |
7 | 6265 { |
6266 int i; | |
6267 histentry_T *hisptr; | |
6268 | |
6269 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6270 { | |
6271 hisptr = history[histype]; | |
6272 for (i = hislen; i--;) | |
6273 { | |
6274 vim_free(hisptr->hisstr); | |
4258 | 6275 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6276 hisptr++; |
7 | 6277 } |
6278 hisidx[histype] = -1; /* mark history as cleared */ | |
6279 hisnum[histype] = 0; /* reset identifier counter */ | |
6280 return OK; | |
6281 } | |
6282 return FAIL; | |
6283 } | |
6284 | |
6285 /* | |
6286 * Remove all entries matching {str} from a history. | |
6287 * "histype" may be one of the HIST_ values. | |
6288 */ | |
6289 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6290 del_history_entry(int histype, char_u *str) |
7 | 6291 { |
6292 regmatch_T regmatch; | |
6293 histentry_T *hisptr; | |
6294 int idx; | |
6295 int i; | |
6296 int last; | |
6297 int found = FALSE; | |
6298 | |
6299 regmatch.regprog = NULL; | |
6300 regmatch.rm_ic = FALSE; /* always match case */ | |
6301 if (hislen != 0 | |
6302 && histype >= 0 | |
6303 && histype < HIST_COUNT | |
6304 && *str != NUL | |
6305 && (idx = hisidx[histype]) >= 0 | |
6306 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6307 != NULL) | |
6308 { | |
6309 i = last = idx; | |
6310 do | |
6311 { | |
6312 hisptr = &history[histype][i]; | |
6313 if (hisptr->hisstr == NULL) | |
6314 break; | |
6315 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6316 { | |
6317 found = TRUE; | |
6318 vim_free(hisptr->hisstr); | |
4258 | 6319 clear_hist_entry(hisptr); |
7 | 6320 } |
6321 else | |
6322 { | |
6323 if (i != last) | |
6324 { | |
6325 history[histype][last] = *hisptr; | |
4258 | 6326 clear_hist_entry(hisptr); |
7 | 6327 } |
6328 if (--last < 0) | |
6329 last += hislen; | |
6330 } | |
6331 if (--i < 0) | |
6332 i += hislen; | |
6333 } while (i != idx); | |
6334 if (history[histype][idx].hisstr == NULL) | |
6335 hisidx[histype] = -1; | |
6336 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6337 vim_regfree(regmatch.regprog); |
7 | 6338 return found; |
6339 } | |
6340 | |
6341 /* | |
6342 * Remove an indexed entry from a history. | |
6343 * "histype" may be one of the HIST_ values. | |
6344 */ | |
6345 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6346 del_history_idx(int histype, int idx) |
7 | 6347 { |
6348 int i, j; | |
6349 | |
6350 i = calc_hist_idx(histype, idx); | |
6351 if (i < 0) | |
6352 return FALSE; | |
6353 idx = hisidx[histype]; | |
6354 vim_free(history[histype][i].hisstr); | |
6355 | |
6356 /* When deleting the last added search string in a mapping, reset | |
6357 * last_maptick, so that the last added search string isn't deleted again. | |
6358 */ | |
6359 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6360 last_maptick = -1; | |
6361 | |
6362 while (i != idx) | |
6363 { | |
6364 j = (i + 1) % hislen; | |
6365 history[histype][i] = history[histype][j]; | |
6366 i = j; | |
6367 } | |
4258 | 6368 clear_hist_entry(&history[histype][i]); |
7 | 6369 if (--i < 0) |
6370 i += hislen; | |
6371 hisidx[histype] = i; | |
6372 return TRUE; | |
6373 } | |
6374 | |
6375 #endif /* FEAT_EVAL */ | |
6376 | |
6377 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6378 /* | |
6379 * Very specific function to remove the value in ":set key=val" from the | |
6380 * history. | |
6381 */ | |
6382 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6383 remove_key_from_history(void) |
7 | 6384 { |
6385 char_u *p; | |
6386 int i; | |
6387 | |
6388 i = hisidx[HIST_CMD]; | |
6389 if (i < 0) | |
6390 return; | |
6391 p = history[HIST_CMD][i].hisstr; | |
6392 if (p != NULL) | |
6393 for ( ; *p; ++p) | |
6394 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6395 { | |
6396 p = vim_strchr(p + 3, '='); | |
6397 if (p == NULL) | |
6398 break; | |
6399 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6400 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6401 if (p[i] == '\\' && p[i + 1]) |
6402 ++i; | |
1621 | 6403 STRMOVE(p, p + i); |
7 | 6404 --p; |
6405 } | |
6406 } | |
6407 #endif | |
6408 | |
6409 #endif /* FEAT_CMDHIST */ | |
6410 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6411 #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
|
6412 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6413 * 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
|
6414 * 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
|
6415 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6416 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6423 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
|
6424 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6427 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6428 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6429 #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
|
6430 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 * 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
|
6432 * 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
|
6433 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6434 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6436 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6437 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 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
|
6439 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6440 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6441 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 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
|
6443 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6446 * 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
|
6447 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6448 * 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
|
6449 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6450 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6453 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 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
|
6455 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6456 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6457 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 * 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
|
6463 * 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
|
6464 * 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
|
6465 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 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
|
6471 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6472 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6475 /* 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
|
6476 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6478 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 #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
|
6486 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6487 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6488 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6489 * 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
|
6490 * Returns NUL when something is wrong. |
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 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6495 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
|
6496 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6498 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6500 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6501 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6502 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6503 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6504 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 return p->cmdfirstc; |
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 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 |
7 | 6509 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6510 /* | |
6511 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6512 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6513 * Returns OK if parsed successfully, otherwise FAIL. | |
6514 */ | |
6515 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6516 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6517 { |
6518 int len; | |
6519 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6520 varnumber_T num; |
7 | 6521 |
6522 *str = skipwhite(*str); | |
6523 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6524 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6525 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6526 *str += len; |
6527 *num1 = (int)num; | |
6528 first = TRUE; | |
6529 } | |
6530 *str = skipwhite(*str); | |
6531 if (**str == ',') /* parse "to" part of range */ | |
6532 { | |
6533 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6534 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6535 if (len > 0) |
6536 { | |
6537 *num2 = (int)num; | |
6538 *str = skipwhite(*str + len); | |
6539 } | |
6540 else if (!first) /* no number given at all */ | |
6541 return FAIL; | |
6542 } | |
6543 else if (first) /* only one number given */ | |
6544 *num2 = *num1; | |
6545 return OK; | |
6546 } | |
6547 #endif | |
6548 | |
6549 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6550 /* | |
6551 * :history command - print a history | |
6552 */ | |
6553 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6554 ex_history(exarg_T *eap) |
7 | 6555 { |
6556 histentry_T *hist; | |
6557 int histype1 = HIST_CMD; | |
6558 int histype2 = HIST_CMD; | |
6559 int hisidx1 = 1; | |
6560 int hisidx2 = -1; | |
6561 int idx; | |
6562 int i, j, k; | |
6563 char_u *end; | |
6564 char_u *arg = eap->arg; | |
6565 | |
6566 if (hislen == 0) | |
6567 { | |
6568 MSG(_("'history' option is zero")); | |
6569 return; | |
6570 } | |
6571 | |
6572 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6573 { | |
6574 end = arg; | |
6575 while (ASCII_ISALPHA(*end) | |
6576 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6577 end++; | |
6578 i = *end; | |
6579 *end = NUL; | |
6580 histype1 = get_histtype(arg); | |
6581 if (histype1 == -1) | |
6582 { | |
1853 | 6583 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6584 { |
6585 histype1 = 0; | |
6586 histype2 = HIST_COUNT-1; | |
6587 } | |
6588 else | |
6589 { | |
6590 *end = i; | |
6591 EMSG(_(e_trailing)); | |
6592 return; | |
6593 } | |
6594 } | |
6595 else | |
6596 histype2 = histype1; | |
6597 *end = i; | |
6598 } | |
6599 else | |
6600 end = arg; | |
6601 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6602 { | |
6603 EMSG(_(e_trailing)); | |
6604 return; | |
6605 } | |
6606 | |
6607 for (; !got_int && histype1 <= histype2; ++histype1) | |
6608 { | |
6609 STRCPY(IObuff, "\n # "); | |
6610 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6611 MSG_PUTS_TITLE(IObuff); | |
6612 idx = hisidx[histype1]; | |
6613 hist = history[histype1]; | |
6614 j = hisidx1; | |
6615 k = hisidx2; | |
6616 if (j < 0) | |
6617 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6618 if (k < 0) | |
6619 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6620 if (idx >= 0 && j <= k) | |
6621 for (i = idx + 1; !got_int; ++i) | |
6622 { | |
6623 if (i == hislen) | |
6624 i = 0; | |
6625 if (hist[i].hisstr != NULL | |
6626 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6627 { | |
6628 msg_putchar('\n'); | |
6629 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6630 hist[i].hisnum); | |
6631 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6632 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6633 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6634 else |
6635 STRCAT(IObuff, hist[i].hisstr); | |
6636 msg_outtrans(IObuff); | |
6637 out_flush(); | |
6638 } | |
6639 if (i == idx) | |
6640 break; | |
6641 } | |
6642 } | |
6643 } | |
6644 #endif | |
6645 | |
6646 #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
|
6647 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6648 * 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
|
6649 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6650 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
|
6651 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6652 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
|
6653 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6654 static int viminfo_add_at_front = FALSE; |
6655 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6656 static int hist_type2char(int type, int use_question); |
7 | 6657 |
6658 /* | |
6659 * Translate a history type number to the associated character. | |
6660 */ | |
6661 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6662 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6663 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6664 int use_question) /* use '?' instead of '/' */ |
7 | 6665 { |
6666 if (type == HIST_CMD) | |
6667 return ':'; | |
6668 if (type == HIST_SEARCH) | |
6669 { | |
6670 if (use_question) | |
6671 return '?'; | |
6672 else | |
6673 return '/'; | |
6674 } | |
6675 if (type == HIST_EXPR) | |
6676 return '='; | |
6677 return '@'; | |
6678 } | |
6679 | |
6680 /* | |
6681 * Prepare for reading the history from the viminfo file. | |
6682 * This allocates history arrays to store the read history lines. | |
6683 */ | |
6684 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6685 prepare_viminfo_history(int asklen, int writing) |
7 | 6686 { |
6687 int i; | |
6688 int num; | |
6689 int type; | |
6690 int len; | |
6691 | |
6692 init_history(); | |
4285 | 6693 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6694 if (asklen > hislen) |
6695 asklen = hislen; | |
6696 | |
6697 for (type = 0; type < HIST_COUNT; ++type) | |
6698 { | |
4258 | 6699 /* Count the number of empty spaces in the history list. Entries read |
6700 * from viminfo previously are also considered empty. If there are | |
6701 * more spaces available than we request, then fill them up. */ | |
7 | 6702 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6703 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6704 num++; |
6705 len = asklen; | |
6706 if (num > len) | |
6707 len = num; | |
6708 if (len <= 0) | |
6709 viminfo_history[type] = NULL; | |
6710 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6711 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6712 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6713 if (viminfo_history[type] == NULL) |
6714 len = 0; | |
6715 viminfo_hislen[type] = len; | |
6716 viminfo_hisidx[type] = 0; | |
6717 } | |
6718 } | |
6719 | |
6720 /* | |
6721 * Accept a line from the viminfo, store it in the history array when it's | |
6722 * new. | |
6723 */ | |
6724 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6725 read_viminfo_history(vir_T *virp, int writing) |
7 | 6726 { |
6727 int type; | |
6728 long_u len; | |
6729 char_u *val; | |
6730 char_u *p; | |
6731 | |
6732 type = hist_char2type(virp->vir_line[0]); | |
6733 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6734 { | |
6735 val = viminfo_readstring(virp, 1, TRUE); | |
6736 if (val != NULL && *val != NUL) | |
6737 { | |
3316 | 6738 int sep = (*val == ' ' ? NUL : *val); |
6739 | |
7 | 6740 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6741 viminfo_add_at_front, sep, writing)) |
7 | 6742 { |
6743 /* Need to re-allocate to append the separator byte. */ | |
6744 len = STRLEN(val); | |
6745 p = lalloc(len + 2, TRUE); | |
6746 if (p != NULL) | |
6747 { | |
6748 if (type == HIST_SEARCH) | |
6749 { | |
6750 /* Search entry: Move the separator from the first | |
6751 * column to after the NUL. */ | |
6752 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6753 p[len] = sep; |
7 | 6754 } |
6755 else | |
6756 { | |
6757 /* Not a search entry: No separator in the viminfo | |
6758 * file, add a NUL separator. */ | |
6759 mch_memmove(p, val, (size_t)len + 1); | |
6760 p[len + 1] = NUL; | |
6761 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 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
|
6763 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
|
6764 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
|
6765 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
|
6766 viminfo_hisidx[type]++; |
7 | 6767 } |
6768 } | |
6769 } | |
6770 vim_free(val); | |
6771 } | |
6772 return viminfo_readline(virp); | |
6773 } | |
6774 | |
4285 | 6775 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6776 * 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
|
6777 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6778 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6779 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6780 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6781 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6782 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6785 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6788 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
|
6789 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6790 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6792 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6793 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6794 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6795 || (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
|
6796 || 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
|
6797 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6798 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6799 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6800 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6801 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6802 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
|
6803 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6804 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6805 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6806 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6807 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
|
6808 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 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
|
6813 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 /* 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
|
6815 * 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
|
6816 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
|
6817 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6819 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6820 && (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
|
6821 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6823 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6824 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 /* 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
|
6830 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6831 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6832 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6833 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6834 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6837 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
|
6838 if (!overwrite) |
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 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
|
6841 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6842 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6843 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
|
6844 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 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
|
6846 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 } |
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 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 * 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
|
6856 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6858 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6866 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6868 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6869 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6872 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6873 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6874 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6875 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6877 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6879 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6881 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 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
|
6886 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6888 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
|
6889 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 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
|
6891 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 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
|
6897 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 #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
|
6904 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 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
|
6909 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 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
|
6914 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
|
6915 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 * 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
|
6921 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 /* 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
|
6933 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 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
|
6935 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
|
6936 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
|
6937 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 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
|
6943 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
|
6944 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 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
|
6951 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 for (i = 0; i < hislen; i++) |
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 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6958 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 new_hist[i].hisnum = ++hisnum[type]; |
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 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6965 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
|
6966 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6968 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
|
6969 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
|
6970 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6974 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 /* |
4285 | 6978 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6979 */ | |
7 | 6980 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 finish_viminfo_history(vir_T *virp) |
7 | 6982 { |
6983 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6984 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6985 |
6986 for (type = 0; type < HIST_COUNT; ++type) | |
6987 { | |
6988 if (history[type] == NULL) | |
4283 | 6989 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6990 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6991 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 merge_history(type); |
7 | 6993 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6996 VIM_CLEAR(viminfo_history[type]); |
4327 | 6997 viminfo_hisidx[type] = 0; |
7 | 6998 } |
6999 } | |
7000 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7001 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7002 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7003 * 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
|
7004 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7005 * 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
|
7006 */ |
7 | 7007 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7008 write_viminfo_history(FILE *fp, int merge) |
7 | 7009 { |
7010 int i; | |
7011 int type; | |
7012 int num_saved; | |
4283 | 7013 int round; |
7 | 7014 |
7015 init_history(); | |
7016 if (hislen == 0) | |
7017 return; | |
7018 for (type = 0; type < HIST_COUNT; ++type) | |
7019 { | |
7020 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7021 if (num_saved == 0) | |
7022 continue; | |
7023 if (num_saved < 0) /* Use default */ | |
7024 num_saved = hislen; | |
7025 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7026 type == HIST_CMD ? _("Command Line") : | |
7027 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7028 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7029 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7030 _("Debug Line")); |
7 | 7031 if (num_saved > hislen) |
7032 num_saved = hislen; | |
4283 | 7033 |
7034 /* | |
7035 * Merge typed and viminfo history: | |
7036 * round 1: history of typed commands. | |
7037 * round 2: history from recently read viminfo. | |
7038 */ | |
7039 for (round = 1; round <= 2; ++round) | |
7040 { | |
4307 | 7041 if (round == 1) |
7042 /* start at newest entry, somewhere in the list */ | |
7043 i = hisidx[type]; | |
7044 else if (viminfo_hisidx[type] > 0) | |
7045 /* start at newest entry, first in the list */ | |
7046 i = 0; | |
7047 else | |
7048 /* empty list */ | |
7049 i = -1; | |
4283 | 7050 if (i >= 0) |
7051 while (num_saved > 0 | |
7052 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7053 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7054 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7055 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7056 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7057 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7058 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7059 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7060 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7061 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7062 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7063 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7064 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7065 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7066 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7067 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7068 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7069 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7070 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7071 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7072 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7073 || !history[type][i].viminfo)) |
7 | 7074 { |
4283 | 7075 --num_saved; |
7076 fputc(hist_type2char(type, TRUE), fp); | |
7077 /* For the search history: put the separator in the | |
7078 * second column; use a space if there isn't one. */ | |
7079 if (type == HIST_SEARCH) | |
7080 { | |
7081 c = p[STRLEN(p) + 1]; | |
7082 putc(c == NUL ? ' ' : c, fp); | |
7083 } | |
7084 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7085 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7086 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7087 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7088 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7089 /* 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
|
7090 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7091 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7092 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7093 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7094 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7095 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
|
7096 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7097 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7098 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7099 } |
7 | 7100 } |
4283 | 7101 if (round == 1) |
7102 { | |
7103 /* Decrement index, loop around and stop when back at | |
7104 * the start. */ | |
7105 if (--i < 0) | |
7106 i = hislen - 1; | |
7107 if (i == hisidx[type]) | |
7108 break; | |
7109 } | |
7110 else | |
7111 { | |
7112 /* Increment index. Stop at the end in the while. */ | |
7113 ++i; | |
7114 } | |
7 | 7115 } |
4283 | 7116 } |
4285 | 7117 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7118 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7119 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
|
7120 VIM_CLEAR(viminfo_history[type]); |
4311 | 7121 viminfo_hisidx[type] = 0; |
7 | 7122 } |
7123 } | |
7124 #endif /* FEAT_VIMINFO */ | |
7125 | |
7126 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7127 /* | |
7128 * Write a character at the current cursor+offset position. | |
7129 * It is directly written into the command buffer block. | |
7130 */ | |
7131 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7132 cmd_pchar(int c, int offset) |
7 | 7133 { |
7134 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7135 { | |
7136 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7137 return; | |
7138 } | |
7139 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7140 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7141 } | |
7142 | |
7143 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7144 cmd_gchar(int offset) |
7 | 7145 { |
7146 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7147 { | |
7148 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7149 return NUL; | |
7150 } | |
7151 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7152 } | |
7153 #endif | |
7154 | |
7155 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7156 /* | |
7157 * Open a window on the current command line and history. Allow editing in | |
7158 * the window. Returns when the window is closed. | |
7159 * Returns: | |
7160 * CR if the command is to be executed | |
7161 * Ctrl_C if it is to be abandoned | |
7162 * K_IGNORE if editing continues | |
7163 */ | |
7164 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
|
7165 open_cmdwin(void) |
7 | 7166 { |
7167 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7168 bufref_T old_curbuf; |
7 | 7169 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7170 bufref_T bufref; |
7 | 7171 win_T *wp; |
7172 int i; | |
7173 linenr_T lnum; | |
7174 int histtype; | |
7175 garray_T winsizes; | |
7176 int save_restart_edit = restart_edit; | |
7177 int save_State = State; | |
7178 int save_exmode = exmode_active; | |
510 | 7179 #ifdef FEAT_RIGHTLEFT |
7180 int save_cmdmsg_rl = cmdmsg_rl; | |
7181 #endif | |
6145 | 7182 #ifdef FEAT_FOLDING |
7183 int save_KeyTyped; | |
7184 #endif | |
7 | 7185 |
7186 /* Can't do this recursively. Can't do it when typing a password. */ | |
7187 if (cmdwin_type != 0 | |
7188 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7189 || cmdline_star > 0 | |
7190 # endif | |
7191 ) | |
7192 { | |
7193 beep_flush(); | |
7194 return K_IGNORE; | |
7195 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7196 set_bufref(&old_curbuf, curbuf); |
7 | 7197 |
7198 /* Save current window sizes. */ | |
7199 win_size_save(&winsizes); | |
7200 | |
7201 /* Don't execute autocommands while creating the window. */ | |
1410 | 7202 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7203 |
683 | 7204 /* don't use a new tab page */ |
7205 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
|
7206 cmdmod.noswapfile = 1; |
683 | 7207 |
7 | 7208 /* Create a window for the command-line buffer. */ |
7209 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7210 { | |
7211 beep_flush(); | |
1410 | 7212 unblock_autocmds(); |
7 | 7213 return K_IGNORE; |
7214 } | |
1831 | 7215 cmdwin_type = get_cmdline_type(); |
7 | 7216 |
7217 /* Create the command-line buffer empty. */ | |
1743 | 7218 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7219 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7220 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7221 curbuf->b_p_ma = TRUE; | |
1865 | 7222 #ifdef FEAT_FOLDING |
7223 curwin->w_p_fen = FALSE; | |
7224 #endif | |
7 | 7225 # ifdef FEAT_RIGHTLEFT |
510 | 7226 curwin->w_p_rl = cmdmsg_rl; |
7227 cmdmsg_rl = FALSE; | |
7 | 7228 # endif |
2583 | 7229 RESET_BINDING(curwin); |
7 | 7230 |
7231 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7232 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7233 /* 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
|
7234 ++curbuf_lock; |
7 | 7235 |
510 | 7236 /* Showing the prompt may have set need_wait_return, reset it. */ |
7237 need_wait_return = FALSE; | |
7238 | |
1831 | 7239 histtype = hist_char2type(cmdwin_type); |
7 | 7240 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7241 { | |
7242 if (p_wc == TAB) | |
7243 { | |
7244 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7245 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7246 } | |
7247 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7248 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7249 --curbuf_lock; |
7 | 7250 |
10 | 7251 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7252 * sets 'textwidth' to 78). */ | |
7253 curbuf->b_p_tw = 0; | |
7254 | |
7 | 7255 /* Fill the buffer with the history. */ |
7256 init_history(); | |
7257 if (hislen > 0) | |
7258 { | |
7259 i = hisidx[histtype]; | |
7260 if (i >= 0) | |
7261 { | |
7262 lnum = 0; | |
7263 do | |
7264 { | |
7265 if (++i == hislen) | |
7266 i = 0; | |
7267 if (history[histtype][i].hisstr != NULL) | |
7268 ml_append(lnum++, history[histtype][i].hisstr, | |
7269 (colnr_T)0, FALSE); | |
7270 } | |
7271 while (i != hisidx[histtype]); | |
7272 } | |
7273 } | |
7274 | |
7275 /* Replace the empty last line with the current command-line and put the | |
7276 * cursor there. */ | |
7277 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7278 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7279 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7280 changed_line_abv_curs(); |
7281 invalidate_botline(); | |
743 | 7282 redraw_later(SOME_VALID); |
7 | 7283 |
7284 /* 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
|
7285 save_cmdline(&save_ccline); |
7 | 7286 |
7287 /* No Ex mode here! */ | |
7288 exmode_active = 0; | |
7289 | |
7290 State = NORMAL; | |
7291 # ifdef FEAT_MOUSE | |
7292 setmouse(); | |
7293 # endif | |
7294 | |
7295 /* 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
|
7296 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7297 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7298 stuffcharReadbuff(K_NOP); | |
7 | 7299 |
7300 i = RedrawingDisabled; | |
7301 RedrawingDisabled = 0; | |
7302 | |
7303 /* | |
7304 * Call the main loop until <CR> or CTRL-C is typed. | |
7305 */ | |
7306 cmdwin_result = 0; | |
168 | 7307 main_loop(TRUE, FALSE); |
7 | 7308 |
7309 RedrawingDisabled = i; | |
7310 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7311 # ifdef FEAT_FOLDING |
6145 | 7312 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7313 # endif |
6145 | 7314 |
7 | 7315 /* 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
|
7316 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7317 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7318 # ifdef FEAT_FOLDING |
6145 | 7319 /* Restore KeyTyped in case it is modified by autocommands */ |
7320 KeyTyped = save_KeyTyped; | |
7 | 7321 # endif |
7322 | |
1214 | 7323 /* 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
|
7324 restore_cmdline(&save_ccline); |
7 | 7325 cmdwin_type = 0; |
7326 | |
7327 exmode_active = save_exmode; | |
7328 | |
1612 | 7329 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7330 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7331 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7332 { |
7333 cmdwin_result = Ctrl_C; | |
7334 EMSG(_("E199: Active window or buffer deleted")); | |
7335 } | |
7336 else | |
7337 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7338 # if defined(FEAT_EVAL) |
7 | 7339 /* autocmds may abort script processing */ |
7340 if (aborting() && cmdwin_result != K_IGNORE) | |
7341 cmdwin_result = Ctrl_C; | |
7342 # endif | |
7343 /* Set the new command line from the cmdline buffer. */ | |
7344 vim_free(ccline.cmdbuff); | |
510 | 7345 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7346 { |
510 | 7347 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7348 | |
7349 if (histtype == HIST_CMD) | |
7350 { | |
7351 /* Execute the command directly. */ | |
7352 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7353 cmdwin_result = CAR; | |
7354 } | |
7355 else | |
7356 { | |
7357 /* First need to cancel what we were doing. */ | |
7358 ccline.cmdbuff = NULL; | |
7359 stuffcharReadbuff(':'); | |
7360 stuffReadbuff((char_u *)p); | |
7361 stuffcharReadbuff(CAR); | |
7362 } | |
7 | 7363 } |
7364 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7365 { | |
7366 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7367 cmdwin_result = CAR; | |
7368 } | |
2839 | 7369 else if (cmdwin_result == Ctrl_C) |
7370 { | |
7371 /* :q or :close, don't execute any command | |
7372 * and don't modify the cmd window. */ | |
7373 ccline.cmdbuff = NULL; | |
7374 } | |
7 | 7375 else |
7376 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7377 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
|
7378 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7379 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
|
7380 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
|
7381 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
|
7382 ccline.cmdpos = 0; |
7 | 7383 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
|
7384 } |
7 | 7385 else |
7386 { | |
7387 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7388 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7389 ccline.cmdpos = curwin->w_cursor.col; | |
7390 if (ccline.cmdpos > ccline.cmdlen) | |
7391 ccline.cmdpos = ccline.cmdlen; | |
7392 if (cmdwin_result == K_IGNORE) | |
7393 { | |
7394 set_cmdspos_cursor(); | |
7395 redrawcmd(); | |
7396 } | |
7397 } | |
7398 | |
7399 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7400 block_autocmds(); |
6876 | 7401 # ifdef FEAT_CONCEAL |
7402 /* Avoid command-line window first character being concealed. */ | |
7403 curwin->w_p_cole = 0; | |
7404 # endif | |
7 | 7405 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7406 set_bufref(&bufref, curbuf); |
7 | 7407 win_goto(old_curwin); |
7408 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7409 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7410 /* 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
|
7411 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7412 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7413 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7414 |
7415 /* Restore window sizes. */ | |
7416 win_size_restore(&winsizes); | |
7417 | |
1410 | 7418 unblock_autocmds(); |
7 | 7419 } |
7420 | |
7421 ga_clear(&winsizes); | |
7422 restart_edit = save_restart_edit; | |
510 | 7423 # ifdef FEAT_RIGHTLEFT |
7424 cmdmsg_rl = save_cmdmsg_rl; | |
7425 # endif | |
7 | 7426 |
7427 State = save_State; | |
7428 # ifdef FEAT_MOUSE | |
7429 setmouse(); | |
7430 # endif | |
7431 | |
7432 return cmdwin_result; | |
7433 } | |
7434 #endif /* FEAT_CMDWIN */ | |
7435 | |
7436 /* | |
7437 * Used for commands that either take a simple command string argument, or: | |
7438 * cmd << endmarker | |
7439 * {script} | |
7440 * endmarker | |
7441 * Returns a pointer to allocated memory with {script} or NULL. | |
7442 */ | |
7443 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7444 script_get(exarg_T *eap, char_u *cmd) |
7 | 7445 { |
7446 char_u *theline; | |
7447 char *end_pattern = NULL; | |
7448 char dot[] = "."; | |
7449 garray_T ga; | |
7450 | |
7451 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7452 return NULL; | |
7453 | |
7454 ga_init2(&ga, 1, 0x400); | |
7455 | |
7456 if (cmd[2] != NUL) | |
7457 end_pattern = (char *)skipwhite(cmd + 2); | |
7458 else | |
7459 end_pattern = dot; | |
7460 | |
7461 for (;;) | |
7462 { | |
7463 theline = eap->getline( | |
7464 #ifdef FEAT_EVAL | |
75 | 7465 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7466 #endif |
7467 NUL, eap->cookie, 0); | |
7468 | |
7469 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7470 { |
7471 vim_free(theline); | |
7 | 7472 break; |
1694 | 7473 } |
7 | 7474 |
7475 ga_concat(&ga, theline); | |
7476 ga_append(&ga, '\n'); | |
7477 vim_free(theline); | |
7478 } | |
21 | 7479 ga_append(&ga, NUL); |
7 | 7480 |
7481 return (char_u *)ga.ga_data; | |
7482 } |