Mercurial > vim
annotate src/ex_getln.c @ 15064:7b2dcca9e0c1 v8.1.0543
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
commit https://github.com/vim/vim/commit/4e303c8ba8dcd0566a1ad7c82ff18eb016eea335
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 24 14:27:44 2018 +0100
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
Problem: Coverity warns for leaking memory and using wrong struct.
Solution: Free pointer when allocation fails. Change "boff" to "loff".
(closes #3634)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Nov 2018 14:30:08 +0100 |
parents | 676db1b7fc35 |
children | 70aa5caa9f0d |
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 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
47 // The current cmdline_info. It is initialized in getcmdline() and after that |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
48 // used by other functions. When invoking getcmdline() recursively it needs |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
49 // to be saved with save_cmdline() and restored with restore_cmdline(). |
1718 | 50 static struct cmdline_info ccline; |
7 | 51 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
52 static int cmd_showtail; /* Only show path tail in lists ? */ |
7 | 53 |
54 #ifdef FEAT_EVAL | |
55 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
56 #endif | |
57 | |
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
|
58 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
|
59 * 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
|
60 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
|
61 |
7 | 62 #ifdef FEAT_CMDHIST |
63 typedef struct hist_entry | |
64 { | |
65 int hisnum; /* identifying number */ | |
4258 | 66 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 67 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
|
68 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 69 } histentry_T; |
70 | |
71 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
72 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
73 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
74 /* identifying (unique) number of newest history entry */ | |
75 static int hislen = 0; /* actual length of history tables */ | |
76 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
77 static int hist_char2type(int c); |
7 | 78 #endif |
79 | |
80 #ifdef FEAT_RIGHTLEFT | |
81 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
82 #endif | |
83 | |
84 #ifdef FEAT_FKMAP | |
85 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
86 #endif | |
87 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
88 static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
89 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos_cursor(void); |
7 | 92 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
93 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
|
94 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 101 #ifdef FEAT_WILDMENU |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 static int expand_showtail(expand_T *xp); |
7 | 113 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 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
|
115 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
|
116 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 117 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 119 # endif |
7 | 120 # 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
|
121 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
|
122 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 123 # endif |
124 #endif | |
4265 | 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 void clear_hist_entry(histentry_T *hisptr); |
4265 | 127 #endif |
7 | 128 |
129 #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
|
130 static int open_cmdwin(void); |
7 | 131 #endif |
132 | |
3164 | 133 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
134 static int | |
135 #ifdef __BORLANDC__ | |
136 _RTLENTRYF | |
137 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
138 sort_func_compare(const void *s1, const void *s2); |
3164 | 139 #endif |
140 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
141 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
142 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
|
143 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
|
144 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 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
|
146 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 |
7 | 152 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
153 * 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
|
154 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
155 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
|
156 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
|
157 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 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
|
163 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
165 #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
|
166 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
167 * 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
|
168 * 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
|
169 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
170 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 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
|
172 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
173 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
|
174 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 /* 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
|
176 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
|
177 && 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
|
178 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 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
|
180 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
181 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
182 // 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
|
183 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 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
|
191 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
|
192 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 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
|
196 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 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
|
202 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 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
|
204 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
|
205 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 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
|
209 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 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
|
215 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 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
|
217 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
|
218 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
219 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
220 // 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
|
221 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 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
|
230 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
|
231 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 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
|
235 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 * 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
|
249 * 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
|
250 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 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
|
253 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 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
|
259 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
|
260 } |
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 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 * 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
|
265 * Sets search_first_line and search_last_line to the address range. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
266 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
272 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
273 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
274 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
275 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
276 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
277 char_u *end; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
278 char_u *dummy; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
279 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
281 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 *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
|
284 *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
|
285 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
288 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
289 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
290 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
291 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
292 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
293 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
333 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
337 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
343 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
347 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
350 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
351 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
353 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
354 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
355 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
356 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
357 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
358 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
359 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
360 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
362 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
363 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
364 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
365 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
366 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
368 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
369 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
371 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
372 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
374 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
376 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
377 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
378 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
379 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
380 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
381 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
382 curwin->w_cursor = is_state->search_start; |
14760
fd69edd2c67e
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
383 parse_cmd_address(&ea, &dummy, TRUE); |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
391 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
397 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
398 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
401 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
402 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
403 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
404 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
405 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
406 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
407 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
408 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
409 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
410 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
411 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
412 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
|
413 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
|
414 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
415 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
|
416 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 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
|
418 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 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
|
420 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 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
|
423 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 // 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
|
425 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 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
|
429 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
430 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
|
431 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
432 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
433 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
434 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
435 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
436 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
437 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
438 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 validate_cursor(); /* needed for TAB */ |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
440 redraw_all_later(SOME_VALID); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
441 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
|
442 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
|
443 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
444 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
445 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
446 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
447 * 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
|
448 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 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
|
451 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 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
|
454 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
455 int skiplen, patlen; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
456 int found; // do_search() result |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 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
|
458 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
461 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
462 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
|
463 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
464 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
465 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
466 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
467 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
|
468 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
469 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
470 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
|
471 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
472 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 // 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
|
475 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
477 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 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
|
479 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 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
|
482 |
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 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
|
484 // 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
|
485 curwin->w_cursor = is_state->search_start; |
14976
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
486 else if (search_first_line > curbuf->b_ml.ml_line_count) |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
487 { |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
488 // start after the last line |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
489 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
490 curwin->w_cursor.col = MAXCOL; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
491 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
492 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
493 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
494 // start at the 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
|
495 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.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
|
497 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
499 // 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
|
500 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
|
501 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
|
502 && 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
|
503 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
504 // 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
|
505 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
|
506 { |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
507 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 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
|
509 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
|
510 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 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
|
514 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 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
|
516 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 ++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
|
518 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 // 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
|
520 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
|
521 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 ccline.cmdbuff[skiplen + patlen] = NUL; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
527 found = do_search(NULL, firstc == ':' ? '/' : firstc, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
528 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
|
529 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
535 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
|
536 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
538 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
|
539 || 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
|
540 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
541 // match outside of address range |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
542 found = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
543 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
|
544 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
545 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 // 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
|
547 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 (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
|
550 got_int = FALSE; // don't abandon the command line |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
551 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 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
|
554 // 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
|
555 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
|
556 } |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
557 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
558 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
|
559 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 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
|
561 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 // 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
|
563 // 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
|
564 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
|
565 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
|
566 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
568 if (found != 0) |
14503
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 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
|
571 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 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
|
573 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
|
574 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 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
|
581 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
582 // Disable 'hlsearch' highlighting if the pattern matches everything. |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
583 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
584 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
585 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
586 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
587 ccline.cmdbuff[skiplen + patlen] = NUL; |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
588 if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
589 { |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
590 redraw_all_later(SOME_VALID); |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
591 set_no_hlsearch(TRUE); |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
592 } |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
593 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
594 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
595 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
596 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 // 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
|
598 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
|
599 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
|
600 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 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
|
602 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
|
603 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
604 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
605 // end of the pattern, e.g. for ":s/pat/". |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
606 if (ccline.cmdbuff[skiplen + patlen] != NUL) |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
607 curwin->w_cursor = is_state->search_start; |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
608 else if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 is_state->did_incsearch = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 * May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 * Returns FAIL when jumping to cmdline_not_changed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 may_adjust_incsearch_highlighting( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
623 int firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
624 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 incsearch_state_T *is_state, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
626 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
628 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 int search_flags = SEARCH_NOOF; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 int i; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
633 int save; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
634 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
635 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
636 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
637 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
638 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
639 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
640 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
642 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
643 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
644 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
645 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
647 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
649 if (firstc == ccline.cmdbuff[skiplen]) |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
650 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 pat = last_search_pattern(); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
652 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
653 patlen = (int)STRLEN(pat); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
654 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 else |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
656 pat = ccline.cmdbuff + skiplen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
657 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
658 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 if (c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
661 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 t = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 if (LT_POS(is_state->match_start, is_state->match_end)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 // Start searching at the end of the match not at the beginning of |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 t = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 search_flags += SEARCH_KEEP; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
674 save = pat[patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
675 pat[patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 i = searchit(curwin, curbuf, &t, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 c == Ctrl_G ? FORWARD : BACKWARD, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 pat, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 RE_SEARCH, 0, NULL, NULL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
681 pat[patlen] = save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
682 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
684 is_state->search_start = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 is_state->match_end = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 is_state->match_start = t; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
687 if (c == Ctrl_T && firstc != '?') |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 // Move just before the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
693 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
694 else if (c == Ctrl_G && firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
695 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
696 // Move just after the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
697 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
699 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
700 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
701 if (LT_POS(t, is_state->search_start) && c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
705 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
709 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
710 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
711 set_search_match(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
712 curwin->w_cursor = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
714 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
715 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
716 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
717 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
718 update_screen(NOT_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
719 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
720 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
721 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 vim_beep(BO_ERROR); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
723 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
724 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
726 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
727 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
728 * When CTRL-L typed: add character from the match to the pattern. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
729 * May set "*c" to the added character. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 * Return OK when jumping to cmdline_not_changed. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
731 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
732 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
734 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
735 int skiplen, patlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
736 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
737 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
738 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
739 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
740 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
741 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
742 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
743 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
744 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
745 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
746 // Add a character from under the cursor for 'incsearch'. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
747 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
748 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
749 curwin->w_cursor = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
750 if (!EQUAL_POS(curwin->w_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
751 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
752 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
753 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
754 // If 'ignorecase' and 'smartcase' are set and the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
755 // command line has no uppercase characters, convert |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
756 // the character to lowercase. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
757 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
758 *c = MB_TOLOWER(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
759 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
760 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
761 if (*c == firstc || vim_strchr((char_u *)( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
762 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
763 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
764 // put a backslash before special characters |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
765 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
766 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
767 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
768 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
769 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
770 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
771 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
772 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
773 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
774 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
775 |
14858
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
776 void |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
777 cmdline_init(void) |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
778 { |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
779 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
780 } |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
781 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
782 /* |
7 | 783 * getcmdline() - accept a command line starting with firstc. |
784 * | |
785 * firstc == ':' get ":" command line. | |
786 * firstc == '/' or '?' get search pattern | |
787 * firstc == '=' get expression | |
788 * firstc == '@' get text for input() function | |
789 * firstc == '>' get text for debug mode | |
790 * firstc == NUL get text for :insert command | |
791 * firstc == -1 like NUL, and break on CTRL-C | |
792 * | |
793 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
794 * command line. | |
795 * | |
796 * Careful: getcmdline() can be called recursively! | |
797 * | |
798 * Return pointer to allocated string if there is a commandline, NULL | |
799 * otherwise. | |
800 */ | |
801 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
802 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
803 int firstc, |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
804 long count, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
805 int indent) // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
806 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
807 return getcmdline_int(firstc, count, indent, TRUE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
808 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
809 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
810 static char_u * |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
811 getcmdline_int( |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
812 int firstc, |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
813 long count UNUSED, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
814 int indent, // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
815 int init_ccline) // clear ccline first |
7 | 816 { |
817 int c; | |
818 int i; | |
819 int j; | |
820 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
821 int do_abbr; /* when TRUE check for abbr. */ | |
822 #ifdef FEAT_CMDHIST | |
823 char_u *lookfor = NULL; /* string to match */ | |
824 int hiscnt; /* current history line in use */ | |
825 int histype; /* history type to be used */ | |
826 #endif | |
827 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
828 incsearch_state_T is_state; |
7 | 829 #endif |
830 int did_wild_list = FALSE; /* did wild_list() recently */ | |
831 int wim_index = 0; /* index in wim_flags[] */ | |
832 int res; | |
833 int save_msg_scroll = msg_scroll; | |
834 int save_State = State; /* remember State when called */ | |
835 int some_key_typed = FALSE; /* one of the keys was typed */ | |
836 #ifdef FEAT_MOUSE | |
837 /* mouse drag and release events are ignored, unless they are | |
838 * preceded with a mouse down event */ | |
839 int ignore_drag_release = TRUE; | |
840 #endif | |
841 #ifdef FEAT_EVAL | |
842 int break_ctrl_c = FALSE; | |
843 #endif | |
844 expand_T xpc; | |
845 long *b_im_ptr = NULL; | |
195 | 846 struct cmdline_info save_ccline; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
847 int did_save_ccline = FALSE; |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
848 int cmdline_type; |
7 | 849 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
850 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
851 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
852 // Being called recursively. Since ccline is global, we need to save |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
853 // the current buffer and restore it when returning. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
854 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
855 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
856 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
857 if (init_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
858 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
859 |
7 | 860 #ifdef FEAT_EVAL |
861 if (firstc == -1) | |
862 { | |
863 firstc = NUL; | |
864 break_ctrl_c = TRUE; | |
865 } | |
866 #endif | |
867 #ifdef FEAT_RIGHTLEFT | |
868 /* start without Hebrew mapping for a command line */ | |
869 if (firstc == ':' || firstc == '=' || firstc == '>') | |
870 cmd_hkmap = 0; | |
871 #endif | |
872 | |
873 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
|
874 |
7 | 875 #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
|
876 init_incsearch_state(&is_state); |
7 | 877 #endif |
878 | |
879 /* | |
880 * set some variables for redrawcmd() | |
881 */ | |
882 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 883 ccline.cmdindent = (firstc > 0 ? indent : 0); |
884 | |
885 /* alloc initial ccline.cmdbuff */ | |
886 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 887 if (ccline.cmdbuff == NULL) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
888 goto theend; // out of memory |
7 | 889 ccline.cmdlen = ccline.cmdpos = 0; |
890 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
|
891 sb_text_start_cmdline(); |
7 | 892 |
164 | 893 /* autoindent for :insert and :append */ |
894 if (firstc <= 0) | |
895 { | |
6929 | 896 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 897 ccline.cmdbuff[indent] = NUL; |
898 ccline.cmdpos = indent; | |
899 ccline.cmdspos = indent; | |
900 ccline.cmdlen = indent; | |
901 } | |
902 | |
7 | 903 ExpandInit(&xpc); |
1718 | 904 ccline.xpc = &xpc; |
7 | 905 |
906 #ifdef FEAT_RIGHTLEFT | |
907 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
908 && (firstc == '/' || firstc == '?')) | |
909 cmdmsg_rl = TRUE; | |
910 else | |
911 cmdmsg_rl = FALSE; | |
912 #endif | |
913 | |
914 redir_off = TRUE; /* don't redirect the typed command */ | |
915 if (!cmd_silent) | |
916 { | |
917 i = msg_scrolled; | |
918 msg_scrolled = 0; /* avoid wait_return message */ | |
919 gotocmdline(TRUE); | |
920 msg_scrolled += i; | |
921 redrawcmdprompt(); /* draw prompt or indent */ | |
922 set_cmdspos(); | |
923 } | |
924 xpc.xp_context = EXPAND_NOTHING; | |
925 xpc.xp_backslash = XP_BS_NONE; | |
632 | 926 #ifndef BACKSLASH_IN_FILENAME |
927 xpc.xp_shell = FALSE; | |
928 #endif | |
7 | 929 |
531 | 930 #if defined(FEAT_EVAL) |
931 if (ccline.input_fn) | |
932 { | |
933 xpc.xp_context = ccline.xp_context; | |
934 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 935 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 936 xpc.xp_arg = ccline.xp_arg; |
1322 | 937 # endif |
531 | 938 } |
939 #endif | |
940 | |
7 | 941 /* |
942 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
943 * doing ":@0" when register 0 doesn't contain a CR. | |
944 */ | |
945 msg_scroll = FALSE; | |
946 | |
947 State = CMDLINE; | |
948 | |
949 if (firstc == '/' || firstc == '?' || firstc == '@') | |
950 { | |
951 /* Use ":lmap" mappings for search pattern and input(). */ | |
952 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
953 b_im_ptr = &curbuf->b_p_iminsert; | |
954 else | |
955 b_im_ptr = &curbuf->b_p_imsearch; | |
956 if (*b_im_ptr == B_IMODE_LMAP) | |
957 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
958 #ifdef HAVE_INPUT_METHOD |
7 | 959 im_set_active(*b_im_ptr == B_IMODE_IM); |
960 #endif | |
961 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
962 #ifdef HAVE_INPUT_METHOD |
7 | 963 else if (p_imcmdline) |
964 im_set_active(TRUE); | |
965 #endif | |
966 | |
967 #ifdef FEAT_MOUSE | |
968 setmouse(); | |
969 #endif | |
970 #ifdef CURSOR_SHAPE | |
971 ui_cursor_shape(); /* may show different cursor shape */ | |
972 #endif | |
973 | |
571 | 974 /* When inside an autocommand for writing "exiting" may be set and |
975 * terminal mode set to cooked. Need to set raw mode here then. */ | |
976 settmode(TMODE_RAW); | |
977 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
978 /* 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
|
979 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
|
980 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
|
981 |
7 | 982 #ifdef FEAT_CMDHIST |
983 init_history(); | |
984 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
985 histype = hist_char2type(firstc); | |
986 #endif | |
987 | |
988 #ifdef FEAT_DIGRAPHS | |
1868 | 989 do_digraph(-1); /* init digraph typeahead */ |
7 | 990 #endif |
991 | |
5993 | 992 /* If something above caused an error, reset the flags, we do want to type |
993 * and execute commands. Display may be messed up a bit. */ | |
994 if (did_emsg) | |
995 redrawcmd(); | |
996 did_emsg = FALSE; | |
997 got_int = FALSE; | |
998 | |
7 | 999 /* |
1000 * Collect the command string, handling editing keys. | |
1001 */ | |
1002 for (;;) | |
1003 { | |
972 | 1004 redir_off = TRUE; /* Don't redirect the typed command. |
1005 Repeated, because a ":redir" inside | |
1006 completion may switch it on. */ | |
7 | 1007 #ifdef USE_ON_FLY_SCROLL |
1008 dont_scroll = FALSE; /* allow scrolling here */ | |
1009 #endif | |
1010 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
1011 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 |
7 | 1016 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 1017 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
1018 /* 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
|
1019 * anything, such as stop completion. */ |
1472 | 1020 do |
1021 { | |
1022 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
|
1023 } while (c == K_IGNORE || c == K_NOP); |
1472 | 1024 |
7 | 1025 if (KeyTyped) |
1026 { | |
1027 some_key_typed = TRUE; | |
1028 #ifdef FEAT_RIGHTLEFT | |
1029 if (cmd_hkmap) | |
1030 c = hkmap(c); | |
1031 # ifdef FEAT_FKMAP | |
1032 if (cmd_fkmap) | |
1033 c = cmdl_fkmap(c); | |
1034 # endif | |
1035 if (cmdmsg_rl && !KeyStuffed) | |
1036 { | |
1037 /* Invert horizontal movements and operations. Only when | |
1038 * typed by the user directly, not when the result of a | |
1039 * mapping. */ | |
1040 switch (c) | |
1041 { | |
1042 case K_RIGHT: c = K_LEFT; break; | |
1043 case K_S_RIGHT: c = K_S_LEFT; break; | |
1044 case K_C_RIGHT: c = K_C_LEFT; break; | |
1045 case K_LEFT: c = K_RIGHT; break; | |
1046 case K_S_LEFT: c = K_S_RIGHT; break; | |
1047 case K_C_LEFT: c = K_C_RIGHT; break; | |
1048 } | |
1049 } | |
1050 #endif | |
1051 } | |
1052 | |
1053 /* | |
1054 * Ignore got_int when CTRL-C was typed here. | |
1055 * Don't ignore it in :global, we really need to break then, e.g., for | |
1056 * ":g/pat/normal /pat" (without the <CR>). | |
1057 * Don't ignore it for the input() function. | |
1058 */ | |
1059 if ((c == Ctrl_C | |
1060 #ifdef UNIX | |
1061 || c == intr_char | |
1062 #endif | |
1063 ) | |
1064 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1065 && firstc != '@' | |
1066 #endif | |
1067 #ifdef FEAT_EVAL | |
1068 && !break_ctrl_c | |
1069 #endif | |
1070 && !global_busy) | |
1071 got_int = FALSE; | |
1072 | |
1073 #ifdef FEAT_CMDHIST | |
1074 /* free old command line when finished moving around in the history | |
1075 * list */ | |
1076 if (lookfor != NULL | |
180 | 1077 && c != K_S_DOWN && c != K_S_UP |
230 | 1078 && c != K_DOWN && c != K_UP |
7 | 1079 && c != K_PAGEDOWN && c != K_PAGEUP |
1080 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1081 && c != K_LEFT && c != K_RIGHT |
7 | 1082 && (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
|
1083 VIM_CLEAR(lookfor); |
7 | 1084 #endif |
1085 | |
1086 /* | |
1718 | 1087 * When there are matching completions to select <S-Tab> works like |
1088 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1089 */ |
1718 | 1090 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1091 c = Ctrl_P; |
1092 | |
1093 #ifdef FEAT_WILDMENU | |
1094 /* Special translations for 'wildmenu' */ | |
1095 if (did_wild_list && p_wmnu) | |
1096 { | |
230 | 1097 if (c == K_LEFT) |
7 | 1098 c = Ctrl_P; |
230 | 1099 else if (c == K_RIGHT) |
7 | 1100 c = Ctrl_N; |
1101 } | |
1102 /* Hitting CR after "emenu Name.": complete submenu */ | |
1103 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1104 && ccline.cmdpos > 1 | |
1105 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1106 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1107 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1108 c = K_DOWN; | |
1109 #endif | |
1110 | |
1111 /* free expanded names when finished walking through matches */ | |
1112 if (xpc.xp_numfiles != -1 | |
1113 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1114 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1115 && c != Ctrl_L) | |
1116 { | |
1117 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1118 did_wild_list = FALSE; | |
1119 #ifdef FEAT_WILDMENU | |
230 | 1120 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1121 #endif |
1122 xpc.xp_context = EXPAND_NOTHING; | |
1123 wim_index = 0; | |
1124 #ifdef FEAT_WILDMENU | |
1125 if (p_wmnu && wild_menu_showing != 0) | |
1126 { | |
1127 int skt = KeyTyped; | |
532 | 1128 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1129 |
1130 if (ccline.input_fn) | |
1131 RedrawingDisabled = 0; | |
7 | 1132 |
1133 if (wild_menu_showing == WM_SCROLLED) | |
1134 { | |
1135 /* Entered command line, move it up */ | |
1136 cmdline_row--; | |
1137 redrawcmd(); | |
1138 } | |
1139 else if (save_p_ls != -1) | |
1140 { | |
1141 /* restore 'laststatus' and 'winminheight' */ | |
1142 p_ls = save_p_ls; | |
1143 p_wmh = save_p_wmh; | |
1144 last_status(FALSE); | |
1145 update_screen(VALID); /* redraw the screen NOW */ | |
1146 redrawcmd(); | |
1147 save_p_ls = -1; | |
1148 } | |
1149 else | |
1150 { | |
1151 win_redraw_last_status(topframe); | |
1152 redraw_statuslines(); | |
1153 } | |
532 | 1154 KeyTyped = skt; |
1155 wild_menu_showing = 0; | |
531 | 1156 if (ccline.input_fn) |
1157 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1158 } |
1159 #endif | |
1160 } | |
1161 | |
1162 #ifdef FEAT_WILDMENU | |
1163 /* Special translations for 'wildmenu' */ | |
1164 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1165 { | |
1166 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1167 if (c == K_DOWN && ccline.cmdpos > 0 |
1168 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1169 c = p_wc; |
230 | 1170 else if (c == K_UP) |
7 | 1171 { |
1172 /* Hitting <Up>: Remove one submenu name in front of the | |
1173 * cursor */ | |
1174 int found = FALSE; | |
1175 | |
1176 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1177 i = 0; | |
1178 while (--j > 0) | |
1179 { | |
1180 /* check for start of menu name */ | |
1181 if (ccline.cmdbuff[j] == ' ' | |
1182 && ccline.cmdbuff[j - 1] != '\\') | |
1183 { | |
1184 i = j + 1; | |
1185 break; | |
1186 } | |
1187 /* check for start of submenu name */ | |
1188 if (ccline.cmdbuff[j] == '.' | |
1189 && ccline.cmdbuff[j - 1] != '\\') | |
1190 { | |
1191 if (found) | |
1192 { | |
1193 i = j + 1; | |
1194 break; | |
1195 } | |
1196 else | |
1197 found = TRUE; | |
1198 } | |
1199 } | |
1200 if (i > 0) | |
1201 cmdline_del(i); | |
1202 c = p_wc; | |
1203 xpc.xp_context = EXPAND_NOTHING; | |
1204 } | |
1205 } | |
714 | 1206 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1207 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1208 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1209 { |
1210 char_u upseg[5]; | |
1211 | |
1212 upseg[0] = PATHSEP; | |
1213 upseg[1] = '.'; | |
1214 upseg[2] = '.'; | |
1215 upseg[3] = PATHSEP; | |
1216 upseg[4] = NUL; | |
1217 | |
1318 | 1218 if (c == K_DOWN |
1219 && ccline.cmdpos > 0 | |
1220 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1221 && (ccline.cmdpos < 3 | |
1222 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1223 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1224 { | |
1225 /* go down a directory */ | |
1226 c = p_wc; | |
1227 } | |
230 | 1228 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1229 { |
1230 /* If in a direct ancestor, strip off one ../ to go down */ | |
1231 int found = FALSE; | |
1232 | |
1233 j = ccline.cmdpos; | |
1234 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1235 while (--j > i) | |
1236 { | |
39 | 1237 #ifdef FEAT_MBYTE |
1238 if (has_mbyte) | |
1239 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1240 #endif | |
7 | 1241 if (vim_ispathsep(ccline.cmdbuff[j])) |
1242 { | |
1243 found = TRUE; | |
1244 break; | |
1245 } | |
1246 } | |
1247 if (found | |
1248 && ccline.cmdbuff[j - 1] == '.' | |
1249 && ccline.cmdbuff[j - 2] == '.' | |
1250 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1251 { | |
1252 cmdline_del(j - 2); | |
1253 c = p_wc; | |
1254 } | |
1255 } | |
230 | 1256 else if (c == K_UP) |
7 | 1257 { |
1258 /* go up a directory */ | |
1259 int found = FALSE; | |
1260 | |
1261 j = ccline.cmdpos - 1; | |
1262 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1263 while (--j > i) | |
1264 { | |
1265 #ifdef FEAT_MBYTE | |
1266 if (has_mbyte) | |
1267 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1268 #endif | |
1269 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1270 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1271 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1272 ccline.cmdbuff[j + 1]) == NULL |
7 | 1273 #endif |
1274 ) | |
1275 { | |
1276 if (found) | |
1277 { | |
1278 i = j + 1; | |
1279 break; | |
1280 } | |
1281 else | |
1282 found = TRUE; | |
1283 } | |
1284 } | |
1285 | |
1286 if (!found) | |
1287 j = i; | |
1288 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1289 j += 4; | |
1290 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1291 && j == i) | |
1292 j += 3; | |
1293 else | |
1294 j = 0; | |
1295 if (j > 0) | |
1296 { | |
1297 /* TODO this is only for DOS/UNIX systems - need to put in | |
1298 * machine-specific stuff here and in upseg init */ | |
1299 cmdline_del(j); | |
1300 put_on_cmdline(upseg + 1, 3, FALSE); | |
1301 } | |
1302 else if (ccline.cmdpos > i) | |
1303 cmdline_del(i); | |
3204 | 1304 |
1305 /* Now complete in the new directory. Set KeyTyped in case the | |
1306 * Up key came from a mapping. */ | |
7 | 1307 c = p_wc; |
3204 | 1308 KeyTyped = TRUE; |
7 | 1309 } |
1310 } | |
1311 | |
1312 #endif /* FEAT_WILDMENU */ | |
1313 | |
1314 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1315 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1316 if (c == Ctrl_BSL) | |
1317 { | |
1318 ++no_mapping; | |
1319 ++allow_keys; | |
1389 | 1320 c = plain_vgetc(); |
7 | 1321 --no_mapping; |
1322 --allow_keys; | |
3859 | 1323 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1324 * is in a mapping. */ | |
1325 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1326 || (ccline.cmdfirstc == '=' && KeyTyped) |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1327 #ifdef FEAT_EVAL |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1328 || cmdline_star > 0 |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1329 #endif |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1330 )) |
7 | 1331 { |
1332 vungetc(c); | |
1333 c = Ctrl_BSL; | |
1334 } | |
1335 #ifdef FEAT_EVAL | |
1336 else if (c == 'e') | |
1337 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1338 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1339 int len; |
7 | 1340 |
1341 /* | |
1342 * Replace the command line with the result of an expression. | |
625 | 1343 * Need to save and restore the current command line, to be |
1344 * able to enter a new one... | |
7 | 1345 */ |
1346 if (ccline.cmdpos == ccline.cmdlen) | |
1347 new_cmdpos = 99999; /* keep it at the end */ | |
1348 else | |
1349 new_cmdpos = ccline.cmdpos; | |
95 | 1350 |
7 | 1351 c = get_expr_register(); |
1352 if (c == '=') | |
1353 { | |
634 | 1354 /* Need to save and restore ccline. And set "textlock" |
632 | 1355 * to avoid nasty things like going to another buffer when |
1356 * evaluating an expression. */ | |
634 | 1357 ++textlock; |
7 | 1358 p = get_expr_line(); |
634 | 1359 --textlock; |
2617 | 1360 |
1361 if (p != NULL) | |
7 | 1362 { |
2617 | 1363 len = (int)STRLEN(p); |
1364 if (realloc_cmdbuff(len + 1) == OK) | |
1365 { | |
1366 ccline.cmdlen = len; | |
1367 STRCPY(ccline.cmdbuff, p); | |
1368 vim_free(p); | |
1369 | |
1370 /* Restore the cursor or use the position set with | |
1371 * set_cmdline_pos(). */ | |
1372 if (new_cmdpos > ccline.cmdlen) | |
1373 ccline.cmdpos = ccline.cmdlen; | |
1374 else | |
1375 ccline.cmdpos = new_cmdpos; | |
1376 | |
1377 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1378 redrawcmd(); | |
1379 goto cmdline_changed; | |
1380 } | |
15064
7b2dcca9e0c1
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
Bram Moolenaar <Bram@vim.org>
parents:
14976
diff
changeset
|
1381 vim_free(p); |
7 | 1382 } |
1383 } | |
1384 beep_flush(); | |
2636 | 1385 got_int = FALSE; /* don't abandon the command line */ |
1386 did_emsg = FALSE; | |
1387 emsg_on_display = FALSE; | |
1388 redrawcmd(); | |
1389 goto cmdline_not_changed; | |
7 | 1390 } |
1391 #endif | |
1392 else | |
1393 { | |
1394 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1395 restart_edit = 'a'; | |
1396 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1397 in history */ | |
1398 goto returncmd; /* back to Normal mode */ | |
1399 } | |
1400 } | |
1401 | |
1402 #ifdef FEAT_CMDWIN | |
1403 if (c == cedit_key || c == K_CMDWIN) | |
1404 { | |
6211 | 1405 if (ex_normal_busy == 0 && got_int == FALSE) |
1406 { | |
1407 /* | |
1408 * Open a window to edit the command line (and history). | |
1409 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1410 c = open_cmdwin(); |
6211 | 1411 some_key_typed = TRUE; |
1412 } | |
7 | 1413 } |
1414 # ifdef FEAT_DIGRAPHS | |
1415 else | |
1416 # endif | |
1417 #endif | |
1418 #ifdef FEAT_DIGRAPHS | |
1419 c = do_digraph(c); | |
1420 #endif | |
1421 | |
1422 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1423 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1424 { | |
168 | 1425 /* In Ex mode a backslash escapes a newline. */ |
1426 if (exmode_active | |
1427 && c != ESC | |
1318 | 1428 && ccline.cmdpos == ccline.cmdlen |
168 | 1429 && ccline.cmdpos > 0 |
1430 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1431 { | |
1432 if (c == K_KENTER) | |
1433 c = '\n'; | |
1434 } | |
1435 else | |
7 | 1436 { |
168 | 1437 gotesc = FALSE; /* Might have typed ESC previously, don't |
1438 truncate the cmdline now. */ | |
1439 if (ccheck_abbr(c + ABBR_OFF)) | |
1440 goto cmdline_changed; | |
1441 if (!cmd_silent) | |
1442 { | |
1443 windgoto(msg_row, 0); | |
1444 out_flush(); | |
1445 } | |
1446 break; | |
7 | 1447 } |
1448 } | |
1449 | |
1450 /* | |
1451 * Completion for 'wildchar' or 'wildcharm' key. | |
1452 * - hitting <ESC> twice means: abandon command line. | |
1453 * - wildcard expansion is only done when the 'wildchar' key is really | |
1454 * typed, not when it comes from a macro | |
1455 */ | |
1456 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1457 { | |
1458 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1459 { | |
1460 /* if 'wildmode' contains "list" may still need to list */ | |
1461 if (xpc.xp_numfiles > 1 | |
1462 && !did_wild_list | |
1463 && (wim_flags[wim_index] & WIM_LIST)) | |
1464 { | |
1465 (void)showmatches(&xpc, FALSE); | |
1466 redrawcmd(); | |
1467 did_wild_list = TRUE; | |
1468 } | |
1469 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1470 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1471 firstc != '@'); | |
7 | 1472 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1473 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1474 firstc != '@'); | |
7 | 1475 else |
1476 res = OK; /* don't insert 'wildchar' now */ | |
1477 } | |
1478 else /* typed p_wc first time */ | |
1479 { | |
1480 wim_index = 0; | |
1481 j = ccline.cmdpos; | |
1482 /* if 'wildmode' first contains "longest", get longest | |
1483 * common part */ | |
1484 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1485 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1486 firstc != '@'); | |
7 | 1487 else |
3961 | 1488 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1489 firstc != '@'); | |
7 | 1490 |
1491 /* if interrupted while completing, behave like it failed */ | |
1492 if (got_int) | |
1493 { | |
1494 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1495 got_int = FALSE; /* don't abandon the command line */ | |
1496 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1497 #ifdef FEAT_WILDMENU | |
1498 xpc.xp_context = EXPAND_NOTHING; | |
1499 #endif | |
1500 goto cmdline_changed; | |
1501 } | |
1502 | |
1503 /* when more than one match, and 'wildmode' first contains | |
1504 * "list", or no change and 'wildmode' contains "longest,list", | |
1505 * list all matches */ | |
1506 if (res == OK && xpc.xp_numfiles > 1) | |
1507 { | |
1508 /* a "longest" that didn't do anything is skipped (but not | |
1509 * "list:longest") */ | |
1510 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1511 wim_index = 1; | |
1512 if ((wim_flags[wim_index] & WIM_LIST) | |
1513 #ifdef FEAT_WILDMENU | |
1514 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1515 #endif | |
1516 ) | |
1517 { | |
1518 if (!(wim_flags[0] & WIM_LONGEST)) | |
1519 { | |
1520 #ifdef FEAT_WILDMENU | |
1521 int p_wmnu_save = p_wmnu; | |
1522 p_wmnu = 0; | |
1523 #endif | |
3961 | 1524 /* remove match */ |
1525 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1526 #ifdef FEAT_WILDMENU |
1527 p_wmnu = p_wmnu_save; | |
1528 #endif | |
1529 } | |
1530 #ifdef FEAT_WILDMENU | |
1531 (void)showmatches(&xpc, p_wmnu | |
1532 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1533 #else | |
1534 (void)showmatches(&xpc, FALSE); | |
1535 #endif | |
1536 redrawcmd(); | |
1537 did_wild_list = TRUE; | |
1538 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1539 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1540 firstc != '@'); | |
7 | 1541 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1542 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1543 firstc != '@'); | |
7 | 1544 } |
1545 else | |
6949 | 1546 vim_beep(BO_WILD); |
7 | 1547 } |
1548 #ifdef FEAT_WILDMENU | |
1549 else if (xpc.xp_numfiles == -1) | |
1550 xpc.xp_context = EXPAND_NOTHING; | |
1551 #endif | |
1552 } | |
1553 if (wim_index < 3) | |
1554 ++wim_index; | |
1555 if (c == ESC) | |
1556 gotesc = TRUE; | |
1557 if (res == OK) | |
1558 goto cmdline_changed; | |
1559 } | |
1560 | |
1561 gotesc = FALSE; | |
1562 | |
1563 /* <S-Tab> goes to last match, in a clumsy way */ | |
1564 if (c == K_S_TAB && KeyTyped) | |
1565 { | |
3961 | 1566 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1567 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1568 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1569 goto cmdline_changed; |
1570 } | |
1571 | |
1572 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1573 c = NL; | |
1574 | |
1575 do_abbr = TRUE; /* default: check for abbreviation */ | |
1576 | |
1577 /* | |
1578 * Big switch for a typed command line character. | |
1579 */ | |
1580 switch (c) | |
1581 { | |
1582 case K_BS: | |
1583 case Ctrl_H: | |
1584 case K_DEL: | |
1585 case K_KDEL: | |
1586 case Ctrl_W: | |
1587 #ifdef FEAT_FKMAP | |
1588 if (cmd_fkmap && c == K_BS) | |
1589 c = K_DEL; | |
1590 #endif | |
1591 if (c == K_KDEL) | |
1592 c = K_DEL; | |
1593 | |
1594 /* | |
1595 * delete current character is the same as backspace on next | |
1596 * character, except at end of line | |
1597 */ | |
1598 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1599 ++ccline.cmdpos; | |
1600 #ifdef FEAT_MBYTE | |
1601 if (has_mbyte && c == K_DEL) | |
1602 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1603 ccline.cmdbuff + ccline.cmdpos); | |
1604 #endif | |
1605 if (ccline.cmdpos > 0) | |
1606 { | |
1607 char_u *p; | |
1608 | |
1609 j = ccline.cmdpos; | |
1610 p = ccline.cmdbuff + j; | |
1611 #ifdef FEAT_MBYTE | |
1612 if (has_mbyte) | |
1613 { | |
1614 p = mb_prevptr(ccline.cmdbuff, p); | |
1615 if (c == Ctrl_W) | |
1616 { | |
1617 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1618 p = mb_prevptr(ccline.cmdbuff, p); | |
1619 i = mb_get_class(p); | |
1620 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1621 p = mb_prevptr(ccline.cmdbuff, p); | |
1622 if (mb_get_class(p) != i) | |
474 | 1623 p += (*mb_ptr2len)(p); |
7 | 1624 } |
1625 } | |
1626 else | |
1627 #endif | |
1628 if (c == Ctrl_W) | |
1629 { | |
1630 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1631 --p; | |
1632 i = vim_iswordc(p[-1]); | |
1633 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1634 && vim_iswordc(p[-1]) == i) | |
1635 --p; | |
1636 } | |
1637 else | |
1638 --p; | |
1639 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1640 ccline.cmdlen -= j - ccline.cmdpos; | |
1641 i = ccline.cmdpos; | |
1642 while (i < ccline.cmdlen) | |
1643 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1644 | |
1645 /* Truncate at the end, required for multi-byte chars. */ | |
1646 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1647 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1648 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1649 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1650 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
|
1651 /* 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
|
1652 * 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
|
1653 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
|
1654 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1655 #endif |
7 | 1656 redrawcmd(); |
1657 } | |
1658 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1659 && ccline.cmdprompt == NULL && indent == 0) | |
1660 { | |
1661 /* In ex and debug mode it doesn't make sense to return. */ | |
1662 if (exmode_active | |
1663 #ifdef FEAT_EVAL | |
1664 || ccline.cmdfirstc == '>' | |
1665 #endif | |
1666 ) | |
1667 goto cmdline_not_changed; | |
1668 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1669 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1670 if (!cmd_silent) |
1671 { | |
1672 #ifdef FEAT_RIGHTLEFT | |
1673 if (cmdmsg_rl) | |
1674 msg_col = Columns; | |
1675 else | |
1676 #endif | |
1677 msg_col = 0; | |
1678 msg_putchar(' '); /* delete ':' */ | |
1679 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1680 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1681 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
|
1682 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
|
1683 #endif |
7 | 1684 redraw_cmdline = TRUE; |
1685 goto returncmd; /* back to cmd mode */ | |
1686 } | |
1687 goto cmdline_changed; | |
1688 | |
1689 case K_INS: | |
1690 case K_KINS: | |
1691 #ifdef FEAT_FKMAP | |
1692 /* if Farsi mode set, we are in reverse insert mode - | |
1693 Do not change the mode */ | |
1694 if (cmd_fkmap) | |
1695 beep_flush(); | |
1696 else | |
1697 #endif | |
1698 ccline.overstrike = !ccline.overstrike; | |
1699 #ifdef CURSOR_SHAPE | |
1700 ui_cursor_shape(); /* may show different cursor shape */ | |
1701 #endif | |
1702 goto cmdline_not_changed; | |
1703 | |
1704 case Ctrl_HAT: | |
782 | 1705 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1706 { |
1707 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1708 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1709 #ifdef HAVE_INPUT_METHOD |
7 | 1710 im_set_active(FALSE); /* Disable input method */ |
1711 #endif | |
1712 if (b_im_ptr != NULL) | |
1713 { | |
1714 if (State & LANGMAP) | |
1715 *b_im_ptr = B_IMODE_LMAP; | |
1716 else | |
1717 *b_im_ptr = B_IMODE_NONE; | |
1718 } | |
1719 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1720 #ifdef HAVE_INPUT_METHOD |
7 | 1721 else |
1722 { | |
1723 /* There are no ":lmap" mappings, toggle IM. When | |
1724 * 'imdisable' is set don't try getting the status, it's | |
1725 * always off. */ | |
1726 if ((p_imdisable && b_im_ptr != NULL) | |
1727 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1728 { | |
1729 im_set_active(FALSE); /* Disable input method */ | |
1730 if (b_im_ptr != NULL) | |
1731 *b_im_ptr = B_IMODE_NONE; | |
1732 } | |
1733 else | |
1734 { | |
1735 im_set_active(TRUE); /* Enable input method */ | |
1736 if (b_im_ptr != NULL) | |
1737 *b_im_ptr = B_IMODE_IM; | |
1738 } | |
1739 } | |
1740 #endif | |
1741 if (b_im_ptr != NULL) | |
1742 { | |
1743 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1744 set_iminsert_global(); | |
1745 else | |
1746 set_imsearch_global(); | |
1747 } | |
1748 #ifdef CURSOR_SHAPE | |
1749 ui_cursor_shape(); /* may show different cursor shape */ | |
1750 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1751 #if defined(FEAT_KEYMAP) |
7 | 1752 /* Show/unshow value of 'keymap' in status lines later. */ |
1753 status_redraw_curbuf(); | |
1754 #endif | |
1755 goto cmdline_not_changed; | |
1756 | |
1757 /* case '@': only in very old vi */ | |
1758 case Ctrl_U: | |
1759 /* delete all characters left of the cursor */ | |
1760 j = ccline.cmdpos; | |
1761 ccline.cmdlen -= j; | |
1762 i = ccline.cmdpos = 0; | |
1763 while (i < ccline.cmdlen) | |
1764 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1765 /* Truncate at the end, required for multi-byte chars. */ | |
1766 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1767 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1768 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
|
1769 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
|
1770 #endif |
7 | 1771 redrawcmd(); |
1772 goto cmdline_changed; | |
1773 | |
1774 #ifdef FEAT_CLIPBOARD | |
1775 case Ctrl_Y: | |
1776 /* Copy the modeless selection, if there is one. */ | |
1777 if (clip_star.state != SELECT_CLEARED) | |
1778 { | |
1779 if (clip_star.state == SELECT_DONE) | |
1780 clip_copy_modeless_selection(TRUE); | |
1781 goto cmdline_not_changed; | |
1782 } | |
1783 break; | |
1784 #endif | |
1785 | |
1786 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1787 case Ctrl_C: | |
571 | 1788 /* In exmode it doesn't make sense to return. Except when |
161 | 1789 * ":normal" runs out of characters. */ |
1790 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1791 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1792 goto cmdline_not_changed; |
1793 | |
1794 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1795 putting it in history */ | |
1796 goto returncmd; /* back to cmd mode */ | |
1797 | |
1798 case Ctrl_R: /* insert register */ | |
1799 #ifdef USE_ON_FLY_SCROLL | |
1800 dont_scroll = TRUE; /* disallow scrolling here */ | |
1801 #endif | |
1802 putcmdline('"', TRUE); | |
1803 ++no_mapping; | |
1389 | 1804 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1805 if (i == Ctrl_O) |
1806 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1807 if (i == Ctrl_R) | |
1389 | 1808 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
|
1809 extra_char = NUL; |
7 | 1810 --no_mapping; |
1811 #ifdef FEAT_EVAL | |
1812 /* | |
1813 * Insert the result of an expression. | |
1814 * Need to save the current command line, to be able to enter | |
1815 * a new one... | |
1816 */ | |
1817 new_cmdpos = -1; | |
1818 if (c == '=') | |
1819 { | |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1820 if (ccline.cmdfirstc == '=' // can't do this recursively |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1821 || cmdline_star > 0) // or when typing a password |
7 | 1822 { |
1823 beep_flush(); | |
1824 c = ESC; | |
1825 } | |
1826 else | |
1827 c = get_expr_register(); | |
1828 } | |
1829 #endif | |
1830 if (c != ESC) /* use ESC to cancel inserting register */ | |
1831 { | |
1015 | 1832 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1833 |
613 | 1834 #ifdef FEAT_EVAL |
606 | 1835 /* When there was a serious error abort getting the |
1836 * command line. */ | |
1837 if (aborting()) | |
1838 { | |
1839 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1840 putting it in history */ | |
1841 goto returncmd; /* back to cmd mode */ | |
1842 } | |
613 | 1843 #endif |
7 | 1844 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1845 #ifdef FEAT_EVAL | |
1846 if (new_cmdpos >= 0) | |
1847 { | |
1848 /* set_cmdline_pos() was used */ | |
1849 if (new_cmdpos > ccline.cmdlen) | |
1850 ccline.cmdpos = ccline.cmdlen; | |
1851 else | |
1852 ccline.cmdpos = new_cmdpos; | |
1853 } | |
1854 #endif | |
1855 } | |
1856 redrawcmd(); | |
1857 goto cmdline_changed; | |
1858 | |
1859 case Ctrl_D: | |
1860 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1861 break; /* Use ^D as normal char instead */ | |
1862 | |
1863 redrawcmd(); | |
1864 continue; /* don't do incremental search now */ | |
1865 | |
1866 case K_RIGHT: | |
1867 case K_S_RIGHT: | |
1868 case K_C_RIGHT: | |
1869 do | |
1870 { | |
1871 if (ccline.cmdpos >= ccline.cmdlen) | |
1872 break; | |
1873 i = cmdline_charsize(ccline.cmdpos); | |
1874 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1875 break; | |
1876 ccline.cmdspos += i; | |
1877 #ifdef FEAT_MBYTE | |
1878 if (has_mbyte) | |
474 | 1879 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1880 + ccline.cmdpos); |
1881 else | |
1882 #endif | |
1883 ++ccline.cmdpos; | |
1884 } | |
180 | 1885 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1886 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1887 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1888 #ifdef FEAT_MBYTE | |
1889 if (has_mbyte) | |
1890 set_cmdspos_cursor(); | |
1891 #endif | |
1892 goto cmdline_not_changed; | |
1893 | |
1894 case K_LEFT: | |
1895 case K_S_LEFT: | |
1896 case K_C_LEFT: | |
1456 | 1897 if (ccline.cmdpos == 0) |
1898 goto cmdline_not_changed; | |
7 | 1899 do |
1900 { | |
1901 --ccline.cmdpos; | |
1902 #ifdef FEAT_MBYTE | |
1903 if (has_mbyte) /* move to first byte of char */ | |
1904 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1905 ccline.cmdbuff + ccline.cmdpos); | |
1906 #endif | |
1907 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1908 } | |
1456 | 1909 while (ccline.cmdpos > 0 |
1910 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1911 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1912 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1913 #ifdef FEAT_MBYTE | |
1914 if (has_mbyte) | |
1915 set_cmdspos_cursor(); | |
1916 #endif | |
1917 goto cmdline_not_changed; | |
1918 | |
1919 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
|
1920 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1921 goto cmdline_not_changed; |
7 | 1922 |
625 | 1923 #ifdef FEAT_GUI_W32 |
1924 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1925 * cancelled. */ | |
1926 case K_F4: | |
1927 if (mod_mask == MOD_MASK_ALT) | |
1928 { | |
1929 redrawcmd(); /* somehow the cmdline is cleared */ | |
1930 goto cmdline_not_changed; | |
1931 } | |
1932 break; | |
1933 #endif | |
1934 | |
7 | 1935 #ifdef FEAT_MOUSE |
1936 case K_MIDDLEDRAG: | |
1937 case K_MIDDLERELEASE: | |
1938 goto cmdline_not_changed; /* Ignore mouse */ | |
1939 | |
1940 case K_MIDDLEMOUSE: | |
1941 # ifdef FEAT_GUI | |
1942 /* When GUI is active, also paste when 'mouse' is empty */ | |
1943 if (!gui.in_use) | |
1944 # endif | |
1945 if (!mouse_has(MOUSE_COMMAND)) | |
1946 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1947 # ifdef FEAT_CLIPBOARD |
7 | 1948 if (clip_star.available) |
1015 | 1949 cmdline_paste('*', TRUE, TRUE); |
7 | 1950 else |
692 | 1951 # endif |
1015 | 1952 cmdline_paste(0, TRUE, TRUE); |
7 | 1953 redrawcmd(); |
1954 goto cmdline_changed; | |
1955 | |
692 | 1956 # ifdef FEAT_DND |
7 | 1957 case K_DROP: |
1015 | 1958 cmdline_paste('~', TRUE, FALSE); |
7 | 1959 redrawcmd(); |
1960 goto cmdline_changed; | |
692 | 1961 # endif |
7 | 1962 |
1963 case K_LEFTDRAG: | |
1964 case K_LEFTRELEASE: | |
1965 case K_RIGHTDRAG: | |
1966 case K_RIGHTRELEASE: | |
1967 /* Ignore drag and release events when the button-down wasn't | |
1968 * seen before. */ | |
1969 if (ignore_drag_release) | |
1970 goto cmdline_not_changed; | |
1971 /* FALLTHROUGH */ | |
1972 case K_LEFTMOUSE: | |
1973 case K_RIGHTMOUSE: | |
1974 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1975 ignore_drag_release = TRUE; | |
1976 else | |
1977 ignore_drag_release = FALSE; | |
1978 # ifdef FEAT_GUI | |
1979 /* When GUI is active, also move when 'mouse' is empty */ | |
1980 if (!gui.in_use) | |
1981 # endif | |
1982 if (!mouse_has(MOUSE_COMMAND)) | |
1983 goto cmdline_not_changed; /* Ignore mouse */ | |
1984 # ifdef FEAT_CLIPBOARD | |
1985 if (mouse_row < cmdline_row && clip_star.available) | |
1986 { | |
1987 int button, is_click, is_drag; | |
1988 | |
1989 /* | |
1990 * Handle modeless selection. | |
1991 */ | |
1992 button = get_mouse_button(KEY2TERMCAP1(c), | |
1993 &is_click, &is_drag); | |
1994 if (mouse_model_popup() && button == MOUSE_LEFT | |
1995 && (mod_mask & MOD_MASK_SHIFT)) | |
1996 { | |
1997 /* Translate shift-left to right button. */ | |
1998 button = MOUSE_RIGHT; | |
1999 mod_mask &= ~MOD_MASK_SHIFT; | |
2000 } | |
2001 clip_modeless(button, is_click, is_drag); | |
2002 goto cmdline_not_changed; | |
2003 } | |
2004 # endif | |
2005 | |
2006 set_cmdspos(); | |
2007 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
2008 ++ccline.cmdpos) | |
2009 { | |
2010 i = cmdline_charsize(ccline.cmdpos); | |
2011 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
2012 && mouse_col < ccline.cmdspos % Columns + i) | |
2013 break; | |
692 | 2014 # ifdef FEAT_MBYTE |
7 | 2015 if (has_mbyte) |
2016 { | |
2017 /* Count ">" for double-wide char that doesn't fit. */ | |
2018 correct_cmdspos(ccline.cmdpos, i); | |
474 | 2019 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 2020 + ccline.cmdpos) - 1; |
2021 } | |
692 | 2022 # endif |
7 | 2023 ccline.cmdspos += i; |
2024 } | |
2025 goto cmdline_not_changed; | |
2026 | |
2027 /* Mouse scroll wheel: ignored here */ | |
2028 case K_MOUSEDOWN: | |
2029 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2030 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2031 case K_MOUSERIGHT: |
7 | 2032 /* Alternate buttons ignored here */ |
2033 case K_X1MOUSE: | |
2034 case K_X1DRAG: | |
2035 case K_X1RELEASE: | |
2036 case K_X2MOUSE: | |
2037 case K_X2DRAG: | |
2038 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2039 case K_MOUSEMOVE: |
7 | 2040 goto cmdline_not_changed; |
2041 | |
2042 #endif /* FEAT_MOUSE */ | |
2043 | |
2044 #ifdef FEAT_GUI | |
2045 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2046 case K_LEFTRELEASE_NM: | |
2047 goto cmdline_not_changed; | |
2048 | |
2049 case K_VER_SCROLLBAR: | |
540 | 2050 if (msg_scrolled == 0) |
7 | 2051 { |
2052 gui_do_scroll(); | |
2053 redrawcmd(); | |
2054 } | |
2055 goto cmdline_not_changed; | |
2056 | |
2057 case K_HOR_SCROLLBAR: | |
540 | 2058 if (msg_scrolled == 0) |
7 | 2059 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2060 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2061 redrawcmd(); |
2062 } | |
2063 goto cmdline_not_changed; | |
2064 #endif | |
692 | 2065 #ifdef FEAT_GUI_TABLINE |
2066 case K_TABLINE: | |
2067 case K_TABMENU: | |
2068 /* Don't want to change any tabs here. Make sure the same tab | |
2069 * is still selected. */ | |
2070 if (gui_use_tabline()) | |
2071 gui_mch_set_curtab(tabpage_index(curtab)); | |
2072 goto cmdline_not_changed; | |
2073 #endif | |
2074 | |
7 | 2075 case K_SELECT: /* end of Select mode mapping - ignore */ |
2076 goto cmdline_not_changed; | |
2077 | |
2078 case Ctrl_B: /* begin of command line */ | |
2079 case K_HOME: | |
2080 case K_KHOME: | |
2081 case K_S_HOME: | |
2082 case K_C_HOME: | |
2083 ccline.cmdpos = 0; | |
2084 set_cmdspos(); | |
2085 goto cmdline_not_changed; | |
2086 | |
2087 case Ctrl_E: /* end of command line */ | |
2088 case K_END: | |
2089 case K_KEND: | |
2090 case K_S_END: | |
2091 case K_C_END: | |
2092 ccline.cmdpos = ccline.cmdlen; | |
2093 set_cmdspos_cursor(); | |
2094 goto cmdline_not_changed; | |
2095 | |
2096 case Ctrl_A: /* all matches */ | |
3961 | 2097 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2098 break; |
2099 goto cmdline_changed; | |
2100 | |
772 | 2101 case Ctrl_L: |
2102 #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
|
2103 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2104 goto cmdline_not_changed; |
2105 #endif | |
2106 | |
2107 /* completion: longest common part */ | |
3961 | 2108 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2109 break; |
2110 goto cmdline_changed; | |
2111 | |
2112 case Ctrl_N: /* next match */ | |
2113 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2114 if (xpc.xp_numfiles > 0) |
7 | 2115 { |
3961 | 2116 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2117 0, firstc != '@') == FAIL) | |
7 | 2118 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2119 goto cmdline_not_changed; |
7 | 2120 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2121 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2122 /* FALLTHROUGH */ |
7 | 2123 case K_UP: |
2124 case K_DOWN: | |
2125 case K_S_UP: | |
2126 case K_S_DOWN: | |
2127 case K_PAGEUP: | |
2128 case K_KPAGEUP: | |
2129 case K_PAGEDOWN: | |
2130 case K_KPAGEDOWN: | |
2131 if (hislen == 0 || firstc == NUL) /* no history */ | |
2132 goto cmdline_not_changed; | |
2133 | |
2134 i = hiscnt; | |
2135 | |
2136 /* save current command string so it can be restored later */ | |
2137 if (lookfor == NULL) | |
2138 { | |
2139 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2140 goto cmdline_not_changed; | |
2141 lookfor[ccline.cmdpos] = NUL; | |
2142 } | |
2143 | |
2144 j = (int)STRLEN(lookfor); | |
2145 for (;;) | |
2146 { | |
2147 /* one step backwards */ | |
230 | 2148 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2149 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2150 { |
2151 if (hiscnt == hislen) /* first time */ | |
2152 hiscnt = hisidx[histype]; | |
2153 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2154 hiscnt = hislen - 1; | |
2155 else if (hiscnt != hisidx[histype] + 1) | |
2156 --hiscnt; | |
2157 else /* at top of list */ | |
2158 { | |
2159 hiscnt = i; | |
2160 break; | |
2161 } | |
2162 } | |
2163 else /* one step forwards */ | |
2164 { | |
2165 /* on last entry, clear the line */ | |
2166 if (hiscnt == hisidx[histype]) | |
2167 { | |
2168 hiscnt = hislen; | |
2169 break; | |
2170 } | |
2171 | |
2172 /* not on a history line, nothing to do */ | |
2173 if (hiscnt == hislen) | |
2174 break; | |
2175 if (hiscnt == hislen - 1) /* wrap around */ | |
2176 hiscnt = 0; | |
2177 else | |
2178 ++hiscnt; | |
2179 } | |
2180 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2181 { | |
2182 hiscnt = i; | |
2183 break; | |
2184 } | |
230 | 2185 if ((c != K_UP && c != K_DOWN) |
180 | 2186 || hiscnt == i |
7 | 2187 || STRNCMP(history[histype][hiscnt].hisstr, |
2188 lookfor, (size_t)j) == 0) | |
2189 break; | |
2190 } | |
2191 | |
2192 if (hiscnt != i) /* jumped to other entry */ | |
2193 { | |
2194 char_u *p; | |
2195 int len; | |
2196 int old_firstc; | |
2197 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2198 VIM_CLEAR(ccline.cmdbuff); |
1718 | 2199 xpc.xp_context = EXPAND_NOTHING; |
7 | 2200 if (hiscnt == hislen) |
2201 p = lookfor; /* back to the old one */ | |
2202 else | |
2203 p = history[histype][hiscnt].hisstr; | |
2204 | |
2205 if (histype == HIST_SEARCH | |
2206 && p != lookfor | |
2207 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2208 { | |
2209 /* Correct for the separator character used when | |
2210 * adding the history entry vs the one used now. | |
2211 * First loop: count length. | |
2212 * Second loop: copy the characters. */ | |
2213 for (i = 0; i <= 1; ++i) | |
2214 { | |
2215 len = 0; | |
2216 for (j = 0; p[j] != NUL; ++j) | |
2217 { | |
2218 /* Replace old sep with new sep, unless it is | |
2219 * escaped. */ | |
2220 if (p[j] == old_firstc | |
2221 && (j == 0 || p[j - 1] != '\\')) | |
2222 { | |
2223 if (i > 0) | |
2224 ccline.cmdbuff[len] = firstc; | |
2225 } | |
2226 else | |
2227 { | |
2228 /* Escape new sep, unless it is already | |
2229 * escaped. */ | |
2230 if (p[j] == firstc | |
2231 && (j == 0 || p[j - 1] != '\\')) | |
2232 { | |
2233 if (i > 0) | |
2234 ccline.cmdbuff[len] = '\\'; | |
2235 ++len; | |
2236 } | |
2237 if (i > 0) | |
2238 ccline.cmdbuff[len] = p[j]; | |
2239 } | |
2240 ++len; | |
2241 } | |
2242 if (i == 0) | |
2243 { | |
2244 alloc_cmdbuff(len); | |
2245 if (ccline.cmdbuff == NULL) | |
2246 goto returncmd; | |
2247 } | |
2248 } | |
2249 ccline.cmdbuff[len] = NUL; | |
2250 } | |
2251 else | |
2252 { | |
2253 alloc_cmdbuff((int)STRLEN(p)); | |
2254 if (ccline.cmdbuff == NULL) | |
2255 goto returncmd; | |
2256 STRCPY(ccline.cmdbuff, p); | |
2257 } | |
2258 | |
2259 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2260 redrawcmd(); | |
2261 goto cmdline_changed; | |
2262 } | |
2263 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2264 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2265 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2266 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2267 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2268 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2269 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
|
2270 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
|
2271 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
|
2272 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2273 break; |
7 | 2274 #endif |
2275 | |
2276 case Ctrl_V: | |
2277 case Ctrl_Q: | |
2278 #ifdef FEAT_MOUSE | |
2279 ignore_drag_release = TRUE; | |
2280 #endif | |
2281 putcmdline('^', TRUE); | |
2282 c = get_literal(); /* get next (two) character(s) */ | |
2283 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
|
2284 extra_char = NUL; |
7 | 2285 #ifdef FEAT_MBYTE |
2286 /* may need to remove ^ when composing char was typed */ | |
2287 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2288 { | |
2289 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2290 msg_putchar(' '); | |
2291 cursorcmd(); | |
2292 } | |
2293 #endif | |
2294 break; | |
2295 | |
2296 #ifdef FEAT_DIGRAPHS | |
2297 case Ctrl_K: | |
2298 #ifdef FEAT_MOUSE | |
2299 ignore_drag_release = TRUE; | |
2300 #endif | |
2301 putcmdline('?', TRUE); | |
2302 #ifdef USE_ON_FLY_SCROLL | |
2303 dont_scroll = TRUE; /* disallow scrolling here */ | |
2304 #endif | |
2305 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
|
2306 extra_char = NUL; |
7 | 2307 if (c != NUL) |
2308 break; | |
2309 | |
2310 redrawcmd(); | |
2311 goto cmdline_not_changed; | |
2312 #endif /* FEAT_DIGRAPHS */ | |
2313 | |
2314 #ifdef FEAT_RIGHTLEFT | |
2315 case Ctrl__: /* CTRL-_: switch language mode */ | |
2316 if (!p_ari) | |
2317 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2318 # ifdef FEAT_FKMAP |
7 | 2319 if (p_altkeymap) |
2320 { | |
2321 cmd_fkmap = !cmd_fkmap; | |
2322 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2323 ccline.overstrike = FALSE; | |
2324 } | |
2325 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2326 # endif |
7 | 2327 cmd_hkmap = !cmd_hkmap; |
2328 goto cmdline_not_changed; | |
2329 #endif | |
2330 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2331 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
|
2332 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
|
2333 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
|
2334 |
7 | 2335 default: |
2336 #ifdef UNIX | |
2337 if (c == intr_char) | |
2338 { | |
2339 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2340 putting it in history */ | |
2341 goto returncmd; /* back to Normal mode */ | |
2342 } | |
2343 #endif | |
2344 /* | |
2345 * Normal character with no special meaning. Just set mod_mask | |
2346 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2347 * the string <S-Space>. This should only happen after ^V. | |
2348 */ | |
2349 if (!IS_SPECIAL(c)) | |
2350 mod_mask = 0x0; | |
2351 break; | |
2352 } | |
2353 /* | |
2354 * End of switch on command line character. | |
2355 * We come here if we have a normal character. | |
2356 */ | |
2357 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2358 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2359 #ifdef FEAT_MBYTE |
2360 /* Add ABBR_OFF for characters above 0x100, this is | |
2361 * what check_abbr() expects. */ | |
2362 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2363 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2364 c) || c == Ctrl_RSB)) |
7 | 2365 goto cmdline_changed; |
2366 | |
2367 /* | |
2368 * put the character in the command line | |
2369 */ | |
2370 if (IS_SPECIAL(c) || mod_mask != 0) | |
2371 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2372 else | |
2373 { | |
2374 #ifdef FEAT_MBYTE | |
2375 if (has_mbyte) | |
2376 { | |
2377 j = (*mb_char2bytes)(c, IObuff); | |
2378 IObuff[j] = NUL; /* exclude composing chars */ | |
2379 put_on_cmdline(IObuff, j, TRUE); | |
2380 } | |
2381 else | |
2382 #endif | |
2383 { | |
2384 IObuff[0] = c; | |
2385 put_on_cmdline(IObuff, 1, TRUE); | |
2386 } | |
2387 } | |
2388 goto cmdline_changed; | |
2389 | |
2390 /* | |
2391 * This part implements incremental searches for "/" and "?" | |
2392 * Jump to cmdline_not_changed when a character has been read but the command | |
2393 * line did not change. Then we only search and redraw if something changed in | |
2394 * the past. | |
2395 * Jump to cmdline_changed when the command line did change. | |
2396 * (Sorry for the goto's, I know it is ugly). | |
2397 */ | |
2398 cmdline_not_changed: | |
2399 #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
|
2400 if (!is_state.incsearch_postponed) |
7 | 2401 continue; |
2402 #endif | |
2403 | |
2404 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
|
2405 /* 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
|
2406 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
|
2407 |
7 | 2408 #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
|
2409 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2410 #endif |
2411 | |
2412 #ifdef FEAT_RIGHTLEFT | |
2413 if (cmdmsg_rl | |
2414 # ifdef FEAT_ARABIC | |
534 | 2415 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2416 # endif |
2417 ) | |
2418 /* Always redraw the whole command line to fix shaping and | |
3374 | 2419 * right-left typing. Not efficient, but it works. |
2420 * Do it only when there are no characters left to read | |
2421 * to avoid useless intermediate redraws. */ | |
2422 if (vpeekc() == NUL) | |
2423 redrawcmd(); | |
7 | 2424 #endif |
2425 } | |
2426 | |
2427 returncmd: | |
2428 | |
2429 #ifdef FEAT_RIGHTLEFT | |
2430 cmdmsg_rl = FALSE; | |
2431 #endif | |
2432 | |
2433 #ifdef FEAT_FKMAP | |
2434 cmd_fkmap = 0; | |
2435 #endif | |
2436 | |
2437 ExpandCleanup(&xpc); | |
1718 | 2438 ccline.xpc = NULL; |
7 | 2439 |
2440 #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
|
2441 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2442 #endif |
2443 | |
2444 if (ccline.cmdbuff != NULL) | |
2445 { | |
2446 /* | |
2447 * Put line in history buffer (":" and "=" only when it was typed). | |
2448 */ | |
2449 #ifdef FEAT_CMDHIST | |
2450 if (ccline.cmdlen && firstc != NUL | |
2451 && (some_key_typed || histype == HIST_SEARCH)) | |
2452 { | |
2453 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2454 histype == HIST_SEARCH ? firstc : NUL); | |
2455 if (firstc == ':') | |
2456 { | |
2457 vim_free(new_last_cmdline); | |
2458 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2459 } | |
2460 } | |
2461 #endif | |
2462 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2463 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
|
2464 abandon_cmdline(); |
7 | 2465 } |
2466 | |
2467 /* | |
2468 * If the screen was shifted up, redraw the whole screen (later). | |
2469 * If the line is too long, clear it, so ruler and shown command do | |
2470 * not get printed in the middle of it. | |
2471 */ | |
2472 msg_check(); | |
2473 msg_scroll = save_msg_scroll; | |
2474 redir_off = FALSE; | |
2475 | |
2476 /* When the command line was typed, no need for a wait-return prompt. */ | |
2477 if (some_key_typed) | |
2478 need_wait_return = FALSE; | |
2479 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2480 /* 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
|
2481 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
|
2482 |
7 | 2483 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2484 #ifdef HAVE_INPUT_METHOD |
7 | 2485 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2486 im_save_status(b_im_ptr); | |
2487 im_set_active(FALSE); | |
2488 #endif | |
2489 #ifdef FEAT_MOUSE | |
2490 setmouse(); | |
2491 #endif | |
2492 #ifdef CURSOR_SHAPE | |
2493 ui_cursor_shape(); /* may show different cursor shape */ | |
2494 #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
|
2495 sb_text_end_cmdline(); |
7 | 2496 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2497 theend: |
95 | 2498 { |
2499 char_u *p = ccline.cmdbuff; | |
2500 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2501 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2502 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2503 else |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2504 ccline.cmdbuff = NULL; |
95 | 2505 return p; |
2506 } | |
7 | 2507 } |
2508 | |
2509 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2510 /* | |
2511 * Get a command line with a prompt. | |
2512 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2513 * f_input() when evaluating an expression from CTRL-R =). | |
2514 * Returns the command line in allocated memory, or NULL. | |
2515 */ | |
2516 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2517 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2518 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2519 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2520 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2521 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2522 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2523 { |
2524 char_u *s; | |
2525 struct cmdline_info save_ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2526 int did_save_ccline = FALSE; |
7 | 2527 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
|
2528 int msg_silent_save = msg_silent; |
7 | 2529 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2530 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2531 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2532 // Save the values of the current cmdline and restore them below. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2533 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2534 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2535 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2536 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2537 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
7 | 2538 ccline.cmdprompt = prompt; |
2539 ccline.cmdattr = attr; | |
531 | 2540 # ifdef FEAT_EVAL |
2541 ccline.xp_context = xp_context; | |
2542 ccline.xp_arg = xp_arg; | |
2543 ccline.input_fn = (firstc == '@'); | |
2544 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2545 msg_silent = 0; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2546 s = getcmdline_int(firstc, 1L, 0, FALSE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2547 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2548 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2549 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2550 |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2551 msg_silent = msg_silent_save; |
3020 | 2552 /* Restore msg_col, the prompt from input() may have changed it. |
2553 * But only if called recursively and the commandline is therefore being | |
2554 * restored to an old one; if not, the input() prompt stays on the screen, | |
2555 * so we need its modified msg_col left intact. */ | |
2556 if (ccline.cmdbuff != NULL) | |
2557 msg_col = msg_col_save; | |
7 | 2558 |
2559 return s; | |
2560 } | |
2561 #endif | |
2562 | |
632 | 2563 /* |
634 | 2564 * Return TRUE when the text must not be changed and we can't switch to |
2565 * another window or buffer. Used when editing the command line, evaluating | |
2566 * 'balloonexpr', etc. | |
632 | 2567 */ |
2568 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2569 text_locked(void) |
632 | 2570 { |
2571 #ifdef FEAT_CMDWIN | |
2572 if (cmdwin_type != 0) | |
2573 return TRUE; | |
2574 #endif | |
634 | 2575 return textlock != 0; |
632 | 2576 } |
2577 | |
2578 /* | |
2579 * Give an error message for a command that isn't allowed while the cmdline | |
2580 * window is open or editing the cmdline in another way. | |
2581 */ | |
2582 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2583 text_locked_msg(void) |
632 | 2584 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2585 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2586 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2587 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2588 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2589 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2590 { |
632 | 2591 #ifdef FEAT_CMDWIN |
2592 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2593 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2594 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2595 return e_secure; |
632 | 2596 } |
2597 | |
819 | 2598 /* |
1834 | 2599 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2600 * and give an error message. | |
819 | 2601 */ |
2602 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2603 curbuf_locked(void) |
819 | 2604 { |
2605 if (curbuf_lock > 0) | |
2606 { | |
2607 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2608 return TRUE; | |
2609 } | |
1834 | 2610 return allbuf_locked(); |
2611 } | |
2612 | |
2613 /* | |
2614 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2615 * message. | |
2616 */ | |
2617 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2618 allbuf_locked(void) |
1834 | 2619 { |
2620 if (allbuf_lock > 0) | |
2621 { | |
2622 EMSG(_("E811: Not allowed to change buffer information now")); | |
2623 return TRUE; | |
2624 } | |
819 | 2625 return FALSE; |
2626 } | |
2627 | |
7 | 2628 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2629 cmdline_charsize(int idx) |
7 | 2630 { |
2631 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2632 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2633 return 1; | |
2634 #endif | |
2635 return ptr2cells(ccline.cmdbuff + idx); | |
2636 } | |
2637 | |
2638 /* | |
2639 * Compute the offset of the cursor on the command line for the prompt and | |
2640 * indent. | |
2641 */ | |
2642 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2643 set_cmdspos(void) |
7 | 2644 { |
531 | 2645 if (ccline.cmdfirstc != NUL) |
7 | 2646 ccline.cmdspos = 1 + ccline.cmdindent; |
2647 else | |
2648 ccline.cmdspos = 0 + ccline.cmdindent; | |
2649 } | |
2650 | |
2651 /* | |
2652 * Compute the screen position for the cursor on the command line. | |
2653 */ | |
2654 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2655 set_cmdspos_cursor(void) |
7 | 2656 { |
2657 int i, m, c; | |
2658 | |
2659 set_cmdspos(); | |
2660 if (KeyTyped) | |
534 | 2661 { |
7 | 2662 m = Columns * Rows; |
534 | 2663 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2664 m = MAXCOL; | |
2665 } | |
7 | 2666 else |
2667 m = MAXCOL; | |
2668 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2669 { | |
2670 c = cmdline_charsize(i); | |
2671 #ifdef FEAT_MBYTE | |
2672 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2673 if (has_mbyte) | |
2674 correct_cmdspos(i, c); | |
2675 #endif | |
1612 | 2676 /* If the cmdline doesn't fit, show cursor on last visible char. |
2677 * Don't move the cursor itself, so we can still append. */ | |
7 | 2678 if ((ccline.cmdspos += c) >= m) |
2679 { | |
2680 ccline.cmdspos -= c; | |
2681 break; | |
2682 } | |
2683 #ifdef FEAT_MBYTE | |
2684 if (has_mbyte) | |
474 | 2685 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2686 #endif |
2687 } | |
2688 } | |
2689 | |
2690 #ifdef FEAT_MBYTE | |
2691 /* | |
2692 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2693 * character that doesn't fit, so that a ">" must be displayed. | |
2694 */ | |
2695 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2696 correct_cmdspos(int idx, int cells) |
7 | 2697 { |
474 | 2698 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2699 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2700 && ccline.cmdspos % Columns + cells > Columns) | |
2701 ccline.cmdspos++; | |
2702 } | |
2703 #endif | |
2704 | |
2705 /* | |
2706 * Get an Ex command line for the ":" command. | |
2707 */ | |
2708 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2709 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2710 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2711 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2712 int indent) /* indent for inside conditionals */ |
7 | 2713 { |
2714 /* When executing a register, remove ':' that's in front of each line. */ | |
2715 if (exec_from_reg && vpeekc() == ':') | |
2716 (void)vgetc(); | |
2717 return getcmdline(c, 1L, indent); | |
2718 } | |
2719 | |
2720 /* | |
2721 * Get an Ex command line for Ex mode. | |
2722 * In Ex mode we only use the OS supplied line editing features and no | |
2723 * mappings or abbreviations. | |
168 | 2724 * Returns a string in allocated memory or NULL. |
7 | 2725 */ |
2726 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2727 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2728 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2729 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2730 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2731 int indent) /* indent for inside conditionals */ |
7 | 2732 { |
168 | 2733 garray_T line_ga; |
2734 char_u *pend; | |
2735 int startcol = 0; | |
1329 | 2736 int c1 = 0; |
168 | 2737 int escaped = FALSE; /* CTRL-V typed */ |
2738 int vcol = 0; | |
2739 char_u *p; | |
1329 | 2740 int prev_char; |
5966 | 2741 int len; |
7 | 2742 |
2743 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2744 * confuses the system function that computes tabstops. */ | |
2745 cursor_on(); | |
2746 | |
2747 /* always start in column 0; write a newline if necessary */ | |
2748 compute_cmdrow(); | |
168 | 2749 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2750 msg_putchar('\n'); |
168 | 2751 if (promptc == ':') |
7 | 2752 { |
164 | 2753 /* indent that is only displayed, not in the line itself */ |
168 | 2754 if (p_prompt) |
2755 msg_putchar(':'); | |
7 | 2756 while (indent-- > 0) |
2757 msg_putchar(' '); | |
2758 startcol = msg_col; | |
2759 } | |
2760 | |
2761 ga_init2(&line_ga, 1, 30); | |
2762 | |
164 | 2763 /* autoindent for :insert and :append is in the line itself */ |
168 | 2764 if (promptc <= 0) |
164 | 2765 { |
2766 vcol = indent; | |
2767 while (indent >= 8) | |
2768 { | |
2769 ga_append(&line_ga, TAB); | |
2770 msg_puts((char_u *)" "); | |
2771 indent -= 8; | |
2772 } | |
2773 while (indent-- > 0) | |
2774 { | |
2775 ga_append(&line_ga, ' '); | |
2776 msg_putchar(' '); | |
2777 } | |
2778 } | |
168 | 2779 ++no_mapping; |
2780 ++allow_keys; | |
164 | 2781 |
7 | 2782 /* |
2783 * Get the line, one character at a time. | |
2784 */ | |
2785 got_int = FALSE; | |
168 | 2786 while (!got_int) |
7 | 2787 { |
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
|
2788 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
|
2789 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
|
2790 |
7 | 2791 if (ga_grow(&line_ga, 40) == FAIL) |
2792 break; | |
2793 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2794 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2795 * 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
|
2796 */ |
1329 | 2797 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
|
2798 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2799 /* 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
|
2800 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
|
2801 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
|
2802 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2803 c1 = vgetc(); |
7 | 2804 |
2805 /* | |
168 | 2806 * Handle line editing. |
2807 * Previously this was left to the system, putting the terminal in | |
2808 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2809 */ |
168 | 2810 if (got_int) |
2811 { | |
2812 msg_putchar('\n'); | |
2813 break; | |
2814 } | |
2815 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2816 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
|
2817 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2818 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
|
2819 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
|
2820 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2821 |
168 | 2822 if (!escaped) |
7 | 2823 { |
168 | 2824 /* CR typed means "enter", which is NL */ |
2825 if (c1 == '\r') | |
2826 c1 = '\n'; | |
2827 | |
2828 if (c1 == BS || c1 == K_BS | |
2829 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2830 { |
168 | 2831 if (line_ga.ga_len > 0) |
2832 { | |
5966 | 2833 #ifdef FEAT_MBYTE |
2834 if (has_mbyte) | |
2835 { | |
2836 p = (char_u *)line_ga.ga_data; | |
2837 p[line_ga.ga_len] = NUL; | |
2838 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2839 line_ga.ga_len -= len; | |
2840 } | |
2841 else | |
2842 #endif | |
2843 --line_ga.ga_len; | |
168 | 2844 goto redraw; |
2845 } | |
2846 continue; | |
7 | 2847 } |
2848 | |
168 | 2849 if (c1 == Ctrl_U) |
7 | 2850 { |
168 | 2851 msg_col = startcol; |
2852 msg_clr_eos(); | |
2853 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
|
2854 goto redraw; |
168 | 2855 } |
2856 | |
2857 if (c1 == Ctrl_T) | |
2858 { | |
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
|
2859 sw = get_sw_value(curbuf); |
168 | 2860 p = (char_u *)line_ga.ga_data; |
2861 p[line_ga.ga_len] = NUL; | |
5995 | 2862 indent = get_indent_str(p, 8, FALSE); |
3740 | 2863 indent += sw - indent % sw; |
168 | 2864 add_indent: |
5995 | 2865 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2866 { |
7009 | 2867 (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
|
2868 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
|
2869 s = skipwhite(p); |
168 | 2870 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2871 *s = ' '; | |
2872 ++line_ga.ga_len; | |
7 | 2873 } |
168 | 2874 redraw: |
2875 /* redraw the line */ | |
2876 msg_col = startcol; | |
2877 vcol = 0; | |
5966 | 2878 p = (char_u *)line_ga.ga_data; |
2879 p[line_ga.ga_len] = NUL; | |
2880 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2881 { |
168 | 2882 if (*p == TAB) |
7 | 2883 { |
168 | 2884 do |
7 | 2885 { |
168 | 2886 msg_putchar(' '); |
2887 } while (++vcol % 8); | |
5966 | 2888 ++p; |
7 | 2889 } |
168 | 2890 else |
164 | 2891 { |
5966 | 2892 len = MB_PTR2LEN(p); |
2893 msg_outtrans_len(p, len); | |
2894 vcol += ptr2cells(p); | |
2895 p += len; | |
7 | 2896 } |
2897 } | |
168 | 2898 msg_clr_eos(); |
1329 | 2899 windgoto(msg_row, msg_col); |
168 | 2900 continue; |
2901 } | |
2902 | |
2903 if (c1 == Ctrl_D) | |
2904 { | |
2905 /* Delete one shiftwidth. */ | |
2906 p = (char_u *)line_ga.ga_data; | |
2907 if (prev_char == '0' || prev_char == '^') | |
7 | 2908 { |
168 | 2909 if (prev_char == '^') |
2910 ex_keep_indent = TRUE; | |
2911 indent = 0; | |
2912 p[--line_ga.ga_len] = NUL; | |
7 | 2913 } |
2914 else | |
2915 { | |
168 | 2916 p[line_ga.ga_len] = NUL; |
5995 | 2917 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
|
2918 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
|
2919 { |
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
|
2920 --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
|
2921 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
|
2922 } |
168 | 2923 } |
5995 | 2924 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2925 { |
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
|
2926 s = skipwhite(p); |
168 | 2927 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2928 --line_ga.ga_len; | |
7 | 2929 } |
168 | 2930 goto add_indent; |
2931 } | |
2932 | |
2933 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2934 { | |
2935 escaped = TRUE; | |
2936 continue; | |
7 | 2937 } |
168 | 2938 |
2939 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2940 if (IS_SPECIAL(c1)) | |
2941 continue; | |
7 | 2942 } |
168 | 2943 |
2944 if (IS_SPECIAL(c1)) | |
2945 c1 = '?'; | |
5966 | 2946 #ifdef FEAT_MBYTE |
2947 if (has_mbyte) | |
2948 len = (*mb_char2bytes)(c1, | |
2949 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2950 else | |
2951 #endif | |
2952 { | |
2953 len = 1; | |
2954 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2955 } | |
168 | 2956 if (c1 == '\n') |
2957 msg_putchar('\n'); | |
2958 else if (c1 == TAB) | |
2959 { | |
2960 /* Don't use chartabsize(), 'ts' can be different */ | |
2961 do | |
2962 { | |
2963 msg_putchar(' '); | |
2964 } while (++vcol % 8); | |
2965 } | |
7 | 2966 else |
2967 { | |
168 | 2968 msg_outtrans_len( |
5966 | 2969 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2970 vcol += char2cells(c1); |
7 | 2971 } |
5966 | 2972 line_ga.ga_len += len; |
168 | 2973 escaped = FALSE; |
2974 | |
2975 windgoto(msg_row, msg_col); | |
164 | 2976 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2977 |
2590 | 2978 /* We are done when a NL is entered, but not when it comes after an |
2979 * odd number of backslashes, that results in a NUL. */ | |
2980 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2981 { |
2590 | 2982 int bcount = 0; |
2983 | |
2984 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2985 ++bcount; | |
2986 | |
2987 if (bcount > 0) | |
2988 { | |
2989 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2990 * "\NL", etc. */ | |
2991 line_ga.ga_len -= (bcount + 1) / 2; | |
2992 pend -= (bcount + 1) / 2; | |
2993 pend[-1] = '\n'; | |
2994 } | |
2995 | |
2996 if ((bcount & 1) == 0) | |
2997 { | |
2998 --line_ga.ga_len; | |
2999 --pend; | |
3000 *pend = NUL; | |
3001 break; | |
3002 } | |
7 | 3003 } |
3004 } | |
3005 | |
168 | 3006 --no_mapping; |
3007 --allow_keys; | |
3008 | |
7 | 3009 /* make following messages go to the next line */ |
3010 msg_didout = FALSE; | |
3011 msg_col = 0; | |
3012 if (msg_row < Rows - 1) | |
3013 ++msg_row; | |
3014 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
3015 | |
3016 if (got_int) | |
3017 ga_clear(&line_ga); | |
3018 | |
3019 return (char_u *)line_ga.ga_data; | |
3020 } | |
3021 | |
502 | 3022 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
3023 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 3024 /* |
3025 * Return TRUE if ccline.overstrike is on. | |
3026 */ | |
3027 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3028 cmdline_overstrike(void) |
7 | 3029 { |
3030 return ccline.overstrike; | |
3031 } | |
3032 | |
3033 /* | |
3034 * Return TRUE if the cursor is at the end of the cmdline. | |
3035 */ | |
3036 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3037 cmdline_at_end(void) |
7 | 3038 { |
3039 return (ccline.cmdpos >= ccline.cmdlen); | |
3040 } | |
3041 #endif | |
3042 | |
574 | 3043 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 3044 /* |
3045 * Return the virtual column number at the current cursor position. | |
3046 * This is used by the IM code to obtain the start of the preedit string. | |
3047 */ | |
3048 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3049 cmdline_getvcol_cursor(void) |
7 | 3050 { |
3051 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3052 return MAXCOL; | |
3053 | |
3054 # ifdef FEAT_MBYTE | |
3055 if (has_mbyte) | |
3056 { | |
3057 colnr_T col; | |
3058 int i = 0; | |
3059 | |
3060 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3061 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3062 |
3063 return col; | |
3064 } | |
3065 else | |
3066 # endif | |
3067 return ccline.cmdpos; | |
3068 } | |
3069 #endif | |
3070 | |
3071 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3072 /* | |
3073 * If part of the command line is an IM preedit string, redraw it with | |
3074 * IM feedback attributes. The cursor position is restored after drawing. | |
3075 */ | |
3076 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3077 redrawcmd_preedit(void) |
7 | 3078 { |
3079 if ((State & CMDLINE) | |
3080 && xic != NULL | |
976 | 3081 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3082 && !p_imdisable |
3083 && im_is_preediting()) | |
3084 { | |
3085 int cmdpos = 0; | |
3086 int cmdspos; | |
3087 int old_row; | |
3088 int old_col; | |
3089 colnr_T col; | |
3090 | |
3091 old_row = msg_row; | |
3092 old_col = msg_col; | |
531 | 3093 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3094 |
3095 # ifdef FEAT_MBYTE | |
3096 if (has_mbyte) | |
3097 { | |
3098 for (col = 0; col < preedit_start_col | |
3099 && cmdpos < ccline.cmdlen; ++col) | |
3100 { | |
3101 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3102 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3103 } |
3104 } | |
3105 else | |
3106 # endif | |
3107 { | |
3108 cmdspos += preedit_start_col; | |
3109 cmdpos += preedit_start_col; | |
3110 } | |
3111 | |
3112 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3113 msg_col = cmdspos % (int)Columns; | |
3114 if (msg_row >= Rows) | |
3115 msg_row = Rows - 1; | |
3116 | |
3117 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3118 { | |
3119 int char_len; | |
3120 int char_attr; | |
3121 | |
3122 char_attr = im_get_feedback_attr(col); | |
3123 if (char_attr < 0) | |
3124 break; /* end of preedit string */ | |
3125 | |
3126 # ifdef FEAT_MBYTE | |
3127 if (has_mbyte) | |
474 | 3128 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3129 else |
3130 # endif | |
3131 char_len = 1; | |
3132 | |
3133 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3134 cmdpos += char_len; | |
3135 } | |
3136 | |
3137 msg_row = old_row; | |
3138 msg_col = old_col; | |
3139 } | |
3140 } | |
3141 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3142 | |
3143 /* | |
3144 * Allocate a new command line buffer. | |
3145 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3146 */ | |
3147 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3148 alloc_cmdbuff(int len) |
7 | 3149 { |
3150 /* | |
3151 * give some extra space to avoid having to allocate all the time | |
3152 */ | |
3153 if (len < 80) | |
3154 len = 100; | |
3155 else | |
3156 len += 20; | |
3157 | |
3158 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3159 ccline.cmdbufflen = len; | |
3160 } | |
3161 | |
3162 /* | |
3163 * Re-allocate the command line to length len + something extra. | |
3164 * return FAIL for failure, OK otherwise | |
3165 */ | |
3166 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3167 realloc_cmdbuff(int len) |
7 | 3168 { |
3169 char_u *p; | |
3170 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3171 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3172 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
|
3173 |
7 | 3174 p = ccline.cmdbuff; |
3175 alloc_cmdbuff(len); /* will get some more */ | |
3176 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3177 { | |
3178 ccline.cmdbuff = p; /* keep the old one */ | |
3179 return FAIL; | |
3180 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3181 /* 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
|
3182 * 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
|
3183 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
|
3184 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3185 vim_free(p); |
1718 | 3186 |
3187 if (ccline.xpc != NULL | |
3188 && ccline.xpc->xp_pattern != NULL | |
3189 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3190 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3191 { | |
1754 | 3192 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3193 |
3194 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3195 * to point into the newly allocated memory. */ | |
3196 if (i >= 0 && i <= ccline.cmdlen) | |
3197 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3198 } | |
3199 | |
7 | 3200 return OK; |
3201 } | |
3202 | |
359 | 3203 #if defined(FEAT_ARABIC) || defined(PROTO) |
3204 static char_u *arshape_buf = NULL; | |
3205 | |
3206 # if defined(EXITFREE) || defined(PROTO) | |
3207 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3208 free_cmdline_buf(void) |
359 | 3209 { |
3210 vim_free(arshape_buf); | |
3211 } | |
3212 # endif | |
3213 #endif | |
3214 | |
7 | 3215 /* |
3216 * Draw part of the cmdline at the current cursor position. But draw stars | |
3217 * when cmdline_star is TRUE. | |
3218 */ | |
3219 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3220 draw_cmdline(int start, int len) |
7 | 3221 { |
3222 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3223 int i; | |
3224 | |
3225 if (cmdline_star > 0) | |
3226 for (i = 0; i < len; ++i) | |
3227 { | |
3228 msg_putchar('*'); | |
3229 # ifdef FEAT_MBYTE | |
3230 if (has_mbyte) | |
474 | 3231 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3232 # endif |
3233 } | |
3234 else | |
3235 #endif | |
3236 #ifdef FEAT_ARABIC | |
3237 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3238 { | |
3239 static int buflen = 0; | |
3240 char_u *p; | |
3241 int j; | |
3242 int newlen = 0; | |
3243 int mb_l; | |
719 | 3244 int pc, pc1 = 0; |
7 | 3245 int prev_c = 0; |
3246 int prev_c1 = 0; | |
714 | 3247 int u8c; |
3248 int u8cc[MAX_MCO]; | |
7 | 3249 int nc = 0; |
3250 | |
3251 /* | |
3252 * Do arabic shaping into a temporary buffer. This is very | |
3253 * inefficient! | |
3254 */ | |
507 | 3255 if (len * 2 + 2 > buflen) |
7 | 3256 { |
3257 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3258 * alloc()/free() calls. */ | |
359 | 3259 vim_free(arshape_buf); |
507 | 3260 buflen = len * 2 + 2; |
359 | 3261 arshape_buf = alloc(buflen); |
3262 if (arshape_buf == NULL) | |
7 | 3263 return; /* out of memory */ |
3264 } | |
3265 | |
507 | 3266 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3267 { | |
3268 /* Prepend a space to draw the leading composing char on. */ | |
3269 arshape_buf[0] = ' '; | |
3270 newlen = 1; | |
3271 } | |
3272 | |
7 | 3273 for (j = start; j < start + len; j += mb_l) |
3274 { | |
3275 p = ccline.cmdbuff + j; | |
714 | 3276 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3277 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3278 if (ARABIC_CHAR(u8c)) |
3279 { | |
3280 /* Do Arabic shaping. */ | |
3281 if (cmdmsg_rl) | |
3282 { | |
3283 /* displaying from right to left */ | |
3284 pc = prev_c; | |
3285 pc1 = prev_c1; | |
714 | 3286 prev_c1 = u8cc[0]; |
7 | 3287 if (j + mb_l >= start + len) |
3288 nc = NUL; | |
3289 else | |
3290 nc = utf_ptr2char(p + mb_l); | |
3291 } | |
3292 else | |
3293 { | |
3294 /* displaying from left to right */ | |
3295 if (j + mb_l >= start + len) | |
3296 pc = NUL; | |
3297 else | |
714 | 3298 { |
3299 int pcc[MAX_MCO]; | |
3300 | |
3301 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3302 start + len - j - mb_l); |
714 | 3303 pc1 = pcc[0]; |
3304 } | |
7 | 3305 nc = prev_c; |
3306 } | |
3307 prev_c = u8c; | |
3308 | |
714 | 3309 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3310 |
359 | 3311 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3312 if (u8cc[0] != 0) |
7 | 3313 { |
714 | 3314 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3315 if (u8cc[1] != 0) | |
3316 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3317 arshape_buf + newlen); |
7 | 3318 } |
3319 } | |
3320 else | |
3321 { | |
3322 prev_c = u8c; | |
359 | 3323 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3324 newlen += mb_l; |
3325 } | |
3326 } | |
3327 | |
359 | 3328 msg_outtrans_len(arshape_buf, newlen); |
7 | 3329 } |
3330 else | |
3331 #endif | |
3332 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3333 } | |
3334 | |
3335 /* | |
3336 * Put a character on the command line. Shifts the following text to the | |
3337 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3338 * "c" must be printable (fit in one display cell)! | |
3339 */ | |
3340 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3341 putcmdline(int c, int shift) |
7 | 3342 { |
3343 if (cmd_silent) | |
3344 return; | |
3345 msg_no_more = TRUE; | |
3346 msg_putchar(c); | |
3347 if (shift) | |
3348 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3349 msg_no_more = FALSE; | |
3350 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3351 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3352 extra_char_shift = shift; |
7 | 3353 } |
3354 | |
3355 /* | |
3356 * Undo a putcmdline(c, FALSE). | |
3357 */ | |
3358 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3359 unputcmdline(void) |
7 | 3360 { |
3361 if (cmd_silent) | |
3362 return; | |
3363 msg_no_more = TRUE; | |
3364 if (ccline.cmdlen == ccline.cmdpos) | |
3365 msg_putchar(' '); | |
3558 | 3366 #ifdef FEAT_MBYTE |
3367 else if (has_mbyte) | |
3368 draw_cmdline(ccline.cmdpos, | |
3369 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3370 #endif | |
7 | 3371 else |
3372 draw_cmdline(ccline.cmdpos, 1); | |
3373 msg_no_more = FALSE; | |
3374 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3375 extra_char = NUL; |
7 | 3376 } |
3377 | |
3378 /* | |
3379 * Put the given string, of the given length, onto the command line. | |
3380 * If len is -1, then STRLEN() is used to calculate the length. | |
3381 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3382 * part will be redrawn, otherwise it will not. If this function is called | |
3383 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3384 * called afterwards. | |
3385 */ | |
3386 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3387 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3388 { |
3389 int retval; | |
3390 int i; | |
3391 int m; | |
3392 int c; | |
3393 | |
3394 if (len < 0) | |
3395 len = (int)STRLEN(str); | |
3396 | |
3397 /* Check if ccline.cmdbuff needs to be longer */ | |
3398 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
|
3399 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3400 else |
3401 retval = OK; | |
3402 if (retval == OK) | |
3403 { | |
3404 if (!ccline.overstrike) | |
3405 { | |
3406 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3407 ccline.cmdbuff + ccline.cmdpos, | |
3408 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3409 ccline.cmdlen += len; | |
3410 } | |
3411 else | |
3412 { | |
3413 #ifdef FEAT_MBYTE | |
3414 if (has_mbyte) | |
3415 { | |
3416 /* Count nr of characters in the new string. */ | |
3417 m = 0; | |
474 | 3418 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3419 ++m; |
3420 /* Count nr of bytes in cmdline that are overwritten by these | |
3421 * characters. */ | |
3422 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3423 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3424 --m; |
3425 if (i < ccline.cmdlen) | |
3426 { | |
3427 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3428 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3429 ccline.cmdlen += ccline.cmdpos + len - i; | |
3430 } | |
3431 else | |
3432 ccline.cmdlen = ccline.cmdpos + len; | |
3433 } | |
3434 else | |
3435 #endif | |
3436 if (ccline.cmdpos + len > ccline.cmdlen) | |
3437 ccline.cmdlen = ccline.cmdpos + len; | |
3438 } | |
3439 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3440 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3441 | |
3442 #ifdef FEAT_MBYTE | |
3443 if (enc_utf8) | |
3444 { | |
3445 /* When the inserted text starts with a composing character, | |
3446 * backup to the character before it. There could be two of them. | |
3447 */ | |
3448 i = 0; | |
3449 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3450 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3451 { | |
3452 i = (*mb_head_off)(ccline.cmdbuff, | |
3453 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3454 ccline.cmdpos -= i; | |
3455 len += i; | |
3456 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3457 } | |
3458 # ifdef FEAT_ARABIC | |
3459 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3460 { | |
3461 /* Check the previous character for Arabic combining pair. */ | |
3462 i = (*mb_head_off)(ccline.cmdbuff, | |
3463 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3464 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3465 + ccline.cmdpos - i), c)) | |
3466 { | |
3467 ccline.cmdpos -= i; | |
3468 len += i; | |
3469 } | |
3470 else | |
3471 i = 0; | |
3472 } | |
3473 # endif | |
3474 if (i != 0) | |
3475 { | |
3476 /* Also backup the cursor position. */ | |
3477 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3478 ccline.cmdspos -= i; | |
3479 msg_col -= i; | |
3480 if (msg_col < 0) | |
3481 { | |
3482 msg_col += Columns; | |
3483 --msg_row; | |
3484 } | |
3485 } | |
3486 } | |
3487 #endif | |
3488 | |
3489 if (redraw && !cmd_silent) | |
3490 { | |
3491 msg_no_more = TRUE; | |
3492 i = cmdline_row; | |
3114 | 3493 cursorcmd(); |
7 | 3494 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3495 /* Avoid clearing the rest of the line too often. */ | |
3496 if (cmdline_row != i || ccline.overstrike) | |
3497 msg_clr_eos(); | |
3498 msg_no_more = FALSE; | |
3499 } | |
3500 #ifdef FEAT_FKMAP | |
3501 /* | |
3502 * If we are in Farsi command mode, the character input must be in | |
3503 * Insert mode. So do not advance the cmdpos. | |
3504 */ | |
3505 if (!cmd_fkmap) | |
3506 #endif | |
3507 { | |
3508 if (KeyTyped) | |
534 | 3509 { |
7 | 3510 m = Columns * Rows; |
534 | 3511 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3512 m = MAXCOL; | |
3513 } | |
7 | 3514 else |
3515 m = MAXCOL; | |
3516 for (i = 0; i < len; ++i) | |
3517 { | |
3518 c = cmdline_charsize(ccline.cmdpos); | |
3519 #ifdef FEAT_MBYTE | |
3520 /* count ">" for a double-wide char that doesn't fit. */ | |
3521 if (has_mbyte) | |
3522 correct_cmdspos(ccline.cmdpos, c); | |
3523 #endif | |
1612 | 3524 /* Stop cursor at the end of the screen, but do increment the |
3525 * insert position, so that entering a very long command | |
3526 * works, even though you can't see it. */ | |
3527 if (ccline.cmdspos + c < m) | |
3528 ccline.cmdspos += c; | |
7 | 3529 #ifdef FEAT_MBYTE |
3530 if (has_mbyte) | |
3531 { | |
474 | 3532 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3533 if (c > len - i - 1) |
3534 c = len - i - 1; | |
3535 ccline.cmdpos += c; | |
3536 i += c; | |
3537 } | |
3538 #endif | |
3539 ++ccline.cmdpos; | |
3540 } | |
3541 } | |
3542 } | |
3543 if (redraw) | |
3544 msg_check(); | |
3545 return retval; | |
3546 } | |
3547 | |
95 | 3548 static struct cmdline_info prev_ccline; |
3549 static int prev_ccline_used = FALSE; | |
3550 | |
3551 /* | |
3552 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3553 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3554 * available globally in prev_ccline. | |
3555 */ | |
3556 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3557 save_cmdline(struct cmdline_info *ccp) |
95 | 3558 { |
3559 if (!prev_ccline_used) | |
3560 { | |
3561 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3562 prev_ccline_used = TRUE; | |
3563 } | |
3564 *ccp = prev_ccline; | |
3565 prev_ccline = ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3566 ccline.cmdbuff = NULL; // signal that ccline is not in use |
95 | 3567 } |
3568 | |
3569 /* | |
1214 | 3570 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3571 */ |
3572 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3573 restore_cmdline(struct cmdline_info *ccp) |
95 | 3574 { |
3575 ccline = prev_ccline; | |
3576 prev_ccline = *ccp; | |
3577 } | |
3578 | |
15 | 3579 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3580 * 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
|
3581 * Used by CTRL-R command in command-line mode. |
15 | 3582 * insert_reg() can't be used here, because special characters from the |
3583 * register contents will be interpreted as commands. | |
3584 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3585 * Return FAIL for failure, OK otherwise. |
15 | 3586 */ |
3587 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3588 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3589 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3590 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
|
3591 int remcr) /* remove trailing CR */ |
15 | 3592 { |
3593 long i; | |
3594 char_u *arg; | |
772 | 3595 char_u *p; |
15 | 3596 int allocated; |
3597 | |
3598 /* check for valid regname; also accept special characters for CTRL-R in | |
3599 * the command line */ | |
3600 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
|
3601 && 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
|
3602 && !valid_yank_reg(regname, FALSE)) |
15 | 3603 return FAIL; |
3604 | |
3605 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3606 * CTRL-C to break the loop. */ | |
3607 line_breakcheck(); | |
3608 if (got_int) | |
3609 return FAIL; | |
3610 | |
3611 #ifdef FEAT_CLIPBOARD | |
3612 regname = may_get_selection(regname); | |
3613 #endif | |
3614 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3615 // Need to set "textlock" to avoid nasty things like going to another |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3616 // buffer when evaluating an expression. |
634 | 3617 ++textlock; |
15 | 3618 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3619 --textlock; |
15 | 3620 |
3621 if (i) | |
3622 { | |
3623 /* Got the value of a special register in "arg". */ | |
3624 if (arg == NULL) | |
3625 return FAIL; | |
772 | 3626 |
3627 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3628 * part of the word. */ | |
3629 p = arg; | |
3630 if (p_is && regname == Ctrl_W) | |
3631 { | |
3632 char_u *w; | |
3633 int len; | |
3634 | |
3635 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3636 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3637 { |
3638 #ifdef FEAT_MBYTE | |
3639 if (has_mbyte) | |
3640 { | |
3641 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3642 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3643 break; | |
3644 w -= len; | |
3645 } | |
3646 else | |
3647 #endif | |
3648 { | |
3649 if (!vim_iswordc(w[-1])) | |
3650 break; | |
3651 --w; | |
3652 } | |
3653 } | |
2937 | 3654 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3655 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3656 p += len; | |
3657 } | |
3658 | |
3659 cmdline_paste_str(p, literally); | |
15 | 3660 if (allocated) |
3661 vim_free(arg); | |
3662 return OK; | |
3663 } | |
3664 | |
1015 | 3665 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3666 } |
3667 | |
3668 /* | |
3669 * Put a string on the command line. | |
3670 * When "literally" is TRUE, insert literally. | |
3671 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3672 * line. | |
3673 */ | |
3674 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3675 cmdline_paste_str(char_u *s, int literally) |
15 | 3676 { |
3677 int c, cv; | |
3678 | |
3679 if (literally) | |
3680 put_on_cmdline(s, -1, TRUE); | |
3681 else | |
3682 while (*s != NUL) | |
3683 { | |
3684 cv = *s; | |
3685 if (cv == Ctrl_V && s[1]) | |
3686 ++s; | |
3687 #ifdef FEAT_MBYTE | |
3688 if (has_mbyte) | |
1606 | 3689 c = mb_cptr2char_adv(&s); |
15 | 3690 else |
3691 #endif | |
3692 c = *s++; | |
3628 | 3693 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3694 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3695 #ifdef UNIX |
3696 || c == intr_char | |
3697 #endif | |
3698 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3699 stuffcharReadbuff(Ctrl_V); | |
3700 stuffcharReadbuff(c); | |
3701 } | |
3702 } | |
3703 | |
7 | 3704 #ifdef FEAT_WILDMENU |
3705 /* | |
3706 * Delete characters on the command line, from "from" to the current | |
3707 * position. | |
3708 */ | |
3709 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3710 cmdline_del(int from) |
7 | 3711 { |
3712 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3713 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3714 ccline.cmdlen -= ccline.cmdpos - from; | |
3715 ccline.cmdpos = from; | |
3716 } | |
3717 #endif | |
3718 | |
3719 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3720 * 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
|
3721 * 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
|
3722 * overwritten. |
7 | 3723 */ |
3724 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3725 redrawcmdline(void) |
7 | 3726 { |
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
|
3727 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
|
3728 } |
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
|
3729 |
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
|
3730 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
|
3731 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
|
3732 { |
7 | 3733 if (cmd_silent) |
3734 return; | |
3735 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
|
3736 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
|
3737 compute_cmdrow(); |
7 | 3738 redrawcmd(); |
3739 cursorcmd(); | |
3740 } | |
3741 | |
3742 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3743 redrawcmdprompt(void) |
7 | 3744 { |
3745 int i; | |
3746 | |
3747 if (cmd_silent) | |
3748 return; | |
531 | 3749 if (ccline.cmdfirstc != NUL) |
7 | 3750 msg_putchar(ccline.cmdfirstc); |
3751 if (ccline.cmdprompt != NULL) | |
3752 { | |
3753 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3754 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3755 /* do the reverse of set_cmdspos() */ | |
531 | 3756 if (ccline.cmdfirstc != NUL) |
7 | 3757 --ccline.cmdindent; |
3758 } | |
3759 else | |
3760 for (i = ccline.cmdindent; i > 0; --i) | |
3761 msg_putchar(' '); | |
3762 } | |
3763 | |
3764 /* | |
3765 * Redraw what is currently on the command line. | |
3766 */ | |
3767 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3768 redrawcmd(void) |
7 | 3769 { |
3770 if (cmd_silent) | |
3771 return; | |
3772 | |
683 | 3773 /* when 'incsearch' is set there may be no command line while redrawing */ |
3774 if (ccline.cmdbuff == NULL) | |
3775 { | |
3776 windgoto(cmdline_row, 0); | |
3777 msg_clr_eos(); | |
3778 return; | |
3779 } | |
3780 | |
7 | 3781 msg_start(); |
3782 redrawcmdprompt(); | |
3783 | |
3784 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3785 msg_no_more = TRUE; | |
3786 draw_cmdline(0, ccline.cmdlen); | |
3787 msg_clr_eos(); | |
3788 msg_no_more = FALSE; | |
3789 | |
3790 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
|
3791 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
|
3792 putcmdline(extra_char, extra_char_shift); |
7 | 3793 |
3794 /* | |
3795 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3796 * in cmdline mode we can reset them now. | |
3797 */ | |
3798 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3799 | |
3800 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3801 * in cmdline mode */ | |
3802 skip_redraw = FALSE; | |
3803 } | |
3804 | |
3805 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3806 compute_cmdrow(void) |
7 | 3807 { |
540 | 3808 if (exmode_active || msg_scrolled != 0) |
7 | 3809 cmdline_row = Rows - 1; |
3810 else | |
3811 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
|
3812 + lastwin->w_status_height; |
7 | 3813 } |
3814 | |
3815 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3816 cursorcmd(void) |
7 | 3817 { |
3818 if (cmd_silent) | |
3819 return; | |
3820 | |
3821 #ifdef FEAT_RIGHTLEFT | |
3822 if (cmdmsg_rl) | |
3823 { | |
3824 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3825 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3826 if (msg_row <= 0) | |
3827 msg_row = Rows - 1; | |
3828 } | |
3829 else | |
3830 #endif | |
3831 { | |
3832 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3833 msg_col = ccline.cmdspos % (int)Columns; | |
3834 if (msg_row >= Rows) | |
3835 msg_row = Rows - 1; | |
3836 } | |
3837 | |
3838 windgoto(msg_row, msg_col); | |
3839 #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
|
3840 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
|
3841 redrawcmd_preedit(); |
7 | 3842 #endif |
3843 #ifdef MCH_CURSOR_SHAPE | |
3844 mch_update_cursor(); | |
3845 #endif | |
3846 } | |
3847 | |
3848 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3849 gotocmdline(int clr) |
7 | 3850 { |
3851 msg_start(); | |
3852 #ifdef FEAT_RIGHTLEFT | |
3853 if (cmdmsg_rl) | |
3854 msg_col = Columns - 1; | |
3855 else | |
3856 #endif | |
3857 msg_col = 0; /* always start in column 0 */ | |
3858 if (clr) /* clear the bottom line(s) */ | |
3859 msg_clr_eos(); /* will reset clear_cmdline */ | |
3860 windgoto(cmdline_row, 0); | |
3861 } | |
3862 | |
3863 /* | |
3864 * Check the word in front of the cursor for an abbreviation. | |
3865 * Called when the non-id character "c" has been entered. | |
3866 * When an abbreviation is recognized it is removed from the text with | |
3867 * backspaces and the replacement string is inserted, followed by "c". | |
3868 */ | |
3869 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3870 ccheck_abbr(int c) |
7 | 3871 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3872 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3873 |
7 | 3874 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3875 return FALSE; | |
3876 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3877 /* 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
|
3878 * 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
|
3879 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
|
3880 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3881 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
|
3882 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3883 && 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
|
3884 && 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
|
3885 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3886 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3887 /* 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
|
3888 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3889 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3890 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3891 } |
3892 | |
3164 | 3893 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3894 static int | |
3895 #ifdef __BORLANDC__ | |
3896 _RTLENTRYF | |
3897 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3898 sort_func_compare(const void *s1, const void *s2) |
3164 | 3899 { |
3900 char_u *p1 = *(char_u **)s1; | |
3901 char_u *p2 = *(char_u **)s2; | |
3902 | |
3903 if (*p1 != '<' && *p2 == '<') return -1; | |
3904 if (*p1 == '<' && *p2 != '<') return 1; | |
3905 return STRCMP(p1, p2); | |
3906 } | |
3907 #endif | |
3908 | |
7 | 3909 /* |
3910 * Return FAIL if this is not an appropriate context in which to do | |
3911 * completion of anything, return OK if it is (even if there are no matches). | |
3912 * For the caller, this means that the character is just passed through like a | |
3913 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3914 */ | |
3915 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3916 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3917 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3918 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3919 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3920 int escape) /* if TRUE, escape the returned matches */ |
7 | 3921 { |
3922 int i, j; | |
3923 char_u *p1; | |
3924 char_u *p2; | |
3925 int difflen; | |
3926 int v; | |
3927 | |
3928 if (xp->xp_numfiles == -1) | |
3929 { | |
3930 set_expand_context(xp); | |
3931 cmd_showtail = expand_showtail(xp); | |
3932 } | |
3933 | |
3934 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3935 { | |
3936 beep_flush(); | |
3937 return OK; /* Something illegal on command line */ | |
3938 } | |
3939 if (xp->xp_context == EXPAND_NOTHING) | |
3940 { | |
3941 /* Caller can use the character as a normal char instead */ | |
3942 return FAIL; | |
3943 } | |
3944 | |
3945 MSG_PUTS("..."); /* show that we are busy */ | |
3946 out_flush(); | |
3947 | |
3948 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3949 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3950 |
3951 if (type == WILD_NEXT || type == WILD_PREV) | |
3952 { | |
3953 /* | |
3954 * Get next/previous match for a previous expanded pattern. | |
3955 */ | |
3956 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3957 } | |
3958 else | |
3959 { | |
3960 /* | |
3961 * Translate string into pattern and expand it. | |
3962 */ | |
1965 | 3963 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3964 xp->xp_context)) == NULL) | |
7 | 3965 p2 = NULL; |
3966 else | |
3967 { | |
2652 | 3968 int use_options = options | |
3961 | 3969 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3970 if (escape) | |
3971 use_options |= WILD_ESCAPE; | |
2652 | 3972 |
3973 if (p_wic) | |
3974 use_options += WILD_ICASE; | |
1965 | 3975 p2 = ExpandOne(xp, p1, |
3976 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3977 use_options, type); |
7 | 3978 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3979 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3980 if (p2 != NULL && type == WILD_LONGEST) |
3981 { | |
1965 | 3982 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3983 if (ccline.cmdbuff[i + j] == '*' |
3984 || ccline.cmdbuff[i + j] == '?') | |
3985 break; | |
3986 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
|
3987 VIM_CLEAR(p2); |
7 | 3988 } |
3989 } | |
3990 } | |
3991 | |
3992 if (p2 != NULL && !got_int) | |
3993 { | |
1965 | 3994 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
|
3995 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3996 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3997 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3998 xp->xp_pattern = ccline.cmdbuff + i; |
3999 } | |
4000 else | |
4001 v = OK; | |
4002 if (v == OK) | |
4003 { | |
323 | 4004 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
4005 &ccline.cmdbuff[ccline.cmdpos], | |
4006 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
4007 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 4008 ccline.cmdlen += difflen; |
4009 ccline.cmdpos += difflen; | |
4010 } | |
4011 } | |
4012 vim_free(p2); | |
4013 | |
4014 redrawcmd(); | |
33 | 4015 cursorcmd(); |
7 | 4016 |
4017 /* When expanding a ":map" command and no matches are found, assume that | |
4018 * the key is supposed to be inserted literally */ | |
4019 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
4020 return FAIL; | |
4021 | |
4022 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4023 beep_flush(); | |
4024 else if (xp->xp_numfiles == 1) | |
4025 /* free expanded pattern */ | |
4026 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4027 | |
4028 return OK; | |
4029 } | |
4030 | |
4031 /* | |
4032 * Do wildcard expansion on the string 'str'. | |
4033 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4034 * Return a pointer to allocated memory containing the new string. |
7 | 4035 * Return NULL for failure. |
4036 * | |
1412 | 4037 * "orig" is the originally expanded string, copied to allocated memory. It |
4038 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4039 * WILD_PREV "orig" should be NULL. | |
4040 * | |
838 | 4041 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4042 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4043 * |
4044 * mode = WILD_FREE: just free previously expanded matches | |
4045 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4046 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4047 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4048 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4049 * mode = WILD_ALL: return all matches concatenated | |
4050 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4051 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4052 * |
4053 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4054 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4055 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4056 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4057 * options = WILD_ADD_SLASH: add a slash after directory names | |
4058 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4059 * options = WILD_SILENT: don't print warning messages | |
4060 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4061 * options = WILD_ICASE: ignore case for files |
7 | 4062 * |
4063 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4064 */ | |
4065 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4066 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4067 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4068 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4069 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
|
4070 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4071 int mode) |
7 | 4072 { |
4073 char_u *ss = NULL; | |
4074 static int findex; | |
4075 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4076 int orig_saved = FALSE; |
7 | 4077 int i; |
4078 long_u len; | |
4079 int non_suf_match; /* number without matching suffix */ | |
4080 | |
4081 /* | |
4082 * first handle the case of using an old match | |
4083 */ | |
4084 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4085 { | |
4086 if (xp->xp_numfiles > 0) | |
4087 { | |
4088 if (mode == WILD_PREV) | |
4089 { | |
4090 if (findex == -1) | |
4091 findex = xp->xp_numfiles; | |
4092 --findex; | |
4093 } | |
4094 else /* mode == WILD_NEXT */ | |
4095 ++findex; | |
4096 | |
4097 /* | |
4098 * When wrapping around, return the original string, set findex to | |
4099 * -1. | |
4100 */ | |
4101 if (findex < 0) | |
4102 { | |
4103 if (orig_save == NULL) | |
4104 findex = xp->xp_numfiles - 1; | |
4105 else | |
4106 findex = -1; | |
4107 } | |
4108 if (findex >= xp->xp_numfiles) | |
4109 { | |
4110 if (orig_save == NULL) | |
4111 findex = 0; | |
4112 else | |
4113 findex = -1; | |
4114 } | |
4115 #ifdef FEAT_WILDMENU | |
4116 if (p_wmnu) | |
4117 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4118 findex, cmd_showtail); | |
4119 #endif | |
4120 if (findex == -1) | |
4121 return vim_strsave(orig_save); | |
4122 return vim_strsave(xp->xp_files[findex]); | |
4123 } | |
4124 else | |
4125 return NULL; | |
4126 } | |
4127 | |
1412 | 4128 /* free old names */ |
7 | 4129 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4130 { | |
4131 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4132 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
|
4133 VIM_CLEAR(orig_save); |
7 | 4134 } |
4135 findex = 0; | |
4136 | |
4137 if (mode == WILD_FREE) /* only release file name */ | |
4138 return NULL; | |
4139 | |
4140 if (xp->xp_numfiles == -1) | |
4141 { | |
4142 vim_free(orig_save); | |
4143 orig_save = orig; | |
1432 | 4144 orig_saved = TRUE; |
7 | 4145 |
4146 /* | |
4147 * Do the expansion. | |
4148 */ | |
4149 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4150 options) == FAIL) | |
4151 { | |
4152 #ifdef FNAME_ILLEGAL | |
4153 /* Illegal file name has been silently skipped. But when there | |
4154 * are wildcards, the real problem is that there was no match, | |
4155 * causing the pattern to be added, which has illegal characters. | |
4156 */ | |
4157 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4158 EMSG2(_(e_nomatch2), str); | |
4159 #endif | |
4160 } | |
4161 else if (xp->xp_numfiles == 0) | |
4162 { | |
4163 if (!(options & WILD_SILENT)) | |
4164 EMSG2(_(e_nomatch2), str); | |
4165 } | |
4166 else | |
4167 { | |
4168 /* Escape the matches for use on the command line. */ | |
4169 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4170 | |
4171 /* | |
4172 * Check for matching suffixes in file names. | |
4173 */ | |
3398 | 4174 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4175 && mode != WILD_LONGEST) | |
7 | 4176 { |
4177 if (xp->xp_numfiles) | |
4178 non_suf_match = xp->xp_numfiles; | |
4179 else | |
4180 non_suf_match = 1; | |
4181 if ((xp->xp_context == EXPAND_FILES | |
4182 || xp->xp_context == EXPAND_DIRECTORIES) | |
4183 && xp->xp_numfiles > 1) | |
4184 { | |
4185 /* | |
4186 * More than one match; check suffix. | |
4187 * The files will have been sorted on matching suffix in | |
4188 * expand_wildcards, only need to check the first two. | |
4189 */ | |
4190 non_suf_match = 0; | |
4191 for (i = 0; i < 2; ++i) | |
4192 if (match_suffix(xp->xp_files[i])) | |
4193 ++non_suf_match; | |
4194 } | |
4195 if (non_suf_match != 1) | |
4196 { | |
4197 /* Can we ever get here unless it's while expanding | |
4198 * interactively? If not, we can get rid of this all | |
4199 * together. Don't really want to wait for this message | |
4200 * (and possibly have to hit return to continue!). | |
4201 */ | |
4202 if (!(options & WILD_SILENT)) | |
4203 EMSG(_(e_toomany)); | |
4204 else if (!(options & WILD_NO_BEEP)) | |
4205 beep_flush(); | |
4206 } | |
4207 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4208 ss = vim_strsave(xp->xp_files[0]); | |
4209 } | |
4210 } | |
4211 } | |
4212 | |
4213 /* Find longest common part */ | |
4214 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4215 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4216 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4217 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4218 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4219 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4220 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4221 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4222 if (has_mbyte) |
7 | 4223 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4224 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
|
4225 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
|
4226 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4227 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4228 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4229 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
|
4230 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
|
4231 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4232 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4233 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4234 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
|
4235 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4236 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4237 ci = xp->xp_files[i][len]; |
4242 | 4238 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4239 || xp->xp_context == EXPAND_FILES |
714 | 4240 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4241 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4242 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4243 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4244 break; |
4245 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4246 else if (c0 != ci) |
7 | 4247 break; |
4248 } | |
4249 if (i < xp->xp_numfiles) | |
4250 { | |
4251 if (!(options & WILD_NO_BEEP)) | |
6949 | 4252 vim_beep(BO_WILD); |
7 | 4253 break; |
4254 } | |
4255 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4256 |
7 | 4257 ss = alloc((unsigned)len + 1); |
4258 if (ss) | |
419 | 4259 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4260 findex = -1; /* next p_wc gets first one */ |
4261 } | |
4262 | |
4263 /* Concatenate all matching names */ | |
4264 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4265 { | |
4266 len = 0; | |
4267 for (i = 0; i < xp->xp_numfiles; ++i) | |
4268 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4269 ss = lalloc(len, TRUE); | |
4270 if (ss != NULL) | |
4271 { | |
4272 *ss = NUL; | |
4273 for (i = 0; i < xp->xp_numfiles; ++i) | |
4274 { | |
4275 STRCAT(ss, xp->xp_files[i]); | |
4276 if (i != xp->xp_numfiles - 1) | |
4277 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4278 } | |
4279 } | |
4280 } | |
4281 | |
4282 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4283 ExpandCleanup(xp); | |
4284 | |
1412 | 4285 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4286 if (!orig_saved) |
1412 | 4287 vim_free(orig); |
4288 | |
7 | 4289 return ss; |
4290 } | |
4291 | |
4292 /* | |
4293 * Prepare an expand structure for use. | |
4294 */ | |
4295 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4296 ExpandInit(expand_T *xp) |
7 | 4297 { |
1718 | 4298 xp->xp_pattern = NULL; |
1965 | 4299 xp->xp_pattern_len = 0; |
7 | 4300 xp->xp_backslash = XP_BS_NONE; |
632 | 4301 #ifndef BACKSLASH_IN_FILENAME |
4302 xp->xp_shell = FALSE; | |
4303 #endif | |
7 | 4304 xp->xp_numfiles = -1; |
4305 xp->xp_files = NULL; | |
632 | 4306 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4307 xp->xp_arg = NULL; | |
4308 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4309 xp->xp_line = NULL; |
7 | 4310 } |
4311 | |
4312 /* | |
4313 * Cleanup an expand structure after use. | |
4314 */ | |
4315 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4316 ExpandCleanup(expand_T *xp) |
7 | 4317 { |
4318 if (xp->xp_numfiles >= 0) | |
4319 { | |
4320 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4321 xp->xp_numfiles = -1; | |
4322 } | |
4323 } | |
4324 | |
4325 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4326 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4327 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4328 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4329 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4330 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4331 int options) |
7 | 4332 { |
4333 int i; | |
4334 char_u *p; | |
4335 | |
4336 /* | |
4337 * May change home directory back to "~" | |
4338 */ | |
4339 if (options & WILD_HOME_REPLACE) | |
4340 tilde_replace(str, numfiles, files); | |
4341 | |
4342 if (options & WILD_ESCAPE) | |
4343 { | |
4344 if (xp->xp_context == EXPAND_FILES | |
2778 | 4345 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4346 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4347 || xp->xp_context == EXPAND_BUFFERS |
4348 || xp->xp_context == EXPAND_DIRECTORIES) | |
4349 { | |
4350 /* | |
4351 * Insert a backslash into a file name before a space, \, %, # | |
4352 * and wildmatch characters, except '~'. | |
4353 */ | |
4354 for (i = 0; i < numfiles; ++i) | |
4355 { | |
4356 /* for ":set path=" we need to escape spaces twice */ | |
4357 if (xp->xp_backslash == XP_BS_THREE) | |
4358 { | |
4359 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4360 if (p != NULL) | |
4361 { | |
4362 vim_free(files[i]); | |
4363 files[i] = p; | |
719 | 4364 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4365 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4366 if (p != NULL) | |
4367 { | |
4368 vim_free(files[i]); | |
4369 files[i] = p; | |
4370 } | |
4371 #endif | |
4372 } | |
4373 } | |
1589 | 4374 #ifdef BACKSLASH_IN_FILENAME |
4375 p = vim_strsave_fnameescape(files[i], FALSE); | |
4376 #else | |
1586 | 4377 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4378 #endif |
7 | 4379 if (p != NULL) |
4380 { | |
4381 vim_free(files[i]); | |
4382 files[i] = p; | |
4383 } | |
4384 | |
4385 /* If 'str' starts with "\~", replace "~" at start of | |
4386 * files[i] with "\~". */ | |
4387 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4388 escape_fname(&files[i]); |
7 | 4389 } |
4390 xp->xp_backslash = XP_BS_NONE; | |
435 | 4391 |
4392 /* If the first file starts with a '+' escape it. Otherwise it | |
4393 * could be seen as "+cmd". */ | |
4394 if (*files[0] == '+') | |
4395 escape_fname(&files[0]); | |
7 | 4396 } |
4397 else if (xp->xp_context == EXPAND_TAGS) | |
4398 { | |
4399 /* | |
4400 * Insert a backslash before characters in a tag name that | |
4401 * would terminate the ":tag" command. | |
4402 */ | |
4403 for (i = 0; i < numfiles; ++i) | |
4404 { | |
4405 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4406 if (p != NULL) | |
4407 { | |
4408 vim_free(files[i]); | |
4409 files[i] = p; | |
4410 } | |
4411 } | |
4412 } | |
4413 } | |
4414 } | |
4415 | |
4416 /* | |
1586 | 4417 * Escape special characters in "fname" for when used as a file name argument |
4418 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4419 * Returns the result in allocated memory. | |
4420 */ | |
4421 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4422 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4423 { |
1685 | 4424 char_u *p; |
1586 | 4425 #ifdef BACKSLASH_IN_FILENAME |
4426 char_u buf[20]; | |
4427 int j = 0; | |
4428 | |
5481 | 4429 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4430 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4431 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4432 buf[j++] = *p; |
4433 buf[j] = NUL; | |
1700 | 4434 p = vim_strsave_escaped(fname, buf); |
1586 | 4435 #else |
1685 | 4436 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4437 if (shell && csh_like_shell() && p != NULL) | |
4438 { | |
4439 char_u *s; | |
4440 | |
4441 /* For csh and similar shells need to put two backslashes before '!'. | |
4442 * One is taken by Vim, one by the shell. */ | |
4443 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4444 vim_free(p); | |
4445 p = s; | |
4446 } | |
1700 | 4447 #endif |
4448 | |
4449 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4450 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4451 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4452 escape_fname(&p); |
4453 | |
1685 | 4454 return p; |
1586 | 4455 } |
4456 | |
4457 /* | |
435 | 4458 * Put a backslash before the file name in "pp", which is in allocated memory. |
4459 */ | |
4460 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4461 escape_fname(char_u **pp) |
435 | 4462 { |
4463 char_u *p; | |
4464 | |
4465 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4466 if (p != NULL) | |
4467 { | |
4468 p[0] = '\\'; | |
4469 STRCPY(p + 1, *pp); | |
4470 vim_free(*pp); | |
4471 *pp = p; | |
4472 } | |
4473 } | |
4474 | |
4475 /* | |
7 | 4476 * For each file name in files[num_files]: |
4477 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4478 */ | |
4479 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4480 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4481 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4482 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4483 char_u **files) |
7 | 4484 { |
4485 int i; | |
4486 char_u *p; | |
4487 | |
4488 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4489 { | |
4490 for (i = 0; i < num_files; ++i) | |
4491 { | |
4492 p = home_replace_save(NULL, files[i]); | |
4493 if (p != NULL) | |
4494 { | |
4495 vim_free(files[i]); | |
4496 files[i] = p; | |
4497 } | |
4498 } | |
4499 } | |
4500 } | |
4501 | |
4502 /* | |
4503 * Show all matches for completion on the command line. | |
4504 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4505 * be inserted like a normal character. | |
4506 */ | |
4507 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4508 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4509 { |
4510 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4511 int num_files; | |
4512 char_u **files_found; | |
4513 int i, j, k; | |
4514 int maxlen; | |
4515 int lines; | |
4516 int columns; | |
4517 char_u *p; | |
4518 int lastlen; | |
4519 int attr; | |
4520 int showtail; | |
4521 | |
4522 if (xp->xp_numfiles == -1) | |
4523 { | |
4524 set_expand_context(xp); | |
4525 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4526 &num_files, &files_found); | |
4527 showtail = expand_showtail(xp); | |
4528 if (i != EXPAND_OK) | |
4529 return i; | |
4530 | |
4531 } | |
4532 else | |
4533 { | |
4534 num_files = xp->xp_numfiles; | |
4535 files_found = xp->xp_files; | |
4536 showtail = cmd_showtail; | |
4537 } | |
4538 | |
4539 #ifdef FEAT_WILDMENU | |
4540 if (!wildmenu) | |
4541 { | |
4542 #endif | |
4543 msg_didany = FALSE; /* lines_left will be set */ | |
4544 msg_start(); /* prepare for paging */ | |
4545 msg_putchar('\n'); | |
4546 out_flush(); | |
4547 cmdline_row = msg_row; | |
4548 msg_didany = FALSE; /* lines_left will be set again */ | |
4549 msg_start(); /* prepare for paging */ | |
4550 #ifdef FEAT_WILDMENU | |
4551 } | |
4552 #endif | |
4553 | |
4554 if (got_int) | |
4555 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4556 #ifdef FEAT_WILDMENU | |
4557 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
|
4558 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4559 #endif |
4560 else | |
4561 { | |
4562 /* find the length of the longest file name */ | |
4563 maxlen = 0; | |
4564 for (i = 0; i < num_files; ++i) | |
4565 { | |
4566 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4567 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4568 || xp->xp_context == EXPAND_BUFFERS)) |
4569 { | |
4570 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4571 j = vim_strsize(NameBuff); | |
4572 } | |
4573 else | |
4574 j = vim_strsize(L_SHOWFILE(i)); | |
4575 if (j > maxlen) | |
4576 maxlen = j; | |
4577 } | |
4578 | |
4579 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4580 lines = num_files; | |
4581 else | |
4582 { | |
4583 /* compute the number of columns and lines for the listing */ | |
4584 maxlen += 2; /* two spaces between file names */ | |
4585 columns = ((int)Columns + 2) / maxlen; | |
4586 if (columns < 1) | |
4587 columns = 1; | |
4588 lines = (num_files + columns - 1) / columns; | |
4589 } | |
4590 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4591 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4592 |
4593 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4594 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4595 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4596 msg_clr_eos(); |
4597 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
|
4598 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4599 } |
4600 | |
4601 /* list the files line by line */ | |
4602 for (i = 0; i < lines; ++i) | |
4603 { | |
4604 lastlen = 999; | |
4605 for (k = i; k < num_files; k += lines) | |
4606 { | |
4607 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4608 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4609 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4610 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4611 msg_advance(maxlen + 1); | |
4612 msg_puts(p); | |
4613 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
|
4614 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4615 break; |
4616 } | |
4617 for (j = maxlen - lastlen; --j >= 0; ) | |
4618 msg_putchar(' '); | |
4619 if (xp->xp_context == EXPAND_FILES | |
714 | 4620 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4621 || xp->xp_context == EXPAND_BUFFERS) |
4622 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4623 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4624 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4625 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4626 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4627 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4628 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4629 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4630 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4631 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4632 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
|
4633 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4634 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4635 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4636 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4637 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4638 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4639 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4640 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4641 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4642 j = mch_isdir(files_found[k]); |
7 | 4643 if (showtail) |
4644 p = L_SHOWFILE(k); | |
4645 else | |
4646 { | |
4647 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4648 TRUE); | |
4649 p = NameBuff; | |
4650 } | |
4651 } | |
4652 else | |
4653 { | |
4654 j = FALSE; | |
4655 p = L_SHOWFILE(k); | |
4656 } | |
4657 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4658 } | |
4659 if (msg_col > 0) /* when not wrapped around */ | |
4660 { | |
4661 msg_clr_eos(); | |
4662 msg_putchar('\n'); | |
4663 } | |
4664 out_flush(); /* show one line at a time */ | |
4665 if (got_int) | |
4666 { | |
4667 got_int = FALSE; | |
4668 break; | |
4669 } | |
4670 } | |
4671 | |
4672 /* | |
4673 * we redraw the command below the lines that we have just listed | |
4674 * This is a bit tricky, but it saves a lot of screen updating. | |
4675 */ | |
4676 cmdline_row = msg_row; /* will put it back later */ | |
4677 } | |
4678 | |
4679 if (xp->xp_numfiles == -1) | |
4680 FreeWild(num_files, files_found); | |
4681 | |
4682 return EXPAND_OK; | |
4683 } | |
4684 | |
4685 /* | |
4686 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4687 * Find tail of file name path, but ignore trailing "/". | |
4688 */ | |
4689 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4690 sm_gettail(char_u *s) |
7 | 4691 { |
4692 char_u *p; | |
4693 char_u *t = s; | |
4694 int had_sep = FALSE; | |
4695 | |
4696 for (p = s; *p != NUL; ) | |
4697 { | |
4698 if (vim_ispathsep(*p) | |
4699 #ifdef BACKSLASH_IN_FILENAME | |
4700 && !rem_backslash(p) | |
4701 #endif | |
4702 ) | |
4703 had_sep = TRUE; | |
4704 else if (had_sep) | |
4705 { | |
4706 t = p; | |
4707 had_sep = FALSE; | |
4708 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4709 MB_PTR_ADV(p); |
7 | 4710 } |
4711 return t; | |
4712 } | |
4713 | |
4714 /* | |
4715 * Return TRUE if we only need to show the tail of completion matches. | |
4716 * When not completing file names or there is a wildcard in the path FALSE is | |
4717 * returned. | |
4718 */ | |
4719 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4720 expand_showtail(expand_T *xp) |
7 | 4721 { |
4722 char_u *s; | |
4723 char_u *end; | |
4724 | |
4725 /* When not completing file names a "/" may mean something different. */ | |
714 | 4726 if (xp->xp_context != EXPAND_FILES |
4727 && xp->xp_context != EXPAND_SHELLCMD | |
4728 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4729 return FALSE; |
4730 | |
4731 end = gettail(xp->xp_pattern); | |
4732 if (end == xp->xp_pattern) /* there is no path separator */ | |
4733 return FALSE; | |
4734 | |
4735 for (s = xp->xp_pattern; s < end; s++) | |
4736 { | |
4737 /* Skip escaped wildcards. Only when the backslash is not a path | |
4738 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4739 if (rem_backslash(s)) | |
4740 ++s; | |
4741 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4742 return FALSE; | |
4743 } | |
4744 return TRUE; | |
4745 } | |
4746 | |
4747 /* | |
4748 * Prepare a string for expansion. | |
4749 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4750 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4751 * When expanding other names: The string will be used with regcomp(). Copy |
4752 * the name into allocated memory and prepend "^". | |
4753 */ | |
4754 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4755 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4756 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4757 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4758 int context) /* EXPAND_FILES etc. */ |
7 | 4759 { |
4760 char_u *retval; | |
4761 int i, j; | |
4762 int new_len; | |
4763 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4764 int ends_in_star; |
7 | 4765 |
714 | 4766 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4767 && context != EXPAND_FILES_IN_PATH |
714 | 4768 && context != EXPAND_SHELLCMD |
4769 && context != EXPAND_DIRECTORIES) | |
7 | 4770 { |
4771 /* | |
4772 * Matching will be done internally (on something other than files). | |
4773 * So we convert the file-matching-type wildcards into our kind for | |
4774 * use with vim_regcomp(). First work out how long it will be: | |
4775 */ | |
4776 | |
4777 /* For help tags the translation is done in find_help_tags(). | |
4778 * For a tag pattern starting with "/" no translation is needed. */ | |
4779 if (context == EXPAND_HELP | |
4780 || context == EXPAND_COLORS | |
4781 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4782 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4783 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4784 || 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
|
4785 || ((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
|
4786 || 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
|
4787 && fname[0] == '/')) |
7 | 4788 retval = vim_strnsave(fname, len); |
4789 else | |
4790 { | |
4791 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4792 for (i = 0; i < len; i++) | |
4793 { | |
4794 if (fname[i] == '*' || fname[i] == '~') | |
4795 new_len++; /* '*' needs to be replaced by ".*" | |
4796 '~' needs to be replaced by "\~" */ | |
4797 | |
4798 /* Buffer names are like file names. "." should be literal */ | |
4799 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4800 new_len++; /* "." becomes "\." */ | |
4801 | |
4802 /* Custom expansion takes care of special things, match | |
4803 * backslashes literally (perhaps also for other types?) */ | |
634 | 4804 if ((context == EXPAND_USER_DEFINED |
4805 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4806 new_len++; /* '\' becomes "\\" */ |
4807 } | |
4808 retval = alloc(new_len); | |
4809 if (retval != NULL) | |
4810 { | |
4811 retval[0] = '^'; | |
4812 j = 1; | |
4813 for (i = 0; i < len; i++, j++) | |
4814 { | |
4815 /* Skip backslash. But why? At least keep it for custom | |
4816 * expansion. */ | |
4817 if (context != EXPAND_USER_DEFINED | |
407 | 4818 && context != EXPAND_USER_LIST |
4819 && fname[i] == '\\' | |
4820 && ++i == len) | |
7 | 4821 break; |
4822 | |
4823 switch (fname[i]) | |
4824 { | |
4825 case '*': retval[j++] = '.'; | |
4826 break; | |
4827 case '~': retval[j++] = '\\'; | |
4828 break; | |
4829 case '?': retval[j] = '.'; | |
4830 continue; | |
4831 case '.': if (context == EXPAND_BUFFERS) | |
4832 retval[j++] = '\\'; | |
4833 break; | |
407 | 4834 case '\\': if (context == EXPAND_USER_DEFINED |
4835 || context == EXPAND_USER_LIST) | |
7 | 4836 retval[j++] = '\\'; |
4837 break; | |
4838 } | |
4839 retval[j] = fname[i]; | |
4840 } | |
4841 retval[j] = NUL; | |
4842 } | |
4843 } | |
4844 } | |
4845 else | |
4846 { | |
4847 retval = alloc(len + 4); | |
4848 if (retval != NULL) | |
4849 { | |
419 | 4850 vim_strncpy(retval, fname, len); |
7 | 4851 |
4852 /* | |
831 | 4853 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4854 * * would become **, which walks the whole tree. | |
7 | 4855 * ~ would be at the start of the file name, but not the tail. |
4856 * $ could be anywhere in the tail. | |
4857 * ` could be anywhere in the file name. | |
1484 | 4858 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4859 */ |
4860 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4861 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
|
4862 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4863 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4864 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4865 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4866 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4867 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4868 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4869 #endif |
7 | 4870 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4871 && !ends_in_star |
7 | 4872 && vim_strchr(tail, '$') == NULL |
4873 && vim_strchr(retval, '`') == NULL) | |
4874 retval[len++] = '*'; | |
1484 | 4875 else if (len > 0 && retval[len - 1] == '$') |
4876 --len; | |
7 | 4877 retval[len] = NUL; |
4878 } | |
4879 } | |
4880 return retval; | |
4881 } | |
4882 | |
4883 /* | |
4884 * Must parse the command line so far to work out what context we are in. | |
4885 * Completion can then be done based on that context. | |
4886 * This routine sets the variables: | |
4887 * xp->xp_pattern The start of the pattern to be expanded within | |
4888 * the command line (ends at the cursor). | |
4889 * xp->xp_context The type of thing to expand. Will be one of: | |
4890 * | |
4891 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4892 * the command line, like an unknown command. Caller | |
4893 * should beep. | |
4894 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4895 * a normal char, rather than for completion. eg | |
4896 * :s/^I/ | |
4897 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4898 * it. | |
4899 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4900 * EXPAND_FILES After command with XFILE set, or after setting | |
4901 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4902 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4903 * when we know only directories are of interest. eg | |
4904 * :set dir=^I | |
714 | 4905 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4906 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4907 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4908 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4909 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4910 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4911 * EXPAND_EVENTS Complete event names | |
4912 * EXPAND_SYNTAX Complete :syntax command arguments | |
4913 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4914 * EXPAND_AUGROUP Complete autocommand group names | |
4915 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4916 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4917 * eg :unmap a^I , :cunab x^I | |
4918 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4919 * eg :call sub^I | |
4920 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4921 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4922 * names in expressions, eg :while s^I | |
4923 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4924 * EXPAND_USER Complete user names |
7 | 4925 */ |
4926 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4927 set_expand_context(expand_T *xp) |
7 | 4928 { |
168 | 4929 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4930 if (ccline.cmdfirstc != ':' |
4931 #ifdef FEAT_EVAL | |
168 | 4932 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4933 && !ccline.input_fn |
7 | 4934 #endif |
4935 ) | |
4936 { | |
4937 xp->xp_context = EXPAND_NOTHING; | |
4938 return; | |
4939 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4940 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4941 } |
4942 | |
4943 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4944 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4945 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4946 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
|
4947 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
|
4948 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4949 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4950 { |
4951 int old_char = NUL; | |
4952 char_u *nextcomm; | |
4953 | |
4954 /* | |
4955 * Avoid a UMR warning from Purify, only save the character if it has been | |
4956 * written before. | |
4957 */ | |
4958 if (col < len) | |
4959 old_char = str[col]; | |
4960 str[col] = NUL; | |
4961 nextcomm = str; | |
168 | 4962 |
4963 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4964 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4965 { |
4966 # ifdef FEAT_CMDL_COMPL | |
168 | 4967 /* pass CMD_SIZE because there is no real command */ |
4968 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4969 # endif |
4970 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4971 else if (use_ccline && ccline.input_fn) |
531 | 4972 { |
4973 xp->xp_context = ccline.xp_context; | |
4974 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4975 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4976 xp->xp_arg = ccline.xp_arg; |
1322 | 4977 # endif |
531 | 4978 } |
168 | 4979 else |
4980 #endif | |
4981 while (nextcomm != NULL) | |
4982 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4983 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4984 /* 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
|
4985 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4986 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4987 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4988 |
7 | 4989 str[col] = old_char; |
4990 } | |
4991 | |
4992 /* | |
4993 * Expand the command line "str" from context "xp". | |
4994 * "xp" must have been set by set_cmd_context(). | |
4995 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4996 * starts. | |
4997 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4998 * cursor. | |
4999 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
5000 * key that triggered expansion literally. | |
5001 * Returns EXPAND_OK otherwise. | |
5002 */ | |
5003 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5004 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5005 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5006 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
|
5007 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5008 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5009 char_u ***matches) /* return: array of pointers to matches */ |
7 | 5010 { |
5011 char_u *file_str = NULL; | |
2652 | 5012 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 5013 |
5014 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
5015 { | |
5016 beep_flush(); | |
5017 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
5018 } | |
5019 if (xp->xp_context == EXPAND_NOTHING) | |
5020 { | |
5021 /* Caller can use the character as a normal char instead */ | |
5022 return EXPAND_NOTHING; | |
5023 } | |
5024 | |
5025 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5026 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5027 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5028 if (file_str == NULL) |
5029 return EXPAND_UNSUCCESSFUL; | |
5030 | |
2652 | 5031 if (p_wic) |
5032 options += WILD_ICASE; | |
5033 | |
7 | 5034 /* find all files that match the description */ |
2652 | 5035 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5036 { |
5037 *matchcount = 0; | |
5038 *matches = NULL; | |
5039 } | |
5040 vim_free(file_str); | |
5041 | |
5042 return EXPAND_OK; | |
5043 } | |
5044 | |
5045 #ifdef FEAT_MULTI_LANG | |
5046 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5047 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5048 * 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
|
5049 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5050 */ |
5051 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5052 cleanup_help_tags(int num_file, char_u **file) |
7 | 5053 { |
5054 int i, j; | |
5055 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5056 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5057 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5058 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5059 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
|
5060 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5061 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5062 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5063 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5064 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5065 *p = NUL; |
7 | 5066 |
5067 for (i = 0; i < num_file; ++i) | |
5068 { | |
5069 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
|
5070 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5071 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5072 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5073 { |
5074 /* Sorting on priority means the same item in another language may | |
5075 * be anywhere. Search all items for a match up to the "@en". */ | |
5076 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
|
5077 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
|
5078 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5079 break; |
5080 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5081 /* item only exists with @en, remove it */ |
7 | 5082 file[i][len] = NUL; |
5083 } | |
5084 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5085 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5086 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5087 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
|
5088 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5089 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5090 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5091 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5092 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
|
5093 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5094 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5095 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5096 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5097 } |
7 | 5098 } |
5099 #endif | |
5100 | |
5101 /* | |
5102 * Do the expansion based on xp->xp_context and "pat". | |
5103 */ | |
5104 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5105 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5106 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5107 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5108 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5109 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5110 int options) /* EW_ flags */ |
7 | 5111 { |
5112 #ifdef FEAT_CMDL_COMPL | |
5113 regmatch_T regmatch; | |
5114 #endif | |
5115 int ret; | |
5116 int flags; | |
5117 | |
5118 flags = EW_DIR; /* include directories */ | |
5119 if (options & WILD_LIST_NOTFOUND) | |
5120 flags |= EW_NOTFOUND; | |
5121 if (options & WILD_ADD_SLASH) | |
5122 flags |= EW_ADDSLASH; | |
5123 if (options & WILD_KEEP_ALL) | |
5124 flags |= EW_KEEPALL; | |
5125 if (options & WILD_SILENT) | |
5126 flags |= EW_SILENT; | |
6659 | 5127 if (options & WILD_ALLLINKS) |
5128 flags |= EW_ALLLINKS; | |
7 | 5129 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5130 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5131 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5132 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5133 { |
5134 /* | |
5135 * Expand file or directory names. | |
5136 */ | |
5137 int free_pat = FALSE; | |
5138 int i; | |
5139 | |
5140 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5141 * space */ | |
5142 if (xp->xp_backslash != XP_BS_NONE) | |
5143 { | |
5144 free_pat = TRUE; | |
5145 pat = vim_strsave(pat); | |
5146 for (i = 0; pat[i]; ++i) | |
5147 if (pat[i] == '\\') | |
5148 { | |
5149 if (xp->xp_backslash == XP_BS_THREE | |
5150 && pat[i + 1] == '\\' | |
5151 && pat[i + 2] == '\\' | |
5152 && pat[i + 3] == ' ') | |
1621 | 5153 STRMOVE(pat + i, pat + i + 3); |
7 | 5154 if (xp->xp_backslash == XP_BS_ONE |
5155 && pat[i + 1] == ' ') | |
1621 | 5156 STRMOVE(pat + i, pat + i + 1); |
7 | 5157 } |
5158 } | |
5159 | |
5160 if (xp->xp_context == EXPAND_FILES) | |
5161 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5162 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
|
5163 flags |= (EW_FILE | EW_PATH); |
7 | 5164 else |
5165 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5166 if (options & WILD_ICASE) |
5167 flags |= EW_ICASE; | |
5168 | |
2016 | 5169 /* Expand wildcards, supporting %:h and the like. */ |
5170 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5171 if (free_pat) |
5172 vim_free(pat); | |
5173 return ret; | |
5174 } | |
5175 | |
5176 *file = (char_u **)""; | |
5177 *num_file = 0; | |
5178 if (xp->xp_context == EXPAND_HELP) | |
5179 { | |
1696 | 5180 /* With an empty argument we would get all the help tags, which is |
5181 * very slow. Get matches for "help" instead. */ | |
5182 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5183 num_file, file, FALSE) == OK) | |
7 | 5184 { |
5185 #ifdef FEAT_MULTI_LANG | |
5186 cleanup_help_tags(*num_file, *file); | |
5187 #endif | |
5188 return OK; | |
5189 } | |
5190 return FAIL; | |
5191 } | |
5192 | |
5193 #ifndef FEAT_CMDL_COMPL | |
5194 return FAIL; | |
5195 #else | |
716 | 5196 if (xp->xp_context == EXPAND_SHELLCMD) |
5197 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5198 if (xp->xp_context == EXPAND_OLD_SETTING) |
5199 return ExpandOldSetting(num_file, file); | |
5200 if (xp->xp_context == EXPAND_BUFFERS) | |
5201 return ExpandBufnames(pat, num_file, file, options); | |
5202 if (xp->xp_context == EXPAND_TAGS | |
5203 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5204 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5205 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5206 { |
5207 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5208 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
|
5209 directories); |
2929 | 5210 } |
7 | 5211 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5212 { |
3106 | 5213 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5214 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5215 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5216 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5217 { |
5218 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5219 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5220 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5221 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5222 { |
5223 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
|
5224 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5225 } |
407 | 5226 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5227 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5228 return ExpandUserList(xp, num_file, file); |
407 | 5229 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5230 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5231 return ExpandPackAddDir(pat, num_file, file); |
7 | 5232 |
5233 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5234 if (regmatch.regprog == NULL) | |
5235 return FAIL; | |
5236 | |
5237 /* set ignore-case according to p_ic, p_scs and pat */ | |
5238 regmatch.rm_ic = ignorecase(pat); | |
5239 | |
5240 if (xp->xp_context == EXPAND_SETTINGS | |
5241 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5242 ret = ExpandSettings(xp, ®match, num_file, file); | |
5243 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5244 ret = ExpandMappings(®match, num_file, file); | |
5245 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5246 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5247 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5248 # endif | |
5249 else | |
5250 { | |
5251 static struct expgen | |
5252 { | |
5253 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5254 char_u *((*func)(expand_T *, int)); |
7 | 5255 int ic; |
2849 | 5256 int escaped; |
7 | 5257 } tab[] = |
5258 { | |
2849 | 5259 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5260 {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
|
5261 {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
|
5262 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5263 #ifdef FEAT_CMDHIST |
5264 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5265 #endif | |
7 | 5266 #ifdef FEAT_USR_CMDS |
2849 | 5267 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5268 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5269 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5270 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5271 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5272 #endif |
5273 #ifdef FEAT_EVAL | |
2849 | 5274 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5275 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5276 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5277 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5278 #endif |
5279 #ifdef FEAT_MENU | |
2849 | 5280 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5281 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5282 #endif |
5283 #ifdef FEAT_SYN_HL | |
2849 | 5284 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5285 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5286 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5287 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5288 #endif |
2849 | 5289 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5290 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5291 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5292 #ifdef FEAT_CSCOPE |
2849 | 5293 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5294 #endif |
1868 | 5295 #ifdef FEAT_SIGNS |
2849 | 5296 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5297 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5298 #ifdef FEAT_PROFILE |
2849 | 5299 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5300 #endif |
7 | 5301 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5302 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5303 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5304 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5305 #endif | |
5306 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5307 {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
|
5308 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5309 }; |
5310 int i; | |
5311 | |
5312 /* | |
5313 * Find a context in the table and call the ExpandGeneric() with the | |
5314 * right function to do the expansion. | |
5315 */ | |
5316 ret = FAIL; | |
1880 | 5317 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5318 if (xp->xp_context == tab[i].context) |
5319 { | |
5320 if (tab[i].ic) | |
5321 regmatch.rm_ic = TRUE; | |
2849 | 5322 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5323 tab[i].func, tab[i].escaped); |
7 | 5324 break; |
5325 } | |
5326 } | |
5327 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5328 vim_regfree(regmatch.regprog); |
7 | 5329 |
5330 return ret; | |
5331 #endif /* FEAT_CMDL_COMPL */ | |
5332 } | |
5333 | |
5334 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5335 /* | |
5336 * Expand a list of names. | |
5337 * | |
5338 * Generic function for command line completion. It calls a function to | |
5339 * obtain strings, one by one. The strings are matched against a regexp | |
5340 * program. Matching strings are copied into an array, which is returned. | |
5341 * | |
5342 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5343 */ | |
5344 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5345 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5346 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5347 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5348 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5349 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5350 char_u *((*func)(expand_T *, int)), |
7 | 5351 /* 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
|
5352 int escaped) |
7 | 5353 { |
5354 int i; | |
5355 int count = 0; | |
480 | 5356 int round; |
7 | 5357 char_u *str; |
5358 | |
5359 /* do this loop twice: | |
480 | 5360 * round == 0: count the number of matching names |
5361 * round == 1: copy the matching names into allocated memory | |
7 | 5362 */ |
480 | 5363 for (round = 0; round <= 1; ++round) |
7 | 5364 { |
5365 for (i = 0; ; ++i) | |
5366 { | |
5367 str = (*func)(xp, i); | |
5368 if (str == NULL) /* end of list */ | |
5369 break; | |
5370 if (*str == NUL) /* skip empty strings */ | |
5371 continue; | |
5372 | |
5373 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5374 { | |
480 | 5375 if (round) |
7 | 5376 { |
2849 | 5377 if (escaped) |
5378 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5379 else | |
5380 str = vim_strsave(str); | |
7 | 5381 (*file)[count] = str; |
5382 #ifdef FEAT_MENU | |
5383 if (func == get_menu_names && str != NULL) | |
5384 { | |
5385 /* test for separator added by get_menu_names() */ | |
5386 str += STRLEN(str) - 1; | |
5387 if (*str == '\001') | |
5388 *str = '.'; | |
5389 } | |
5390 #endif | |
5391 } | |
5392 ++count; | |
5393 } | |
5394 } | |
480 | 5395 if (round == 0) |
7 | 5396 { |
5397 if (count == 0) | |
5398 return OK; | |
5399 *num_file = count; | |
5400 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5401 if (*file == NULL) | |
5402 { | |
5403 *file = (char_u **)""; | |
5404 return FAIL; | |
5405 } | |
5406 count = 0; | |
5407 } | |
5408 } | |
480 | 5409 |
828 | 5410 /* Sort the results. Keep menu's in the specified order. */ |
5411 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5412 { |
5413 if (xp->xp_context == EXPAND_EXPRESSION | |
5414 || xp->xp_context == EXPAND_FUNCTIONS | |
5415 || xp->xp_context == EXPAND_USER_FUNC) | |
5416 /* <SNR> functions should be sorted to the end. */ | |
5417 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5418 sort_func_compare); | |
5419 else | |
5420 sort_strings(*file, *num_file); | |
5421 } | |
480 | 5422 |
1322 | 5423 #ifdef FEAT_CMDL_COMPL |
5424 /* Reset the variables used for special highlight names expansion, so that | |
5425 * they don't show up when getting normal highlight names by ID. */ | |
5426 reset_expand_highlight(); | |
5427 #endif | |
5428 | |
7 | 5429 return OK; |
5430 } | |
5431 | |
716 | 5432 /* |
5433 * Complete a shell command. | |
5434 * Returns FAIL or OK; | |
5435 */ | |
5436 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5437 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5438 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
|
5439 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
|
5440 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
|
5441 int flagsarg) /* EW_ flags */ |
716 | 5442 { |
5443 char_u *pat; | |
5444 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5445 char_u *path = NULL; |
716 | 5446 int mustfree = FALSE; |
5447 garray_T ga; | |
5448 char_u *buf = alloc(MAXPATHL); | |
5449 size_t l; | |
5450 char_u *s, *e; | |
5451 int flags = flagsarg; | |
5452 int ret; | |
6695 | 5453 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5454 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5455 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5456 hash_T hash; |
716 | 5457 |
5458 if (buf == NULL) | |
5459 return FAIL; | |
5460 | |
5461 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5462 * space */ | |
5463 pat = vim_strsave(filepat); | |
5464 for (i = 0; pat[i]; ++i) | |
5465 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5466 STRMOVE(pat + i, pat + i + 1); |
716 | 5467 |
6695 | 5468 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5469 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5470 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
|
5471 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5472 path = (char_u *)"."; |
5473 else | |
2630 | 5474 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5475 /* 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
|
5476 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5477 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5478 if (path == NULL) |
5479 path = (char_u *)""; | |
5480 } | |
716 | 5481 |
5482 /* | |
5483 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5484 * collect them in "ga". When "." is not in $PATH also expand for the |
5485 * current directory, to find "subdir/cmd". | |
716 | 5486 */ |
5487 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
|
5488 hash_init(&found_ht); |
6695 | 5489 for (s = path; ; s = e) |
716 | 5490 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5491 #if defined(MSWIN) |
716 | 5492 e = vim_strchr(s, ';'); |
5493 #else | |
5494 e = vim_strchr(s, ':'); | |
5495 #endif | |
5496 if (e == NULL) | |
5497 e = s + STRLEN(s); | |
5498 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5499 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
|
5500 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5501 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
|
5502 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5503 // 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
|
5504 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
|
5505 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
|
5506 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5507 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
|
5508 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5509 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
|
5510 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
|
5511 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5512 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5513 // 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
|
5514 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
|
5515 |
716 | 5516 l = e - s; |
5517 if (l > MAXPATHL - 5) | |
5518 break; | |
5519 vim_strncpy(buf, s, l); | |
5520 add_pathsep(buf); | |
5521 l = STRLEN(buf); | |
5522 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5523 | |
5524 /* Expand matches in one directory of $PATH. */ | |
5525 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5526 if (ret == OK) | |
5527 { | |
5528 if (ga_grow(&ga, *num_file) == FAIL) | |
5529 FreeWild(*num_file, *file); | |
5530 else | |
5531 { | |
5532 for (i = 0; i < *num_file; ++i) | |
5533 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5534 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5535 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5536 if (STRLEN(name) > l) |
716 | 5537 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5538 // 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
|
5539 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5540 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
|
5541 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5542 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5543 // 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
|
5544 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5545 ((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
|
5546 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
|
5547 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5548 } |
716 | 5549 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5550 vim_free(name); |
716 | 5551 } |
5552 vim_free(*file); | |
5553 } | |
5554 } | |
5555 if (*e != NUL) | |
5556 ++e; | |
5557 } | |
5558 *file = ga.ga_data; | |
5559 *num_file = ga.ga_len; | |
5560 | |
5561 vim_free(buf); | |
5562 vim_free(pat); | |
5563 if (mustfree) | |
5564 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5565 hash_clear(&found_ht); |
716 | 5566 return OK; |
5567 } | |
5568 | |
5569 | |
7 | 5570 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5571 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5572 * 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
|
5573 * return the result (either a string or a List). |
7 | 5574 */ |
407 | 5575 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5576 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
|
5577 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
|
5578 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5579 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5580 char_u ***file) |
7 | 5581 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5582 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
|
5583 typval_T args[4]; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5584 sctx_T save_current_sctx = current_sctx; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5585 char_u *pat = NULL; |
407 | 5586 void *ret; |
7 | 5587 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5588 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5589 return NULL; |
7 | 5590 *num_file = 0; |
5591 *file = NULL; | |
5592 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5593 if (ccline.cmdbuff != NULL) |
1518 | 5594 { |
5595 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5596 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5597 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5598 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5599 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
|
5600 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5601 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
|
5602 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
|
5603 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
|
5604 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
|
5605 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
|
5606 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
|
5607 args[3].v_type = VAR_UNKNOWN; |
7 | 5608 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5609 current_sctx = xp->xp_script_ctx; |
13 | 5610 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5611 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5612 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5613 current_sctx = save_current_sctx; |
1518 | 5614 if (ccline.cmdbuff != NULL) |
5615 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5616 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5617 vim_free(pat); |
407 | 5618 return ret; |
5619 } | |
5620 | |
5621 /* | |
5622 * Expand names with a function defined by the user. | |
5623 */ | |
5624 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5625 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5626 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5627 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5628 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5629 char_u ***file) |
407 | 5630 { |
5631 char_u *retstr; | |
5632 char_u *s; | |
5633 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
|
5634 int keep; |
407 | 5635 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
|
5636 int skip; |
407 | 5637 |
5638 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5639 if (retstr == NULL) | |
7 | 5640 return FAIL; |
5641 | |
5642 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5643 for (s = retstr; *s != NUL; s = e) |
7 | 5644 { |
5645 e = vim_strchr(s, '\n'); | |
5646 if (e == NULL) | |
5647 e = s + STRLEN(s); | |
5648 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
|
5649 *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
|
5650 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5651 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
|
5652 *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
|
5653 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5654 if (!skip) |
7 | 5655 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5656 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
|
5657 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5658 ((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
|
5659 ++ga.ga_len; |
7 | 5660 } |
5661 | |
5662 if (*e != NUL) | |
5663 ++e; | |
5664 } | |
407 | 5665 vim_free(retstr); |
5666 *file = ga.ga_data; | |
5667 *num_file = ga.ga_len; | |
5668 return OK; | |
5669 } | |
5670 | |
5671 /* | |
5672 * Expand names with a list returned by a function defined by the user. | |
5673 */ | |
5674 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5675 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5676 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5677 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5678 char_u ***file) |
407 | 5679 { |
5680 list_T *retlist; | |
5681 listitem_T *li; | |
5682 garray_T ga; | |
5683 | |
5684 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5685 if (retlist == NULL) | |
5686 return FAIL; | |
5687 | |
5688 ga_init2(&ga, (int)sizeof(char *), 3); | |
5689 /* Loop over the items in the list. */ | |
5690 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5691 { | |
1917 | 5692 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5693 continue; /* Skip non-string items and empty strings */ | |
407 | 5694 |
5695 if (ga_grow(&ga, 1) == FAIL) | |
5696 break; | |
5697 | |
5698 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5699 vim_strsave(li->li_tv.vval.v_string); |
407 | 5700 ++ga.ga_len; |
5701 } | |
5702 list_unref(retlist); | |
5703 | |
7 | 5704 *file = ga.ga_data; |
5705 *num_file = ga.ga_len; | |
5706 return OK; | |
5707 } | |
5708 #endif | |
5709 | |
5710 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5711 * 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
|
5712 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5713 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5714 * 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
|
5715 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5716 * 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
|
5717 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5718 * "dirnames" is an array with one or more directory names. |
7 | 5719 */ |
5720 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5721 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5722 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5723 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5724 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5725 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5726 char *dirnames[]) |
7 | 5727 { |
5728 char_u *s; | |
5729 char_u *e; | |
5873 | 5730 char_u *match; |
7 | 5731 garray_T ga; |
2929 | 5732 int i; |
5733 int pat_len; | |
7 | 5734 |
5735 *num_file = 0; | |
5736 *file = NULL; | |
2931 | 5737 pat_len = (int)STRLEN(pat); |
2929 | 5738 ga_init2(&ga, (int)sizeof(char *), 10); |
5739 | |
5740 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5741 { |
2929 | 5742 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5743 if (s == NULL) | |
5744 { | |
5745 ga_clear_strings(&ga); | |
5746 return FAIL; | |
5747 } | |
5748 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5749 globpath(p_rtp, s, &ga, 0); |
2929 | 5750 vim_free(s); |
5873 | 5751 } |
5752 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5753 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5754 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
|
5755 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5756 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
|
5757 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5758 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5759 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5760 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5761 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5762 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
|
5763 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5764 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5765 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5766 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5767 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5768 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5769 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
|
5770 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5771 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
|
5772 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5773 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5774 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5775 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5776 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5777 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
|
5778 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5779 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5780 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5781 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5782 |
5873 | 5783 for (i = 0; i < ga.ga_len; ++i) |
5784 { | |
5785 match = ((char_u **)ga.ga_data)[i]; | |
5786 s = match; | |
5787 e = s + STRLEN(s); | |
5788 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5789 { |
5873 | 5790 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5791 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5792 if (s < match || vim_ispathsep(*s)) |
5793 break; | |
5794 ++s; | |
5795 *e = NUL; | |
5796 mch_memmove(match, s, e - s + 1); | |
7 | 5797 } |
5798 } | |
5873 | 5799 |
2929 | 5800 if (ga.ga_len == 0) |
3628 | 5801 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5802 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5803 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5804 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5805 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5806 |
7 | 5807 *file = ga.ga_data; |
5808 *num_file = ga.ga_len; | |
5809 return OK; | |
5810 } | |
5811 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5815 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5816 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5817 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5818 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5819 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5820 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5821 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5822 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5823 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5824 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5827 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5828 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5830 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5832 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
|
5833 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5834 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5835 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 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
|
5841 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5842 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5843 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5844 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
|
5845 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5846 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
|
5847 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5849 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
|
5850 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5851 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5852 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5853 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5854 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5855 /* 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
|
5856 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5857 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5858 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5859 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5860 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5861 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5862 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5863 |
7 | 5864 #endif |
5865 | |
5866 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5867 /* | |
5868 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5869 * Adds the matches to "ga". Caller must init "ga". |
7 | 5870 */ |
5873 | 5871 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5872 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5873 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5874 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5875 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5876 int expand_options) |
7 | 5877 { |
5878 expand_T xpc; | |
5879 char_u *buf; | |
5880 int i; | |
5881 int num_p; | |
5882 char_u **p; | |
5883 | |
5884 buf = alloc(MAXPATHL); | |
5885 if (buf == NULL) | |
5873 | 5886 return; |
7 | 5887 |
632 | 5888 ExpandInit(&xpc); |
7 | 5889 xpc.xp_context = EXPAND_FILES; |
632 | 5890 |
7 | 5891 /* Loop over all entries in {path}. */ |
5892 while (*path != NUL) | |
5893 { | |
5894 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5895 copy_option_part(&path, buf, MAXPATHL, ","); | |
5896 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5897 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5898 # 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
|
5899 /* 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
|
5900 * 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
|
5901 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
|
5902 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5903 # else |
7 | 5904 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
|
5905 # endif |
7 | 5906 STRCAT(buf, file); |
1754 | 5907 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5908 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5909 { |
1754 | 5910 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5911 |
5912 if (ga_grow(ga, num_p) == OK) | |
7 | 5913 { |
5914 for (i = 0; i < num_p; ++i) | |
5915 { | |
5873 | 5916 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5917 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5918 ++ga->ga_len; |
7 | 5919 } |
5920 } | |
5873 | 5921 |
7 | 5922 FreeWild(num_p, p); |
5923 } | |
5924 } | |
5925 } | |
5926 | |
5927 vim_free(buf); | |
5928 } | |
5929 | |
5930 #endif | |
5931 | |
5932 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5933 | |
5934 /********************************* | |
5935 * Command line history stuff * | |
5936 *********************************/ | |
5937 | |
5938 /* | |
5939 * Translate a history character to the associated type number. | |
5940 */ | |
5941 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5942 hist_char2type(int c) |
7 | 5943 { |
5944 if (c == ':') | |
5945 return HIST_CMD; | |
5946 if (c == '=') | |
5947 return HIST_EXPR; | |
5948 if (c == '@') | |
5949 return HIST_INPUT; | |
5950 if (c == '>') | |
5951 return HIST_DEBUG; | |
5952 return HIST_SEARCH; /* must be '?' or '/' */ | |
5953 } | |
5954 | |
5955 /* | |
5956 * Table of history names. | |
5957 * These names are used in :history and various hist...() functions. | |
5958 * It is sufficient to give the significant prefix of a history name. | |
5959 */ | |
5960 | |
5961 static char *(history_names[]) = | |
5962 { | |
5963 "cmd", | |
5964 "search", | |
5965 "expr", | |
5966 "input", | |
5967 "debug", | |
5968 NULL | |
5969 }; | |
5970 | |
3503 | 5971 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5972 /* | |
5973 * Function given to ExpandGeneric() to obtain the possible first | |
5974 * arguments of the ":history command. | |
5975 */ | |
5976 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5977 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5978 { |
5979 static char_u compl[2] = { NUL, NUL }; | |
5980 char *short_names = ":=@>?/"; | |
3529 | 5981 int short_names_count = (int)STRLEN(short_names); |
3503 | 5982 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5983 | |
5984 if (idx < short_names_count) | |
5985 { | |
5986 compl[0] = (char_u)short_names[idx]; | |
5987 return compl; | |
5988 } | |
5989 if (idx < short_names_count + history_name_count) | |
5990 return (char_u *)history_names[idx - short_names_count]; | |
5991 if (idx == short_names_count + history_name_count) | |
5992 return (char_u *)"all"; | |
5993 return NULL; | |
5994 } | |
5995 #endif | |
5996 | |
7 | 5997 /* |
5998 * init_history() - Initialize the command line history. | |
5999 * Also used to re-allocate the history when the size changes. | |
6000 */ | |
356 | 6001 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6002 init_history(void) |
7 | 6003 { |
6004 int newlen; /* new length of history table */ | |
6005 histentry_T *temp; | |
6006 int i; | |
6007 int j; | |
6008 int type; | |
6009 | |
6010 /* | |
6011 * If size of history table changed, reallocate it | |
6012 */ | |
6013 newlen = (int)p_hi; | |
6014 if (newlen != hislen) /* history length changed */ | |
6015 { | |
6016 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6017 { | |
6018 if (newlen) | |
6019 { | |
6020 temp = (histentry_T *)lalloc( | |
6021 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6022 if (temp == NULL) /* out of memory! */ | |
6023 { | |
6024 if (type == 0) /* first one: just keep the old length */ | |
6025 { | |
6026 newlen = hislen; | |
6027 break; | |
6028 } | |
6029 /* Already changed one table, now we can only have zero | |
6030 * length for all tables. */ | |
6031 newlen = 0; | |
6032 type = -1; | |
6033 continue; | |
6034 } | |
6035 } | |
6036 else | |
6037 temp = NULL; | |
6038 if (newlen == 0 || temp != NULL) | |
6039 { | |
6040 if (hisidx[type] < 0) /* there are no entries yet */ | |
6041 { | |
6042 for (i = 0; i < newlen; ++i) | |
4258 | 6043 clear_hist_entry(&temp[i]); |
7 | 6044 } |
6045 else if (newlen > hislen) /* array becomes bigger */ | |
6046 { | |
6047 for (i = 0; i <= hisidx[type]; ++i) | |
6048 temp[i] = history[type][i]; | |
6049 j = i; | |
6050 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6051 clear_hist_entry(&temp[i]); |
7 | 6052 for ( ; j < hislen; ++i, ++j) |
6053 temp[i] = history[type][j]; | |
6054 } | |
6055 else /* array becomes smaller or 0 */ | |
6056 { | |
6057 j = hisidx[type]; | |
6058 for (i = newlen - 1; ; --i) | |
6059 { | |
6060 if (i >= 0) /* copy newest entries */ | |
6061 temp[i] = history[type][j]; | |
6062 else /* remove older entries */ | |
6063 vim_free(history[type][j].hisstr); | |
6064 if (--j < 0) | |
6065 j = hislen - 1; | |
6066 if (j == hisidx[type]) | |
6067 break; | |
6068 } | |
6069 hisidx[type] = newlen - 1; | |
6070 } | |
6071 vim_free(history[type]); | |
6072 history[type] = temp; | |
6073 } | |
6074 } | |
6075 hislen = newlen; | |
6076 } | |
6077 } | |
6078 | |
4258 | 6079 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6080 clear_hist_entry(histentry_T *hisptr) |
4258 | 6081 { |
6082 hisptr->hisnum = 0; | |
6083 hisptr->viminfo = FALSE; | |
6084 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6085 hisptr->time_set = 0; |
4258 | 6086 } |
6087 | |
7 | 6088 /* |
6089 * Check if command line 'str' is already in history. | |
6090 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6091 */ | |
6092 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6093 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6094 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6095 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6096 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
|
6097 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6098 int writing) /* ignore entries read from viminfo */ |
7 | 6099 { |
6100 int i; | |
6101 int last_i = -1; | |
2986 | 6102 char_u *p; |
7 | 6103 |
6104 if (hisidx[type] < 0) | |
6105 return FALSE; | |
6106 i = hisidx[type]; | |
6107 do | |
6108 { | |
6109 if (history[type][i].hisstr == NULL) | |
6110 return FALSE; | |
2986 | 6111 |
6112 /* For search history, check that the separator character matches as | |
6113 * well. */ | |
6114 p = history[type][i].hisstr; | |
6115 if (STRCMP(str, p) == 0 | |
4285 | 6116 && !(writing && history[type][i].viminfo) |
2986 | 6117 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6118 { |
6119 if (!move_to_front) | |
6120 return TRUE; | |
6121 last_i = i; | |
6122 break; | |
6123 } | |
6124 if (--i < 0) | |
6125 i = hislen - 1; | |
6126 } while (i != hisidx[type]); | |
6127 | |
6128 if (last_i >= 0) | |
6129 { | |
6130 str = history[type][i].hisstr; | |
6131 while (i != hisidx[type]) | |
6132 { | |
6133 if (++i >= hislen) | |
6134 i = 0; | |
6135 history[type][last_i] = history[type][i]; | |
6136 last_i = i; | |
6137 } | |
4258 | 6138 history[type][i].hisnum = ++hisnum[type]; |
6139 history[type][i].viminfo = FALSE; | |
7 | 6140 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6141 history[type][i].time_set = vim_time(); |
7 | 6142 return TRUE; |
6143 } | |
6144 return FALSE; | |
6145 } | |
6146 | |
6147 /* | |
6148 * Convert history name (from table above) to its HIST_ equivalent. | |
6149 * When "name" is empty, return "cmd" history. | |
6150 * Returns -1 for unknown history name. | |
6151 */ | |
6152 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6153 get_histtype(char_u *name) |
7 | 6154 { |
6155 int i; | |
6156 int len = (int)STRLEN(name); | |
6157 | |
6158 /* No argument: use current history. */ | |
6159 if (len == 0) | |
6160 return hist_char2type(ccline.cmdfirstc); | |
6161 | |
6162 for (i = 0; history_names[i] != NULL; ++i) | |
6163 if (STRNICMP(name, history_names[i], len) == 0) | |
6164 return i; | |
6165 | |
6166 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6167 return hist_char2type(name[0]); | |
6168 | |
6169 return -1; | |
6170 } | |
6171 | |
6172 static int last_maptick = -1; /* last seen maptick */ | |
6173 | |
6174 /* | |
6175 * Add the given string to the given history. If the string is already in the | |
6176 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6177 * values. | |
6178 */ | |
6179 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6180 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6181 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6182 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6183 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
|
6184 int sep) /* separator character used (search hist) */ |
7 | 6185 { |
6186 histentry_T *hisptr; | |
6187 int len; | |
6188 | |
6189 if (hislen == 0) /* no history */ | |
6190 return; | |
6191 | |
5467 | 6192 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6193 return; | |
6194 | |
7 | 6195 /* |
6196 * Searches inside the same mapping overwrite each other, so that only | |
6197 * the last line is kept. Be careful not to remove a line that was moved | |
6198 * down, only lines that were added. | |
6199 */ | |
6200 if (histype == HIST_SEARCH && in_map) | |
6201 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6202 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6203 { |
6204 /* Current line is from the same mapping, remove it */ | |
6205 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6206 vim_free(hisptr->hisstr); | |
4258 | 6207 clear_hist_entry(hisptr); |
7 | 6208 --hisnum[histype]; |
6209 if (--hisidx[HIST_SEARCH] < 0) | |
6210 hisidx[HIST_SEARCH] = hislen - 1; | |
6211 } | |
6212 last_maptick = -1; | |
6213 } | |
4285 | 6214 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6215 { |
6216 if (++hisidx[histype] == hislen) | |
6217 hisidx[histype] = 0; | |
6218 hisptr = &history[histype][hisidx[histype]]; | |
6219 vim_free(hisptr->hisstr); | |
6220 | |
6221 /* Store the separator after the NUL of the string. */ | |
835 | 6222 len = (int)STRLEN(new_entry); |
7 | 6223 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6224 if (hisptr->hisstr != NULL) | |
6225 hisptr->hisstr[len + 1] = sep; | |
6226 | |
6227 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6228 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6229 hisptr->time_set = vim_time(); |
7 | 6230 if (histype == HIST_SEARCH && in_map) |
6231 last_maptick = maptick; | |
6232 } | |
6233 } | |
6234 | |
6235 #if defined(FEAT_EVAL) || defined(PROTO) | |
6236 | |
6237 /* | |
6238 * Get identifier of newest history entry. | |
6239 * "histype" may be one of the HIST_ values. | |
6240 */ | |
6241 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6242 get_history_idx(int histype) |
7 | 6243 { |
6244 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6245 || hisidx[histype] < 0) | |
6246 return -1; | |
6247 | |
6248 return history[histype][hisidx[histype]].hisnum; | |
6249 } | |
6250 | |
531 | 6251 /* |
7 | 6252 * Calculate history index from a number: |
6253 * num > 0: seen as identifying number of a history entry | |
6254 * num < 0: relative position in history wrt newest entry | |
6255 * "histype" may be one of the HIST_ values. | |
6256 */ | |
6257 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6258 calc_hist_idx(int histype, int num) |
7 | 6259 { |
6260 int i; | |
6261 histentry_T *hist; | |
6262 int wrapped = FALSE; | |
6263 | |
6264 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6265 || (i = hisidx[histype]) < 0 || num == 0) | |
6266 return -1; | |
6267 | |
6268 hist = history[histype]; | |
6269 if (num > 0) | |
6270 { | |
6271 while (hist[i].hisnum > num) | |
6272 if (--i < 0) | |
6273 { | |
6274 if (wrapped) | |
6275 break; | |
6276 i += hislen; | |
6277 wrapped = TRUE; | |
6278 } | |
6279 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6280 return i; | |
6281 } | |
6282 else if (-num <= hislen) | |
6283 { | |
6284 i += num + 1; | |
6285 if (i < 0) | |
6286 i += hislen; | |
6287 if (hist[i].hisstr != NULL) | |
6288 return i; | |
6289 } | |
6290 return -1; | |
6291 } | |
6292 | |
6293 /* | |
6294 * Get a history entry by its index. | |
6295 * "histype" may be one of the HIST_ values. | |
6296 */ | |
6297 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6298 get_history_entry(int histype, int idx) |
7 | 6299 { |
6300 idx = calc_hist_idx(histype, idx); | |
6301 if (idx >= 0) | |
6302 return history[histype][idx].hisstr; | |
6303 else | |
6304 return (char_u *)""; | |
6305 } | |
6306 | |
6307 /* | |
6308 * Clear all entries of a history. | |
6309 * "histype" may be one of the HIST_ values. | |
6310 */ | |
6311 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6312 clr_history(int histype) |
7 | 6313 { |
6314 int i; | |
6315 histentry_T *hisptr; | |
6316 | |
6317 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6318 { | |
6319 hisptr = history[histype]; | |
6320 for (i = hislen; i--;) | |
6321 { | |
6322 vim_free(hisptr->hisstr); | |
4258 | 6323 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6324 hisptr++; |
7 | 6325 } |
6326 hisidx[histype] = -1; /* mark history as cleared */ | |
6327 hisnum[histype] = 0; /* reset identifier counter */ | |
6328 return OK; | |
6329 } | |
6330 return FAIL; | |
6331 } | |
6332 | |
6333 /* | |
6334 * Remove all entries matching {str} from a history. | |
6335 * "histype" may be one of the HIST_ values. | |
6336 */ | |
6337 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6338 del_history_entry(int histype, char_u *str) |
7 | 6339 { |
6340 regmatch_T regmatch; | |
6341 histentry_T *hisptr; | |
6342 int idx; | |
6343 int i; | |
6344 int last; | |
6345 int found = FALSE; | |
6346 | |
6347 regmatch.regprog = NULL; | |
6348 regmatch.rm_ic = FALSE; /* always match case */ | |
6349 if (hislen != 0 | |
6350 && histype >= 0 | |
6351 && histype < HIST_COUNT | |
6352 && *str != NUL | |
6353 && (idx = hisidx[histype]) >= 0 | |
6354 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6355 != NULL) | |
6356 { | |
6357 i = last = idx; | |
6358 do | |
6359 { | |
6360 hisptr = &history[histype][i]; | |
6361 if (hisptr->hisstr == NULL) | |
6362 break; | |
6363 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6364 { | |
6365 found = TRUE; | |
6366 vim_free(hisptr->hisstr); | |
4258 | 6367 clear_hist_entry(hisptr); |
7 | 6368 } |
6369 else | |
6370 { | |
6371 if (i != last) | |
6372 { | |
6373 history[histype][last] = *hisptr; | |
4258 | 6374 clear_hist_entry(hisptr); |
7 | 6375 } |
6376 if (--last < 0) | |
6377 last += hislen; | |
6378 } | |
6379 if (--i < 0) | |
6380 i += hislen; | |
6381 } while (i != idx); | |
6382 if (history[histype][idx].hisstr == NULL) | |
6383 hisidx[histype] = -1; | |
6384 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6385 vim_regfree(regmatch.regprog); |
7 | 6386 return found; |
6387 } | |
6388 | |
6389 /* | |
6390 * Remove an indexed entry from a history. | |
6391 * "histype" may be one of the HIST_ values. | |
6392 */ | |
6393 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6394 del_history_idx(int histype, int idx) |
7 | 6395 { |
6396 int i, j; | |
6397 | |
6398 i = calc_hist_idx(histype, idx); | |
6399 if (i < 0) | |
6400 return FALSE; | |
6401 idx = hisidx[histype]; | |
6402 vim_free(history[histype][i].hisstr); | |
6403 | |
6404 /* When deleting the last added search string in a mapping, reset | |
6405 * last_maptick, so that the last added search string isn't deleted again. | |
6406 */ | |
6407 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6408 last_maptick = -1; | |
6409 | |
6410 while (i != idx) | |
6411 { | |
6412 j = (i + 1) % hislen; | |
6413 history[histype][i] = history[histype][j]; | |
6414 i = j; | |
6415 } | |
4258 | 6416 clear_hist_entry(&history[histype][i]); |
7 | 6417 if (--i < 0) |
6418 i += hislen; | |
6419 hisidx[histype] = i; | |
6420 return TRUE; | |
6421 } | |
6422 | |
6423 #endif /* FEAT_EVAL */ | |
6424 | |
6425 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6426 /* | |
6427 * Very specific function to remove the value in ":set key=val" from the | |
6428 * history. | |
6429 */ | |
6430 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6431 remove_key_from_history(void) |
7 | 6432 { |
6433 char_u *p; | |
6434 int i; | |
6435 | |
6436 i = hisidx[HIST_CMD]; | |
6437 if (i < 0) | |
6438 return; | |
6439 p = history[HIST_CMD][i].hisstr; | |
6440 if (p != NULL) | |
6441 for ( ; *p; ++p) | |
6442 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6443 { | |
6444 p = vim_strchr(p + 3, '='); | |
6445 if (p == NULL) | |
6446 break; | |
6447 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6448 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6449 if (p[i] == '\\' && p[i + 1]) |
6450 ++i; | |
1621 | 6451 STRMOVE(p, p + i); |
7 | 6452 --p; |
6453 } | |
6454 } | |
6455 #endif | |
6456 | |
6457 #endif /* FEAT_CMDHIST */ | |
6458 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6459 #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
|
6460 /* |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
6461 * Get pointer to the command line info to use. save_ccline() may clear |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 * 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
|
6463 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 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
|
6472 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6475 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6476 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6477 #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
|
6478 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 * 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
|
6480 * 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
|
6481 * Returns NULL when something is wrong. |
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 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 { |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6486 struct cmdline_info *p; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6487 |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6488 if (cmdline_star > 0) |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6489 return NULL; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6490 p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 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
|
6494 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6495 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6496 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 * 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
|
6498 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 * 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
|
6500 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6501 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6503 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6504 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 struct cmdline_info *p = get_ccline_ptr(); |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6506 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6507 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6509 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6510 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6511 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6512 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6513 * 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
|
6514 * 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
|
6515 * 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
|
6516 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6517 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6519 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6521 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
|
6522 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6524 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6525 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6526 /* 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
|
6527 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6528 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6529 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6532 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6533 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6534 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6535 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6536 #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
|
6537 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6538 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6539 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 * 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
|
6541 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6542 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6543 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6544 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6545 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6546 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
|
6547 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6548 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6549 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6550 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6551 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6552 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6553 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6554 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6555 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6556 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6557 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6558 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6559 |
7 | 6560 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6561 /* | |
6562 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6563 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6564 * Returns OK if parsed successfully, otherwise FAIL. | |
6565 */ | |
6566 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6567 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6568 { |
6569 int len; | |
6570 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6571 varnumber_T num; |
7 | 6572 |
6573 *str = skipwhite(*str); | |
6574 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6575 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6576 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6577 *str += len; |
6578 *num1 = (int)num; | |
6579 first = TRUE; | |
6580 } | |
6581 *str = skipwhite(*str); | |
6582 if (**str == ',') /* parse "to" part of range */ | |
6583 { | |
6584 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6585 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6586 if (len > 0) |
6587 { | |
6588 *num2 = (int)num; | |
6589 *str = skipwhite(*str + len); | |
6590 } | |
6591 else if (!first) /* no number given at all */ | |
6592 return FAIL; | |
6593 } | |
6594 else if (first) /* only one number given */ | |
6595 *num2 = *num1; | |
6596 return OK; | |
6597 } | |
6598 #endif | |
6599 | |
6600 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6601 /* | |
6602 * :history command - print a history | |
6603 */ | |
6604 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6605 ex_history(exarg_T *eap) |
7 | 6606 { |
6607 histentry_T *hist; | |
6608 int histype1 = HIST_CMD; | |
6609 int histype2 = HIST_CMD; | |
6610 int hisidx1 = 1; | |
6611 int hisidx2 = -1; | |
6612 int idx; | |
6613 int i, j, k; | |
6614 char_u *end; | |
6615 char_u *arg = eap->arg; | |
6616 | |
6617 if (hislen == 0) | |
6618 { | |
6619 MSG(_("'history' option is zero")); | |
6620 return; | |
6621 } | |
6622 | |
6623 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6624 { | |
6625 end = arg; | |
6626 while (ASCII_ISALPHA(*end) | |
6627 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6628 end++; | |
6629 i = *end; | |
6630 *end = NUL; | |
6631 histype1 = get_histtype(arg); | |
6632 if (histype1 == -1) | |
6633 { | |
1853 | 6634 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6635 { |
6636 histype1 = 0; | |
6637 histype2 = HIST_COUNT-1; | |
6638 } | |
6639 else | |
6640 { | |
6641 *end = i; | |
6642 EMSG(_(e_trailing)); | |
6643 return; | |
6644 } | |
6645 } | |
6646 else | |
6647 histype2 = histype1; | |
6648 *end = i; | |
6649 } | |
6650 else | |
6651 end = arg; | |
6652 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6653 { | |
6654 EMSG(_(e_trailing)); | |
6655 return; | |
6656 } | |
6657 | |
6658 for (; !got_int && histype1 <= histype2; ++histype1) | |
6659 { | |
6660 STRCPY(IObuff, "\n # "); | |
6661 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6662 MSG_PUTS_TITLE(IObuff); | |
6663 idx = hisidx[histype1]; | |
6664 hist = history[histype1]; | |
6665 j = hisidx1; | |
6666 k = hisidx2; | |
6667 if (j < 0) | |
6668 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6669 if (k < 0) | |
6670 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6671 if (idx >= 0 && j <= k) | |
6672 for (i = idx + 1; !got_int; ++i) | |
6673 { | |
6674 if (i == hislen) | |
6675 i = 0; | |
6676 if (hist[i].hisstr != NULL | |
6677 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6678 { | |
6679 msg_putchar('\n'); | |
6680 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6681 hist[i].hisnum); | |
6682 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6683 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6684 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6685 else |
6686 STRCAT(IObuff, hist[i].hisstr); | |
6687 msg_outtrans(IObuff); | |
6688 out_flush(); | |
6689 } | |
6690 if (i == idx) | |
6691 break; | |
6692 } | |
6693 } | |
6694 } | |
6695 #endif | |
6696 | |
6697 #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
|
6698 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6699 * 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
|
6700 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6701 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
|
6702 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6703 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
|
6704 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6705 static int viminfo_add_at_front = FALSE; |
6706 | |
6707 /* | |
6708 * Translate a history type number to the associated character. | |
6709 */ | |
6710 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6711 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6712 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6713 int use_question) /* use '?' instead of '/' */ |
7 | 6714 { |
6715 if (type == HIST_CMD) | |
6716 return ':'; | |
6717 if (type == HIST_SEARCH) | |
6718 { | |
6719 if (use_question) | |
6720 return '?'; | |
6721 else | |
6722 return '/'; | |
6723 } | |
6724 if (type == HIST_EXPR) | |
6725 return '='; | |
6726 return '@'; | |
6727 } | |
6728 | |
6729 /* | |
6730 * Prepare for reading the history from the viminfo file. | |
6731 * This allocates history arrays to store the read history lines. | |
6732 */ | |
6733 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6734 prepare_viminfo_history(int asklen, int writing) |
7 | 6735 { |
6736 int i; | |
6737 int num; | |
6738 int type; | |
6739 int len; | |
6740 | |
6741 init_history(); | |
4285 | 6742 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6743 if (asklen > hislen) |
6744 asklen = hislen; | |
6745 | |
6746 for (type = 0; type < HIST_COUNT; ++type) | |
6747 { | |
4258 | 6748 /* Count the number of empty spaces in the history list. Entries read |
6749 * from viminfo previously are also considered empty. If there are | |
6750 * more spaces available than we request, then fill them up. */ | |
7 | 6751 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6752 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6753 num++; |
6754 len = asklen; | |
6755 if (num > len) | |
6756 len = num; | |
6757 if (len <= 0) | |
6758 viminfo_history[type] = NULL; | |
6759 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6762 if (viminfo_history[type] == NULL) |
6763 len = 0; | |
6764 viminfo_hislen[type] = len; | |
6765 viminfo_hisidx[type] = 0; | |
6766 } | |
6767 } | |
6768 | |
6769 /* | |
6770 * Accept a line from the viminfo, store it in the history array when it's | |
6771 * new. | |
6772 */ | |
6773 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6774 read_viminfo_history(vir_T *virp, int writing) |
7 | 6775 { |
6776 int type; | |
6777 long_u len; | |
6778 char_u *val; | |
6779 char_u *p; | |
6780 | |
6781 type = hist_char2type(virp->vir_line[0]); | |
6782 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6783 { | |
6784 val = viminfo_readstring(virp, 1, TRUE); | |
6785 if (val != NULL && *val != NUL) | |
6786 { | |
3316 | 6787 int sep = (*val == ' ' ? NUL : *val); |
6788 | |
7 | 6789 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6790 viminfo_add_at_front, sep, writing)) |
7 | 6791 { |
6792 /* Need to re-allocate to append the separator byte. */ | |
6793 len = STRLEN(val); | |
6794 p = lalloc(len + 2, TRUE); | |
6795 if (p != NULL) | |
6796 { | |
6797 if (type == HIST_SEARCH) | |
6798 { | |
6799 /* Search entry: Move the separator from the first | |
6800 * column to after the NUL. */ | |
6801 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6802 p[len] = sep; |
7 | 6803 } |
6804 else | |
6805 { | |
6806 /* Not a search entry: No separator in the viminfo | |
6807 * file, add a NUL separator. */ | |
6808 mch_memmove(p, val, (size_t)len + 1); | |
6809 p[len + 1] = NUL; | |
6810 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 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
|
6812 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
|
6813 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
|
6814 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
|
6815 viminfo_hisidx[type]++; |
7 | 6816 } |
6817 } | |
6818 } | |
6819 vim_free(val); | |
6820 } | |
6821 return viminfo_readline(virp); | |
6822 } | |
6823 | |
4285 | 6824 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 * 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
|
6826 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6830 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6831 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6832 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6834 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6837 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
|
6838 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6841 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6842 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6843 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6844 || (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
|
6845 || 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
|
6846 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6848 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6850 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6851 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
|
6852 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6853 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6855 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6856 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
|
6857 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6858 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6859 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 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
|
6862 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6863 /* 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
|
6864 * 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
|
6865 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
|
6866 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6868 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6869 && (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
|
6870 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6871 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6872 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6873 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6874 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6875 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6876 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6877 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6878 /* 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
|
6879 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6880 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6881 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6882 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6883 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6885 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6886 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
|
6887 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6888 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6889 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
|
6890 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6891 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6892 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
|
6893 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 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
|
6895 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6896 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6897 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6898 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6899 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6900 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6901 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6902 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6903 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 * 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
|
6905 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 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
|
6935 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 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
|
6938 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 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
|
6940 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 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
|
6946 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 } |
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 #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
|
6953 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 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
|
6958 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 histentry_T *p2 = *(histentry_T **)s2; |
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 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
|
6963 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
|
6964 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6965 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6968 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 * 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
|
6970 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6978 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6979 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 /* 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
|
6982 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6983 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
|
6984 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
|
6985 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
|
6986 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 return; |
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 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
|
6992 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
|
6993 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6996 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6997 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6999 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
|
7000 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7003 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7004 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7005 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7007 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7008 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7009 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7010 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7011 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7012 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7013 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7014 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
|
7015 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7017 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
|
7018 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
|
7019 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7020 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7021 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7022 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7023 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7024 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7025 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7026 /* |
4285 | 7027 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7028 */ | |
7 | 7029 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7030 finish_viminfo_history(vir_T *virp) |
7 | 7031 { |
7032 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7033 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7034 |
7035 for (type = 0; type < HIST_COUNT; ++type) | |
7036 { | |
7037 if (history[type] == NULL) | |
4283 | 7038 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7039 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7040 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7041 merge_history(type); |
7 | 7042 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7043 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7044 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7045 VIM_CLEAR(viminfo_history[type]); |
4327 | 7046 viminfo_hisidx[type] = 0; |
7 | 7047 } |
7048 } | |
7049 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7050 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7051 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7052 * 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
|
7053 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7054 * 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
|
7055 */ |
7 | 7056 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7057 write_viminfo_history(FILE *fp, int merge) |
7 | 7058 { |
7059 int i; | |
7060 int type; | |
7061 int num_saved; | |
4283 | 7062 int round; |
7 | 7063 |
7064 init_history(); | |
7065 if (hislen == 0) | |
7066 return; | |
7067 for (type = 0; type < HIST_COUNT; ++type) | |
7068 { | |
7069 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7070 if (num_saved == 0) | |
7071 continue; | |
7072 if (num_saved < 0) /* Use default */ | |
7073 num_saved = hislen; | |
7074 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7075 type == HIST_CMD ? _("Command Line") : | |
7076 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7077 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7078 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7079 _("Debug Line")); |
7 | 7080 if (num_saved > hislen) |
7081 num_saved = hislen; | |
4283 | 7082 |
7083 /* | |
7084 * Merge typed and viminfo history: | |
7085 * round 1: history of typed commands. | |
7086 * round 2: history from recently read viminfo. | |
7087 */ | |
7088 for (round = 1; round <= 2; ++round) | |
7089 { | |
4307 | 7090 if (round == 1) |
7091 /* start at newest entry, somewhere in the list */ | |
7092 i = hisidx[type]; | |
7093 else if (viminfo_hisidx[type] > 0) | |
7094 /* start at newest entry, first in the list */ | |
7095 i = 0; | |
7096 else | |
7097 /* empty list */ | |
7098 i = -1; | |
4283 | 7099 if (i >= 0) |
7100 while (num_saved > 0 | |
7101 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7102 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7103 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7104 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7105 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7106 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7107 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7108 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7109 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7110 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7111 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7112 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7113 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7114 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7115 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7116 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7117 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7118 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7119 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7120 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7121 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7122 || !history[type][i].viminfo)) |
7 | 7123 { |
4283 | 7124 --num_saved; |
7125 fputc(hist_type2char(type, TRUE), fp); | |
7126 /* For the search history: put the separator in the | |
7127 * second column; use a space if there isn't one. */ | |
7128 if (type == HIST_SEARCH) | |
7129 { | |
7130 c = p[STRLEN(p) + 1]; | |
7131 putc(c == NUL ? ' ' : c, fp); | |
7132 } | |
7133 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7134 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7135 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7136 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7137 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7138 /* 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
|
7139 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7140 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7141 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7142 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7143 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7144 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
|
7145 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7146 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7147 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7148 } |
7 | 7149 } |
4283 | 7150 if (round == 1) |
7151 { | |
7152 /* Decrement index, loop around and stop when back at | |
7153 * the start. */ | |
7154 if (--i < 0) | |
7155 i = hislen - 1; | |
7156 if (i == hisidx[type]) | |
7157 break; | |
7158 } | |
7159 else | |
7160 { | |
7161 /* Increment index. Stop at the end in the while. */ | |
7162 ++i; | |
7163 } | |
7 | 7164 } |
4283 | 7165 } |
4285 | 7166 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7167 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7168 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
|
7169 VIM_CLEAR(viminfo_history[type]); |
4311 | 7170 viminfo_hisidx[type] = 0; |
7 | 7171 } |
7172 } | |
7173 #endif /* FEAT_VIMINFO */ | |
7174 | |
7175 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7176 /* | |
7177 * Write a character at the current cursor+offset position. | |
7178 * It is directly written into the command buffer block. | |
7179 */ | |
7180 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7181 cmd_pchar(int c, int offset) |
7 | 7182 { |
7183 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7184 { | |
7185 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7186 return; | |
7187 } | |
7188 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7189 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7190 } | |
7191 | |
7192 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7193 cmd_gchar(int offset) |
7 | 7194 { |
7195 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7196 { | |
7197 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7198 return NUL; | |
7199 } | |
7200 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7201 } | |
7202 #endif | |
7203 | |
7204 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7205 /* | |
7206 * Open a window on the current command line and history. Allow editing in | |
7207 * the window. Returns when the window is closed. | |
7208 * Returns: | |
7209 * CR if the command is to be executed | |
7210 * Ctrl_C if it is to be abandoned | |
7211 * K_IGNORE if editing continues | |
7212 */ | |
7213 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
|
7214 open_cmdwin(void) |
7 | 7215 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7216 bufref_T old_curbuf; |
7 | 7217 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7218 bufref_T bufref; |
7 | 7219 win_T *wp; |
7220 int i; | |
7221 linenr_T lnum; | |
7222 int histtype; | |
7223 garray_T winsizes; | |
7224 int save_restart_edit = restart_edit; | |
7225 int save_State = State; | |
7226 int save_exmode = exmode_active; | |
510 | 7227 #ifdef FEAT_RIGHTLEFT |
7228 int save_cmdmsg_rl = cmdmsg_rl; | |
7229 #endif | |
6145 | 7230 #ifdef FEAT_FOLDING |
7231 int save_KeyTyped; | |
7232 #endif | |
7 | 7233 |
7234 /* Can't do this recursively. Can't do it when typing a password. */ | |
7235 if (cmdwin_type != 0 | |
7236 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7237 || cmdline_star > 0 | |
7238 # endif | |
7239 ) | |
7240 { | |
7241 beep_flush(); | |
7242 return K_IGNORE; | |
7243 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7244 set_bufref(&old_curbuf, curbuf); |
7 | 7245 |
7246 /* Save current window sizes. */ | |
7247 win_size_save(&winsizes); | |
7248 | |
7249 /* Don't execute autocommands while creating the window. */ | |
1410 | 7250 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7251 |
683 | 7252 /* don't use a new tab page */ |
7253 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
|
7254 cmdmod.noswapfile = 1; |
683 | 7255 |
7 | 7256 /* Create a window for the command-line buffer. */ |
7257 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7258 { | |
7259 beep_flush(); | |
1410 | 7260 unblock_autocmds(); |
7 | 7261 return K_IGNORE; |
7262 } | |
1831 | 7263 cmdwin_type = get_cmdline_type(); |
7 | 7264 |
7265 /* Create the command-line buffer empty. */ | |
1743 | 7266 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7267 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7268 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7269 curbuf->b_p_ma = TRUE; | |
1865 | 7270 #ifdef FEAT_FOLDING |
7271 curwin->w_p_fen = FALSE; | |
7272 #endif | |
7 | 7273 # ifdef FEAT_RIGHTLEFT |
510 | 7274 curwin->w_p_rl = cmdmsg_rl; |
7275 cmdmsg_rl = FALSE; | |
7 | 7276 # endif |
2583 | 7277 RESET_BINDING(curwin); |
7 | 7278 |
7279 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7280 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7281 /* 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
|
7282 ++curbuf_lock; |
7 | 7283 |
510 | 7284 /* Showing the prompt may have set need_wait_return, reset it. */ |
7285 need_wait_return = FALSE; | |
7286 | |
1831 | 7287 histtype = hist_char2type(cmdwin_type); |
7 | 7288 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7289 { | |
7290 if (p_wc == TAB) | |
7291 { | |
7292 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7293 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7294 } | |
7295 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7296 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7297 --curbuf_lock; |
7 | 7298 |
10 | 7299 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7300 * sets 'textwidth' to 78). */ | |
7301 curbuf->b_p_tw = 0; | |
7302 | |
7 | 7303 /* Fill the buffer with the history. */ |
7304 init_history(); | |
7305 if (hislen > 0) | |
7306 { | |
7307 i = hisidx[histtype]; | |
7308 if (i >= 0) | |
7309 { | |
7310 lnum = 0; | |
7311 do | |
7312 { | |
7313 if (++i == hislen) | |
7314 i = 0; | |
7315 if (history[histtype][i].hisstr != NULL) | |
7316 ml_append(lnum++, history[histtype][i].hisstr, | |
7317 (colnr_T)0, FALSE); | |
7318 } | |
7319 while (i != hisidx[histtype]); | |
7320 } | |
7321 } | |
7322 | |
7323 /* Replace the empty last line with the current command-line and put the | |
7324 * cursor there. */ | |
7325 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7326 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7327 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7328 changed_line_abv_curs(); |
7329 invalidate_botline(); | |
743 | 7330 redraw_later(SOME_VALID); |
7 | 7331 |
7332 /* No Ex mode here! */ | |
7333 exmode_active = 0; | |
7334 | |
7335 State = NORMAL; | |
7336 # ifdef FEAT_MOUSE | |
7337 setmouse(); | |
7338 # endif | |
7339 | |
7340 /* 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
|
7341 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7342 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7343 stuffcharReadbuff(K_NOP); | |
7 | 7344 |
7345 i = RedrawingDisabled; | |
7346 RedrawingDisabled = 0; | |
7347 | |
7348 /* | |
7349 * Call the main loop until <CR> or CTRL-C is typed. | |
7350 */ | |
7351 cmdwin_result = 0; | |
168 | 7352 main_loop(TRUE, FALSE); |
7 | 7353 |
7354 RedrawingDisabled = i; | |
7355 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7356 # ifdef FEAT_FOLDING |
6145 | 7357 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7358 # endif |
6145 | 7359 |
7 | 7360 /* 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
|
7361 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7362 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7363 # ifdef FEAT_FOLDING |
6145 | 7364 /* Restore KeyTyped in case it is modified by autocommands */ |
7365 KeyTyped = save_KeyTyped; | |
7 | 7366 # endif |
7367 | |
7368 cmdwin_type = 0; | |
7369 exmode_active = save_exmode; | |
7370 | |
1612 | 7371 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7372 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7373 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7374 { |
7375 cmdwin_result = Ctrl_C; | |
7376 EMSG(_("E199: Active window or buffer deleted")); | |
7377 } | |
7378 else | |
7379 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7380 # if defined(FEAT_EVAL) |
7 | 7381 /* autocmds may abort script processing */ |
7382 if (aborting() && cmdwin_result != K_IGNORE) | |
7383 cmdwin_result = Ctrl_C; | |
7384 # endif | |
7385 /* Set the new command line from the cmdline buffer. */ | |
7386 vim_free(ccline.cmdbuff); | |
510 | 7387 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7388 { |
510 | 7389 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7390 | |
7391 if (histtype == HIST_CMD) | |
7392 { | |
7393 /* Execute the command directly. */ | |
7394 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7395 cmdwin_result = CAR; | |
7396 } | |
7397 else | |
7398 { | |
7399 /* First need to cancel what we were doing. */ | |
7400 ccline.cmdbuff = NULL; | |
7401 stuffcharReadbuff(':'); | |
7402 stuffReadbuff((char_u *)p); | |
7403 stuffcharReadbuff(CAR); | |
7404 } | |
7 | 7405 } |
7406 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7407 { | |
7408 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7409 cmdwin_result = CAR; | |
7410 } | |
2839 | 7411 else if (cmdwin_result == Ctrl_C) |
7412 { | |
7413 /* :q or :close, don't execute any command | |
7414 * and don't modify the cmd window. */ | |
7415 ccline.cmdbuff = NULL; | |
7416 } | |
7 | 7417 else |
7418 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7419 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
|
7420 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7421 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
|
7422 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
|
7423 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
|
7424 ccline.cmdpos = 0; |
7 | 7425 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
|
7426 } |
7 | 7427 else |
7428 { | |
7429 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7430 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7431 ccline.cmdpos = curwin->w_cursor.col; | |
7432 if (ccline.cmdpos > ccline.cmdlen) | |
7433 ccline.cmdpos = ccline.cmdlen; | |
7434 if (cmdwin_result == K_IGNORE) | |
7435 { | |
7436 set_cmdspos_cursor(); | |
7437 redrawcmd(); | |
7438 } | |
7439 } | |
7440 | |
7441 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7442 block_autocmds(); |
6876 | 7443 # ifdef FEAT_CONCEAL |
7444 /* Avoid command-line window first character being concealed. */ | |
7445 curwin->w_p_cole = 0; | |
7446 # endif | |
7 | 7447 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7448 set_bufref(&bufref, curbuf); |
7 | 7449 win_goto(old_curwin); |
7450 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7451 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7452 /* 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
|
7453 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7454 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7455 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7456 |
7457 /* Restore window sizes. */ | |
7458 win_size_restore(&winsizes); | |
7459 | |
1410 | 7460 unblock_autocmds(); |
7 | 7461 } |
7462 | |
7463 ga_clear(&winsizes); | |
7464 restart_edit = save_restart_edit; | |
510 | 7465 # ifdef FEAT_RIGHTLEFT |
7466 cmdmsg_rl = save_cmdmsg_rl; | |
7467 # endif | |
7 | 7468 |
7469 State = save_State; | |
7470 # ifdef FEAT_MOUSE | |
7471 setmouse(); | |
7472 # endif | |
7473 | |
7474 return cmdwin_result; | |
7475 } | |
7476 #endif /* FEAT_CMDWIN */ | |
7477 | |
7478 /* | |
7479 * Used for commands that either take a simple command string argument, or: | |
7480 * cmd << endmarker | |
7481 * {script} | |
7482 * endmarker | |
7483 * Returns a pointer to allocated memory with {script} or NULL. | |
7484 */ | |
7485 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7486 script_get(exarg_T *eap, char_u *cmd) |
7 | 7487 { |
7488 char_u *theline; | |
7489 char *end_pattern = NULL; | |
7490 char dot[] = "."; | |
7491 garray_T ga; | |
7492 | |
7493 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7494 return NULL; | |
7495 | |
7496 ga_init2(&ga, 1, 0x400); | |
7497 | |
7498 if (cmd[2] != NUL) | |
7499 end_pattern = (char *)skipwhite(cmd + 2); | |
7500 else | |
7501 end_pattern = dot; | |
7502 | |
7503 for (;;) | |
7504 { | |
7505 theline = eap->getline( | |
7506 #ifdef FEAT_EVAL | |
75 | 7507 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7508 #endif |
7509 NUL, eap->cookie, 0); | |
7510 | |
7511 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7512 { |
7513 vim_free(theline); | |
7 | 7514 break; |
1694 | 7515 } |
7 | 7516 |
7517 ga_concat(&ga, theline); | |
7518 ga_append(&ga, '\n'); | |
7519 vim_free(theline); | |
7520 } | |
21 | 7521 ga_append(&ga, NUL); |
7 | 7522 |
7523 return (char_u *)ga.ga_data; | |
7524 } |