Mercurial > vim
annotate src/ex_getln.c @ 14652:f3b183c3d3e2 v8.1.0339
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
commit https://github.com/vim/vim/commit/f13daa46da85a80dd05704cdde0660c2b2651a5a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 31 22:09:54 2018 +0200
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Problem: Wrong highlight when 'incsearch' set and cancelling :s.
Solution: Reset search line range. (Hirohito Higashi, Masamichi Abe)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 31 Aug 2018 22:15:05 +0200 |
parents | c6b41d47bac1 |
children | 7771a1ff8b99 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
1718 | 47 /* The current cmdline_info. It is initialized in getcmdline() and after that |
48 * used by other functions. When invoking getcmdline() recursively it needs | |
49 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
50 * TODO: make it local to getcmdline() and pass it around. */ | |
51 static struct cmdline_info ccline; | |
7 | 52 |
53 static int cmd_showtail; /* Only show path tail in lists ? */ | |
54 | |
55 #ifdef FEAT_EVAL | |
56 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
57 #endif | |
58 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
60 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
62 |
7 | 63 #ifdef FEAT_CMDHIST |
64 typedef struct hist_entry | |
65 { | |
66 int hisnum; /* identifying number */ | |
4258 | 67 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 68 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
69 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 70 } histentry_T; |
71 | |
72 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
73 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
74 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
75 /* identifying (unique) number of newest history entry */ | |
76 static int hislen = 0; /* actual length of history tables */ | |
77 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
80 static int in_history(int, char_u *, int, int, int); |
7 | 81 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
82 static int calc_hist_idx(int histype, int num); |
7 | 83 # endif |
84 #endif | |
85 | |
86 #ifdef FEAT_RIGHTLEFT | |
87 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
88 #endif | |
89 | |
90 #ifdef FEAT_FKMAP | |
91 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
92 #endif | |
93 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
117 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
119 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
123 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
129 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
156 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
157 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
159 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
274 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
278 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 *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
|
291 *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
|
292 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
293 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
|
294 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 // 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
|
297 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
|
298 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
|
299 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 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
|
301 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 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
|
312 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
|
313 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 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
|
315 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
|
316 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 // 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
|
319 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
|
320 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 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
|
322 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 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
|
325 || 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
|
326 || 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
|
327 || 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
|
328 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 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
|
335 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 // 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
|
337 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
|
338 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 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
|
340 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 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
|
343 || 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
|
344 || 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
|
345 || 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
|
346 || 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
|
347 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 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
|
350 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
351 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 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
|
353 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
|
354 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
355 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
|
356 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
|
357 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
358 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
359 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
360 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
365 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
|
366 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 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
|
368 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
|
369 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 // 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
|
371 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
|
372 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 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
|
374 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
376 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
377 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
|
378 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
379 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
380 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
381 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
382 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
383 // 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
|
384 *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
|
385 *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
|
386 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 // 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
|
388 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
|
389 curwin->w_cursor = is_state->search_start; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 parse_cmd_address(&ea, &dummy); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
391 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
|
392 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 // 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
|
394 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
|
395 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 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
|
397 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
|
398 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 { |
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 = ea.line1; |
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 = ea.line2; |
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 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
|
406 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
407 // :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
|
408 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
|
409 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
|
410 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
411 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
412 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
|
413 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
414 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
416 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 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
|
420 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
|
421 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 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
|
423 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 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
|
425 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 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
|
427 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 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
|
430 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 // 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
|
432 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
|
433 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 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
|
436 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 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
|
438 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
|
439 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
440 // 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
|
441 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
|
442 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
|
443 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
444 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
|
445 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
446 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 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
|
448 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
|
449 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
450 redraw_all_later(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
451 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
452 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
453 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 * 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
|
456 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 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
|
459 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
461 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
|
462 { |
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 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
|
464 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 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
|
466 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
470 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
471 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
|
472 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
473 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
|
474 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
475 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
|
476 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
477 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 // 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
|
480 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 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
|
483 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 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
|
486 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
487 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
|
488 // 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
|
489 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
490 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
491 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
492 // 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
|
493 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
|
494 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
|
495 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
498 // 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
|
499 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
|
500 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
|
501 && 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
|
502 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
503 // 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
|
504 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
|
505 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
507 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
|
508 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
|
509 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 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
|
513 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 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
|
515 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 ++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
|
517 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 // 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
|
519 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
|
520 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
526 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
527 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
|
528 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
534 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
|
535 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
537 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
|
538 || 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
|
539 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
540 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
541 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
542 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
|
543 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
544 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
545 // 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
|
546 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 (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
|
549 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 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
|
553 // 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
|
554 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
|
555 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
556 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 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
|
558 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
559 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
|
560 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 // 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
|
562 // 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
|
563 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
|
564 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
|
565 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 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
|
570 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 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
|
572 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
|
573 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 end_pos = curwin->w_cursor; // shutup gcc 4 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
581 // 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
|
582 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
583 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
584 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
585 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
586 ccline.cmdbuff[skiplen + patlen] = NUL; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
587 if (empty_pattern(ccline.cmdbuff)) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
588 set_no_hlsearch(TRUE); |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
589 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
590 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
591 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 // 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
|
594 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
|
595 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
|
596 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 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
|
599 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 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
|
601 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 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
|
605 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 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
|
609 } |
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 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 * 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
|
613 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 * 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
|
615 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 static int |
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( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
618 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
|
619 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 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
|
621 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 { |
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 skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
630 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
632 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
635 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
|
636 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 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
|
638 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
639 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
|
640 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 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
|
642 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
|
643 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 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
|
648 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 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
|
650 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
|
651 // 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
|
652 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
654 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
|
655 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
657 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
|
658 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 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
|
660 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 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
|
667 --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
|
668 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
|
669 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 // Move just 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
|
677 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 (void)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
|
680 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
681 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
|
682 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 // 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
|
684 // 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
|
685 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
|
686 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
687 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 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
|
689 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 // wrap around |
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 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
693 (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
|
694 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
695 (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
|
696 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
697 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 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
|
705 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
|
706 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
709 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
|
710 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
|
711 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
712 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
714 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
715 * 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
|
716 * 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
|
717 * 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
|
718 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
719 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
720 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
|
721 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
722 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
|
723 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
724 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 return FAIL; |
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 // 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
|
728 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
|
729 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 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
|
731 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
|
732 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
734 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
735 // If '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
|
736 // 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
|
737 // 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
|
738 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
|
739 *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
|
740 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
741 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
742 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
|
743 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
|
744 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
745 // 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
|
746 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
747 *c = '\\'; |
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 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
750 } |
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 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
753 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
754 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
755 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
756 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
757 /* |
7 | 758 * getcmdline() - accept a command line starting with firstc. |
759 * | |
760 * firstc == ':' get ":" command line. | |
761 * firstc == '/' or '?' get search pattern | |
762 * firstc == '=' get expression | |
763 * firstc == '@' get text for input() function | |
764 * firstc == '>' get text for debug mode | |
765 * firstc == NUL get text for :insert command | |
766 * firstc == -1 like NUL, and break on CTRL-C | |
767 * | |
768 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
769 * command line. | |
770 * | |
771 * Careful: getcmdline() can be called recursively! | |
772 * | |
773 * Return pointer to allocated string if there is a commandline, NULL | |
774 * otherwise. | |
775 */ | |
776 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
777 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
778 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
779 long count UNUSED, /* only used for incremental search */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
780 int indent) /* indent for inside conditionals */ |
7 | 781 { |
782 int c; | |
783 int i; | |
784 int j; | |
785 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
786 int do_abbr; /* when TRUE check for abbr. */ | |
787 #ifdef FEAT_CMDHIST | |
788 char_u *lookfor = NULL; /* string to match */ | |
789 int hiscnt; /* current history line in use */ | |
790 int histype; /* history type to be used */ | |
791 #endif | |
792 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
793 incsearch_state_T is_state; |
7 | 794 #endif |
795 int did_wild_list = FALSE; /* did wild_list() recently */ | |
796 int wim_index = 0; /* index in wim_flags[] */ | |
797 int res; | |
798 int save_msg_scroll = msg_scroll; | |
799 int save_State = State; /* remember State when called */ | |
800 int some_key_typed = FALSE; /* one of the keys was typed */ | |
801 #ifdef FEAT_MOUSE | |
802 /* mouse drag and release events are ignored, unless they are | |
803 * preceded with a mouse down event */ | |
804 int ignore_drag_release = TRUE; | |
805 #endif | |
806 #ifdef FEAT_EVAL | |
807 int break_ctrl_c = FALSE; | |
808 #endif | |
809 expand_T xpc; | |
810 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
811 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 812 /* Everything that may work recursively should save and restore the |
813 * current command line in save_ccline. That includes update_screen(), a | |
814 * custom status line may invoke ":normal". */ | |
815 struct cmdline_info save_ccline; | |
816 #endif | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
817 int cmdline_type; |
7 | 818 |
819 #ifdef FEAT_EVAL | |
820 if (firstc == -1) | |
821 { | |
822 firstc = NUL; | |
823 break_ctrl_c = TRUE; | |
824 } | |
825 #endif | |
826 #ifdef FEAT_RIGHTLEFT | |
827 /* start without Hebrew mapping for a command line */ | |
828 if (firstc == ':' || firstc == '=' || firstc == '>') | |
829 cmd_hkmap = 0; | |
830 #endif | |
831 | |
832 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
|
833 |
7 | 834 #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
|
835 init_incsearch_state(&is_state); |
7 | 836 #endif |
837 | |
838 /* | |
839 * set some variables for redrawcmd() | |
840 */ | |
841 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 842 ccline.cmdindent = (firstc > 0 ? indent : 0); |
843 | |
844 /* alloc initial ccline.cmdbuff */ | |
845 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 846 if (ccline.cmdbuff == NULL) |
847 return NULL; /* out of memory */ | |
848 ccline.cmdlen = ccline.cmdpos = 0; | |
849 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
|
850 sb_text_start_cmdline(); |
7 | 851 |
164 | 852 /* autoindent for :insert and :append */ |
853 if (firstc <= 0) | |
854 { | |
6929 | 855 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 856 ccline.cmdbuff[indent] = NUL; |
857 ccline.cmdpos = indent; | |
858 ccline.cmdspos = indent; | |
859 ccline.cmdlen = indent; | |
860 } | |
861 | |
7 | 862 ExpandInit(&xpc); |
1718 | 863 ccline.xpc = &xpc; |
7 | 864 |
865 #ifdef FEAT_RIGHTLEFT | |
866 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
867 && (firstc == '/' || firstc == '?')) | |
868 cmdmsg_rl = TRUE; | |
869 else | |
870 cmdmsg_rl = FALSE; | |
871 #endif | |
872 | |
873 redir_off = TRUE; /* don't redirect the typed command */ | |
874 if (!cmd_silent) | |
875 { | |
876 i = msg_scrolled; | |
877 msg_scrolled = 0; /* avoid wait_return message */ | |
878 gotocmdline(TRUE); | |
879 msg_scrolled += i; | |
880 redrawcmdprompt(); /* draw prompt or indent */ | |
881 set_cmdspos(); | |
882 } | |
883 xpc.xp_context = EXPAND_NOTHING; | |
884 xpc.xp_backslash = XP_BS_NONE; | |
632 | 885 #ifndef BACKSLASH_IN_FILENAME |
886 xpc.xp_shell = FALSE; | |
887 #endif | |
7 | 888 |
531 | 889 #if defined(FEAT_EVAL) |
890 if (ccline.input_fn) | |
891 { | |
892 xpc.xp_context = ccline.xp_context; | |
893 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 894 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 895 xpc.xp_arg = ccline.xp_arg; |
1322 | 896 # endif |
531 | 897 } |
898 #endif | |
899 | |
7 | 900 /* |
901 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
902 * doing ":@0" when register 0 doesn't contain a CR. | |
903 */ | |
904 msg_scroll = FALSE; | |
905 | |
906 State = CMDLINE; | |
907 | |
908 if (firstc == '/' || firstc == '?' || firstc == '@') | |
909 { | |
910 /* Use ":lmap" mappings for search pattern and input(). */ | |
911 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
912 b_im_ptr = &curbuf->b_p_iminsert; | |
913 else | |
914 b_im_ptr = &curbuf->b_p_imsearch; | |
915 if (*b_im_ptr == B_IMODE_LMAP) | |
916 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
917 #ifdef HAVE_INPUT_METHOD |
7 | 918 im_set_active(*b_im_ptr == B_IMODE_IM); |
919 #endif | |
920 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
921 #ifdef HAVE_INPUT_METHOD |
7 | 922 else if (p_imcmdline) |
923 im_set_active(TRUE); | |
924 #endif | |
925 | |
926 #ifdef FEAT_MOUSE | |
927 setmouse(); | |
928 #endif | |
929 #ifdef CURSOR_SHAPE | |
930 ui_cursor_shape(); /* may show different cursor shape */ | |
931 #endif | |
932 | |
571 | 933 /* When inside an autocommand for writing "exiting" may be set and |
934 * terminal mode set to cooked. Need to set raw mode here then. */ | |
935 settmode(TMODE_RAW); | |
936 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
937 /* 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
|
938 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
|
939 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
|
940 |
7 | 941 #ifdef FEAT_CMDHIST |
942 init_history(); | |
943 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
944 histype = hist_char2type(firstc); | |
945 #endif | |
946 | |
947 #ifdef FEAT_DIGRAPHS | |
1868 | 948 do_digraph(-1); /* init digraph typeahead */ |
7 | 949 #endif |
950 | |
5993 | 951 /* If something above caused an error, reset the flags, we do want to type |
952 * and execute commands. Display may be messed up a bit. */ | |
953 if (did_emsg) | |
954 redrawcmd(); | |
955 did_emsg = FALSE; | |
956 got_int = FALSE; | |
957 | |
7 | 958 /* |
959 * Collect the command string, handling editing keys. | |
960 */ | |
961 for (;;) | |
962 { | |
972 | 963 redir_off = TRUE; /* Don't redirect the typed command. |
964 Repeated, because a ":redir" inside | |
965 completion may switch it on. */ | |
7 | 966 #ifdef USE_ON_FLY_SCROLL |
967 dont_scroll = FALSE; /* allow scrolling here */ | |
968 #endif | |
969 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
970 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 |
7 | 975 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 976 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
977 /* 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
|
978 * anything, such as stop completion. */ |
1472 | 979 do |
980 { | |
981 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
|
982 } while (c == K_IGNORE || c == K_NOP); |
1472 | 983 |
7 | 984 if (KeyTyped) |
985 { | |
986 some_key_typed = TRUE; | |
987 #ifdef FEAT_RIGHTLEFT | |
988 if (cmd_hkmap) | |
989 c = hkmap(c); | |
990 # ifdef FEAT_FKMAP | |
991 if (cmd_fkmap) | |
992 c = cmdl_fkmap(c); | |
993 # endif | |
994 if (cmdmsg_rl && !KeyStuffed) | |
995 { | |
996 /* Invert horizontal movements and operations. Only when | |
997 * typed by the user directly, not when the result of a | |
998 * mapping. */ | |
999 switch (c) | |
1000 { | |
1001 case K_RIGHT: c = K_LEFT; break; | |
1002 case K_S_RIGHT: c = K_S_LEFT; break; | |
1003 case K_C_RIGHT: c = K_C_LEFT; break; | |
1004 case K_LEFT: c = K_RIGHT; break; | |
1005 case K_S_LEFT: c = K_S_RIGHT; break; | |
1006 case K_C_LEFT: c = K_C_RIGHT; break; | |
1007 } | |
1008 } | |
1009 #endif | |
1010 } | |
1011 | |
1012 /* | |
1013 * Ignore got_int when CTRL-C was typed here. | |
1014 * Don't ignore it in :global, we really need to break then, e.g., for | |
1015 * ":g/pat/normal /pat" (without the <CR>). | |
1016 * Don't ignore it for the input() function. | |
1017 */ | |
1018 if ((c == Ctrl_C | |
1019 #ifdef UNIX | |
1020 || c == intr_char | |
1021 #endif | |
1022 ) | |
1023 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1024 && firstc != '@' | |
1025 #endif | |
1026 #ifdef FEAT_EVAL | |
1027 && !break_ctrl_c | |
1028 #endif | |
1029 && !global_busy) | |
1030 got_int = FALSE; | |
1031 | |
1032 #ifdef FEAT_CMDHIST | |
1033 /* free old command line when finished moving around in the history | |
1034 * list */ | |
1035 if (lookfor != NULL | |
180 | 1036 && c != K_S_DOWN && c != K_S_UP |
230 | 1037 && c != K_DOWN && c != K_UP |
7 | 1038 && c != K_PAGEDOWN && c != K_PAGEUP |
1039 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1040 && c != K_LEFT && c != K_RIGHT |
7 | 1041 && (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
|
1042 VIM_CLEAR(lookfor); |
7 | 1043 #endif |
1044 | |
1045 /* | |
1718 | 1046 * When there are matching completions to select <S-Tab> works like |
1047 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1048 */ |
1718 | 1049 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1050 c = Ctrl_P; |
1051 | |
1052 #ifdef FEAT_WILDMENU | |
1053 /* Special translations for 'wildmenu' */ | |
1054 if (did_wild_list && p_wmnu) | |
1055 { | |
230 | 1056 if (c == K_LEFT) |
7 | 1057 c = Ctrl_P; |
230 | 1058 else if (c == K_RIGHT) |
7 | 1059 c = Ctrl_N; |
1060 } | |
1061 /* Hitting CR after "emenu Name.": complete submenu */ | |
1062 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1063 && ccline.cmdpos > 1 | |
1064 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1065 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1066 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1067 c = K_DOWN; | |
1068 #endif | |
1069 | |
1070 /* free expanded names when finished walking through matches */ | |
1071 if (xpc.xp_numfiles != -1 | |
1072 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1073 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1074 && c != Ctrl_L) | |
1075 { | |
1076 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1077 did_wild_list = FALSE; | |
1078 #ifdef FEAT_WILDMENU | |
230 | 1079 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1080 #endif |
1081 xpc.xp_context = EXPAND_NOTHING; | |
1082 wim_index = 0; | |
1083 #ifdef FEAT_WILDMENU | |
1084 if (p_wmnu && wild_menu_showing != 0) | |
1085 { | |
1086 int skt = KeyTyped; | |
532 | 1087 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1088 |
1089 if (ccline.input_fn) | |
1090 RedrawingDisabled = 0; | |
7 | 1091 |
1092 if (wild_menu_showing == WM_SCROLLED) | |
1093 { | |
1094 /* Entered command line, move it up */ | |
1095 cmdline_row--; | |
1096 redrawcmd(); | |
1097 } | |
1098 else if (save_p_ls != -1) | |
1099 { | |
1100 /* restore 'laststatus' and 'winminheight' */ | |
1101 p_ls = save_p_ls; | |
1102 p_wmh = save_p_wmh; | |
1103 last_status(FALSE); | |
195 | 1104 save_cmdline(&save_ccline); |
7 | 1105 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1106 restore_cmdline(&save_ccline); |
7 | 1107 redrawcmd(); |
1108 save_p_ls = -1; | |
1109 } | |
1110 else | |
1111 { | |
1112 win_redraw_last_status(topframe); | |
1113 redraw_statuslines(); | |
1114 } | |
532 | 1115 KeyTyped = skt; |
1116 wild_menu_showing = 0; | |
531 | 1117 if (ccline.input_fn) |
1118 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1119 } |
1120 #endif | |
1121 } | |
1122 | |
1123 #ifdef FEAT_WILDMENU | |
1124 /* Special translations for 'wildmenu' */ | |
1125 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1126 { | |
1127 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1128 if (c == K_DOWN && ccline.cmdpos > 0 |
1129 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1130 c = p_wc; |
230 | 1131 else if (c == K_UP) |
7 | 1132 { |
1133 /* Hitting <Up>: Remove one submenu name in front of the | |
1134 * cursor */ | |
1135 int found = FALSE; | |
1136 | |
1137 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1138 i = 0; | |
1139 while (--j > 0) | |
1140 { | |
1141 /* check for start of menu name */ | |
1142 if (ccline.cmdbuff[j] == ' ' | |
1143 && ccline.cmdbuff[j - 1] != '\\') | |
1144 { | |
1145 i = j + 1; | |
1146 break; | |
1147 } | |
1148 /* check for start of submenu name */ | |
1149 if (ccline.cmdbuff[j] == '.' | |
1150 && ccline.cmdbuff[j - 1] != '\\') | |
1151 { | |
1152 if (found) | |
1153 { | |
1154 i = j + 1; | |
1155 break; | |
1156 } | |
1157 else | |
1158 found = TRUE; | |
1159 } | |
1160 } | |
1161 if (i > 0) | |
1162 cmdline_del(i); | |
1163 c = p_wc; | |
1164 xpc.xp_context = EXPAND_NOTHING; | |
1165 } | |
1166 } | |
714 | 1167 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1168 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1169 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1170 { |
1171 char_u upseg[5]; | |
1172 | |
1173 upseg[0] = PATHSEP; | |
1174 upseg[1] = '.'; | |
1175 upseg[2] = '.'; | |
1176 upseg[3] = PATHSEP; | |
1177 upseg[4] = NUL; | |
1178 | |
1318 | 1179 if (c == K_DOWN |
1180 && ccline.cmdpos > 0 | |
1181 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1182 && (ccline.cmdpos < 3 | |
1183 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1184 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1185 { | |
1186 /* go down a directory */ | |
1187 c = p_wc; | |
1188 } | |
230 | 1189 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1190 { |
1191 /* If in a direct ancestor, strip off one ../ to go down */ | |
1192 int found = FALSE; | |
1193 | |
1194 j = ccline.cmdpos; | |
1195 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1196 while (--j > i) | |
1197 { | |
39 | 1198 #ifdef FEAT_MBYTE |
1199 if (has_mbyte) | |
1200 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1201 #endif | |
7 | 1202 if (vim_ispathsep(ccline.cmdbuff[j])) |
1203 { | |
1204 found = TRUE; | |
1205 break; | |
1206 } | |
1207 } | |
1208 if (found | |
1209 && ccline.cmdbuff[j - 1] == '.' | |
1210 && ccline.cmdbuff[j - 2] == '.' | |
1211 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1212 { | |
1213 cmdline_del(j - 2); | |
1214 c = p_wc; | |
1215 } | |
1216 } | |
230 | 1217 else if (c == K_UP) |
7 | 1218 { |
1219 /* go up a directory */ | |
1220 int found = FALSE; | |
1221 | |
1222 j = ccline.cmdpos - 1; | |
1223 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1224 while (--j > i) | |
1225 { | |
1226 #ifdef FEAT_MBYTE | |
1227 if (has_mbyte) | |
1228 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1229 #endif | |
1230 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1231 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1232 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1233 ccline.cmdbuff[j + 1]) == NULL |
7 | 1234 #endif |
1235 ) | |
1236 { | |
1237 if (found) | |
1238 { | |
1239 i = j + 1; | |
1240 break; | |
1241 } | |
1242 else | |
1243 found = TRUE; | |
1244 } | |
1245 } | |
1246 | |
1247 if (!found) | |
1248 j = i; | |
1249 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1250 j += 4; | |
1251 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1252 && j == i) | |
1253 j += 3; | |
1254 else | |
1255 j = 0; | |
1256 if (j > 0) | |
1257 { | |
1258 /* TODO this is only for DOS/UNIX systems - need to put in | |
1259 * machine-specific stuff here and in upseg init */ | |
1260 cmdline_del(j); | |
1261 put_on_cmdline(upseg + 1, 3, FALSE); | |
1262 } | |
1263 else if (ccline.cmdpos > i) | |
1264 cmdline_del(i); | |
3204 | 1265 |
1266 /* Now complete in the new directory. Set KeyTyped in case the | |
1267 * Up key came from a mapping. */ | |
7 | 1268 c = p_wc; |
3204 | 1269 KeyTyped = TRUE; |
7 | 1270 } |
1271 } | |
1272 | |
1273 #endif /* FEAT_WILDMENU */ | |
1274 | |
1275 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1276 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1277 if (c == Ctrl_BSL) | |
1278 { | |
1279 ++no_mapping; | |
1280 ++allow_keys; | |
1389 | 1281 c = plain_vgetc(); |
7 | 1282 --no_mapping; |
1283 --allow_keys; | |
3859 | 1284 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1285 * is in a mapping. */ | |
1286 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1287 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1288 { |
1289 vungetc(c); | |
1290 c = Ctrl_BSL; | |
1291 } | |
1292 #ifdef FEAT_EVAL | |
1293 else if (c == 'e') | |
1294 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1295 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1296 int len; |
7 | 1297 |
1298 /* | |
1299 * Replace the command line with the result of an expression. | |
625 | 1300 * Need to save and restore the current command line, to be |
1301 * able to enter a new one... | |
7 | 1302 */ |
1303 if (ccline.cmdpos == ccline.cmdlen) | |
1304 new_cmdpos = 99999; /* keep it at the end */ | |
1305 else | |
1306 new_cmdpos = ccline.cmdpos; | |
95 | 1307 |
1308 save_cmdline(&save_ccline); | |
7 | 1309 c = get_expr_register(); |
95 | 1310 restore_cmdline(&save_ccline); |
7 | 1311 if (c == '=') |
1312 { | |
634 | 1313 /* Need to save and restore ccline. And set "textlock" |
632 | 1314 * to avoid nasty things like going to another buffer when |
1315 * evaluating an expression. */ | |
95 | 1316 save_cmdline(&save_ccline); |
634 | 1317 ++textlock; |
7 | 1318 p = get_expr_line(); |
634 | 1319 --textlock; |
95 | 1320 restore_cmdline(&save_ccline); |
2617 | 1321 |
1322 if (p != NULL) | |
7 | 1323 { |
2617 | 1324 len = (int)STRLEN(p); |
1325 if (realloc_cmdbuff(len + 1) == OK) | |
1326 { | |
1327 ccline.cmdlen = len; | |
1328 STRCPY(ccline.cmdbuff, p); | |
1329 vim_free(p); | |
1330 | |
1331 /* Restore the cursor or use the position set with | |
1332 * set_cmdline_pos(). */ | |
1333 if (new_cmdpos > ccline.cmdlen) | |
1334 ccline.cmdpos = ccline.cmdlen; | |
1335 else | |
1336 ccline.cmdpos = new_cmdpos; | |
1337 | |
1338 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1339 redrawcmd(); | |
1340 goto cmdline_changed; | |
1341 } | |
7 | 1342 } |
1343 } | |
1344 beep_flush(); | |
2636 | 1345 got_int = FALSE; /* don't abandon the command line */ |
1346 did_emsg = FALSE; | |
1347 emsg_on_display = FALSE; | |
1348 redrawcmd(); | |
1349 goto cmdline_not_changed; | |
7 | 1350 } |
1351 #endif | |
1352 else | |
1353 { | |
1354 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1355 restart_edit = 'a'; | |
1356 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1357 in history */ | |
1358 goto returncmd; /* back to Normal mode */ | |
1359 } | |
1360 } | |
1361 | |
1362 #ifdef FEAT_CMDWIN | |
1363 if (c == cedit_key || c == K_CMDWIN) | |
1364 { | |
6211 | 1365 if (ex_normal_busy == 0 && got_int == FALSE) |
1366 { | |
1367 /* | |
1368 * Open a window to edit the command line (and history). | |
1369 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1370 c = open_cmdwin(); |
6211 | 1371 some_key_typed = TRUE; |
1372 } | |
7 | 1373 } |
1374 # ifdef FEAT_DIGRAPHS | |
1375 else | |
1376 # endif | |
1377 #endif | |
1378 #ifdef FEAT_DIGRAPHS | |
1379 c = do_digraph(c); | |
1380 #endif | |
1381 | |
1382 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1383 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1384 { | |
168 | 1385 /* In Ex mode a backslash escapes a newline. */ |
1386 if (exmode_active | |
1387 && c != ESC | |
1318 | 1388 && ccline.cmdpos == ccline.cmdlen |
168 | 1389 && ccline.cmdpos > 0 |
1390 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1391 { | |
1392 if (c == K_KENTER) | |
1393 c = '\n'; | |
1394 } | |
1395 else | |
7 | 1396 { |
168 | 1397 gotesc = FALSE; /* Might have typed ESC previously, don't |
1398 truncate the cmdline now. */ | |
1399 if (ccheck_abbr(c + ABBR_OFF)) | |
1400 goto cmdline_changed; | |
1401 if (!cmd_silent) | |
1402 { | |
1403 windgoto(msg_row, 0); | |
1404 out_flush(); | |
1405 } | |
1406 break; | |
7 | 1407 } |
1408 } | |
1409 | |
1410 /* | |
1411 * Completion for 'wildchar' or 'wildcharm' key. | |
1412 * - hitting <ESC> twice means: abandon command line. | |
1413 * - wildcard expansion is only done when the 'wildchar' key is really | |
1414 * typed, not when it comes from a macro | |
1415 */ | |
1416 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1417 { | |
1418 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1419 { | |
1420 /* if 'wildmode' contains "list" may still need to list */ | |
1421 if (xpc.xp_numfiles > 1 | |
1422 && !did_wild_list | |
1423 && (wim_flags[wim_index] & WIM_LIST)) | |
1424 { | |
1425 (void)showmatches(&xpc, FALSE); | |
1426 redrawcmd(); | |
1427 did_wild_list = TRUE; | |
1428 } | |
1429 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1430 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1431 firstc != '@'); | |
7 | 1432 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1433 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1434 firstc != '@'); | |
7 | 1435 else |
1436 res = OK; /* don't insert 'wildchar' now */ | |
1437 } | |
1438 else /* typed p_wc first time */ | |
1439 { | |
1440 wim_index = 0; | |
1441 j = ccline.cmdpos; | |
1442 /* if 'wildmode' first contains "longest", get longest | |
1443 * common part */ | |
1444 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1445 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1446 firstc != '@'); | |
7 | 1447 else |
3961 | 1448 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1449 firstc != '@'); | |
7 | 1450 |
1451 /* if interrupted while completing, behave like it failed */ | |
1452 if (got_int) | |
1453 { | |
1454 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1455 got_int = FALSE; /* don't abandon the command line */ | |
1456 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1457 #ifdef FEAT_WILDMENU | |
1458 xpc.xp_context = EXPAND_NOTHING; | |
1459 #endif | |
1460 goto cmdline_changed; | |
1461 } | |
1462 | |
1463 /* when more than one match, and 'wildmode' first contains | |
1464 * "list", or no change and 'wildmode' contains "longest,list", | |
1465 * list all matches */ | |
1466 if (res == OK && xpc.xp_numfiles > 1) | |
1467 { | |
1468 /* a "longest" that didn't do anything is skipped (but not | |
1469 * "list:longest") */ | |
1470 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1471 wim_index = 1; | |
1472 if ((wim_flags[wim_index] & WIM_LIST) | |
1473 #ifdef FEAT_WILDMENU | |
1474 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1475 #endif | |
1476 ) | |
1477 { | |
1478 if (!(wim_flags[0] & WIM_LONGEST)) | |
1479 { | |
1480 #ifdef FEAT_WILDMENU | |
1481 int p_wmnu_save = p_wmnu; | |
1482 p_wmnu = 0; | |
1483 #endif | |
3961 | 1484 /* remove match */ |
1485 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1486 #ifdef FEAT_WILDMENU |
1487 p_wmnu = p_wmnu_save; | |
1488 #endif | |
1489 } | |
1490 #ifdef FEAT_WILDMENU | |
1491 (void)showmatches(&xpc, p_wmnu | |
1492 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1493 #else | |
1494 (void)showmatches(&xpc, FALSE); | |
1495 #endif | |
1496 redrawcmd(); | |
1497 did_wild_list = TRUE; | |
1498 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1499 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1500 firstc != '@'); | |
7 | 1501 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1502 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1503 firstc != '@'); | |
7 | 1504 } |
1505 else | |
6949 | 1506 vim_beep(BO_WILD); |
7 | 1507 } |
1508 #ifdef FEAT_WILDMENU | |
1509 else if (xpc.xp_numfiles == -1) | |
1510 xpc.xp_context = EXPAND_NOTHING; | |
1511 #endif | |
1512 } | |
1513 if (wim_index < 3) | |
1514 ++wim_index; | |
1515 if (c == ESC) | |
1516 gotesc = TRUE; | |
1517 if (res == OK) | |
1518 goto cmdline_changed; | |
1519 } | |
1520 | |
1521 gotesc = FALSE; | |
1522 | |
1523 /* <S-Tab> goes to last match, in a clumsy way */ | |
1524 if (c == K_S_TAB && KeyTyped) | |
1525 { | |
3961 | 1526 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1527 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1528 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1529 goto cmdline_changed; |
1530 } | |
1531 | |
1532 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1533 c = NL; | |
1534 | |
1535 do_abbr = TRUE; /* default: check for abbreviation */ | |
1536 | |
1537 /* | |
1538 * Big switch for a typed command line character. | |
1539 */ | |
1540 switch (c) | |
1541 { | |
1542 case K_BS: | |
1543 case Ctrl_H: | |
1544 case K_DEL: | |
1545 case K_KDEL: | |
1546 case Ctrl_W: | |
1547 #ifdef FEAT_FKMAP | |
1548 if (cmd_fkmap && c == K_BS) | |
1549 c = K_DEL; | |
1550 #endif | |
1551 if (c == K_KDEL) | |
1552 c = K_DEL; | |
1553 | |
1554 /* | |
1555 * delete current character is the same as backspace on next | |
1556 * character, except at end of line | |
1557 */ | |
1558 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1559 ++ccline.cmdpos; | |
1560 #ifdef FEAT_MBYTE | |
1561 if (has_mbyte && c == K_DEL) | |
1562 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1563 ccline.cmdbuff + ccline.cmdpos); | |
1564 #endif | |
1565 if (ccline.cmdpos > 0) | |
1566 { | |
1567 char_u *p; | |
1568 | |
1569 j = ccline.cmdpos; | |
1570 p = ccline.cmdbuff + j; | |
1571 #ifdef FEAT_MBYTE | |
1572 if (has_mbyte) | |
1573 { | |
1574 p = mb_prevptr(ccline.cmdbuff, p); | |
1575 if (c == Ctrl_W) | |
1576 { | |
1577 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1578 p = mb_prevptr(ccline.cmdbuff, p); | |
1579 i = mb_get_class(p); | |
1580 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1581 p = mb_prevptr(ccline.cmdbuff, p); | |
1582 if (mb_get_class(p) != i) | |
474 | 1583 p += (*mb_ptr2len)(p); |
7 | 1584 } |
1585 } | |
1586 else | |
1587 #endif | |
1588 if (c == Ctrl_W) | |
1589 { | |
1590 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1591 --p; | |
1592 i = vim_iswordc(p[-1]); | |
1593 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1594 && vim_iswordc(p[-1]) == i) | |
1595 --p; | |
1596 } | |
1597 else | |
1598 --p; | |
1599 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1600 ccline.cmdlen -= j - ccline.cmdpos; | |
1601 i = ccline.cmdpos; | |
1602 while (i < ccline.cmdlen) | |
1603 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1604 | |
1605 /* Truncate at the end, required for multi-byte chars. */ | |
1606 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1607 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1608 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1609 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1610 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
|
1611 /* 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
|
1612 * 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
|
1613 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
|
1614 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1615 #endif |
7 | 1616 redrawcmd(); |
1617 } | |
1618 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1619 && ccline.cmdprompt == NULL && indent == 0) | |
1620 { | |
1621 /* In ex and debug mode it doesn't make sense to return. */ | |
1622 if (exmode_active | |
1623 #ifdef FEAT_EVAL | |
1624 || ccline.cmdfirstc == '>' | |
1625 #endif | |
1626 ) | |
1627 goto cmdline_not_changed; | |
1628 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1629 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1630 if (!cmd_silent) |
1631 { | |
1632 #ifdef FEAT_RIGHTLEFT | |
1633 if (cmdmsg_rl) | |
1634 msg_col = Columns; | |
1635 else | |
1636 #endif | |
1637 msg_col = 0; | |
1638 msg_putchar(' '); /* delete ':' */ | |
1639 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1640 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1641 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
|
1642 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
|
1643 #endif |
7 | 1644 redraw_cmdline = TRUE; |
1645 goto returncmd; /* back to cmd mode */ | |
1646 } | |
1647 goto cmdline_changed; | |
1648 | |
1649 case K_INS: | |
1650 case K_KINS: | |
1651 #ifdef FEAT_FKMAP | |
1652 /* if Farsi mode set, we are in reverse insert mode - | |
1653 Do not change the mode */ | |
1654 if (cmd_fkmap) | |
1655 beep_flush(); | |
1656 else | |
1657 #endif | |
1658 ccline.overstrike = !ccline.overstrike; | |
1659 #ifdef CURSOR_SHAPE | |
1660 ui_cursor_shape(); /* may show different cursor shape */ | |
1661 #endif | |
1662 goto cmdline_not_changed; | |
1663 | |
1664 case Ctrl_HAT: | |
782 | 1665 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1666 { |
1667 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1668 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1669 #ifdef HAVE_INPUT_METHOD |
7 | 1670 im_set_active(FALSE); /* Disable input method */ |
1671 #endif | |
1672 if (b_im_ptr != NULL) | |
1673 { | |
1674 if (State & LANGMAP) | |
1675 *b_im_ptr = B_IMODE_LMAP; | |
1676 else | |
1677 *b_im_ptr = B_IMODE_NONE; | |
1678 } | |
1679 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1680 #ifdef HAVE_INPUT_METHOD |
7 | 1681 else |
1682 { | |
1683 /* There are no ":lmap" mappings, toggle IM. When | |
1684 * 'imdisable' is set don't try getting the status, it's | |
1685 * always off. */ | |
1686 if ((p_imdisable && b_im_ptr != NULL) | |
1687 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1688 { | |
1689 im_set_active(FALSE); /* Disable input method */ | |
1690 if (b_im_ptr != NULL) | |
1691 *b_im_ptr = B_IMODE_NONE; | |
1692 } | |
1693 else | |
1694 { | |
1695 im_set_active(TRUE); /* Enable input method */ | |
1696 if (b_im_ptr != NULL) | |
1697 *b_im_ptr = B_IMODE_IM; | |
1698 } | |
1699 } | |
1700 #endif | |
1701 if (b_im_ptr != NULL) | |
1702 { | |
1703 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1704 set_iminsert_global(); | |
1705 else | |
1706 set_imsearch_global(); | |
1707 } | |
1708 #ifdef CURSOR_SHAPE | |
1709 ui_cursor_shape(); /* may show different cursor shape */ | |
1710 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1711 #if defined(FEAT_KEYMAP) |
7 | 1712 /* Show/unshow value of 'keymap' in status lines later. */ |
1713 status_redraw_curbuf(); | |
1714 #endif | |
1715 goto cmdline_not_changed; | |
1716 | |
1717 /* case '@': only in very old vi */ | |
1718 case Ctrl_U: | |
1719 /* delete all characters left of the cursor */ | |
1720 j = ccline.cmdpos; | |
1721 ccline.cmdlen -= j; | |
1722 i = ccline.cmdpos = 0; | |
1723 while (i < ccline.cmdlen) | |
1724 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1725 /* Truncate at the end, required for multi-byte chars. */ | |
1726 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1727 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1728 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
|
1729 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
|
1730 #endif |
7 | 1731 redrawcmd(); |
1732 goto cmdline_changed; | |
1733 | |
1734 #ifdef FEAT_CLIPBOARD | |
1735 case Ctrl_Y: | |
1736 /* Copy the modeless selection, if there is one. */ | |
1737 if (clip_star.state != SELECT_CLEARED) | |
1738 { | |
1739 if (clip_star.state == SELECT_DONE) | |
1740 clip_copy_modeless_selection(TRUE); | |
1741 goto cmdline_not_changed; | |
1742 } | |
1743 break; | |
1744 #endif | |
1745 | |
1746 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1747 case Ctrl_C: | |
571 | 1748 /* In exmode it doesn't make sense to return. Except when |
161 | 1749 * ":normal" runs out of characters. */ |
1750 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1751 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1752 goto cmdline_not_changed; |
1753 | |
1754 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1755 putting it in history */ | |
1756 goto returncmd; /* back to cmd mode */ | |
1757 | |
1758 case Ctrl_R: /* insert register */ | |
1759 #ifdef USE_ON_FLY_SCROLL | |
1760 dont_scroll = TRUE; /* disallow scrolling here */ | |
1761 #endif | |
1762 putcmdline('"', TRUE); | |
1763 ++no_mapping; | |
1389 | 1764 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1765 if (i == Ctrl_O) |
1766 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1767 if (i == Ctrl_R) | |
1389 | 1768 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
|
1769 extra_char = NUL; |
7 | 1770 --no_mapping; |
1771 #ifdef FEAT_EVAL | |
1772 /* | |
1773 * Insert the result of an expression. | |
1774 * Need to save the current command line, to be able to enter | |
1775 * a new one... | |
1776 */ | |
1777 new_cmdpos = -1; | |
1778 if (c == '=') | |
1779 { | |
1780 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1781 { | |
1782 beep_flush(); | |
1783 c = ESC; | |
1784 } | |
1785 else | |
1786 { | |
95 | 1787 save_cmdline(&save_ccline); |
7 | 1788 c = get_expr_register(); |
95 | 1789 restore_cmdline(&save_ccline); |
7 | 1790 } |
1791 } | |
1792 #endif | |
1793 if (c != ESC) /* use ESC to cancel inserting register */ | |
1794 { | |
1015 | 1795 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1796 |
613 | 1797 #ifdef FEAT_EVAL |
606 | 1798 /* When there was a serious error abort getting the |
1799 * command line. */ | |
1800 if (aborting()) | |
1801 { | |
1802 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1803 putting it in history */ | |
1804 goto returncmd; /* back to cmd mode */ | |
1805 } | |
613 | 1806 #endif |
7 | 1807 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1808 #ifdef FEAT_EVAL | |
1809 if (new_cmdpos >= 0) | |
1810 { | |
1811 /* set_cmdline_pos() was used */ | |
1812 if (new_cmdpos > ccline.cmdlen) | |
1813 ccline.cmdpos = ccline.cmdlen; | |
1814 else | |
1815 ccline.cmdpos = new_cmdpos; | |
1816 } | |
1817 #endif | |
1818 } | |
1819 redrawcmd(); | |
1820 goto cmdline_changed; | |
1821 | |
1822 case Ctrl_D: | |
1823 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1824 break; /* Use ^D as normal char instead */ | |
1825 | |
1826 redrawcmd(); | |
1827 continue; /* don't do incremental search now */ | |
1828 | |
1829 case K_RIGHT: | |
1830 case K_S_RIGHT: | |
1831 case K_C_RIGHT: | |
1832 do | |
1833 { | |
1834 if (ccline.cmdpos >= ccline.cmdlen) | |
1835 break; | |
1836 i = cmdline_charsize(ccline.cmdpos); | |
1837 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1838 break; | |
1839 ccline.cmdspos += i; | |
1840 #ifdef FEAT_MBYTE | |
1841 if (has_mbyte) | |
474 | 1842 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1843 + ccline.cmdpos); |
1844 else | |
1845 #endif | |
1846 ++ccline.cmdpos; | |
1847 } | |
180 | 1848 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1849 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1850 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1851 #ifdef FEAT_MBYTE | |
1852 if (has_mbyte) | |
1853 set_cmdspos_cursor(); | |
1854 #endif | |
1855 goto cmdline_not_changed; | |
1856 | |
1857 case K_LEFT: | |
1858 case K_S_LEFT: | |
1859 case K_C_LEFT: | |
1456 | 1860 if (ccline.cmdpos == 0) |
1861 goto cmdline_not_changed; | |
7 | 1862 do |
1863 { | |
1864 --ccline.cmdpos; | |
1865 #ifdef FEAT_MBYTE | |
1866 if (has_mbyte) /* move to first byte of char */ | |
1867 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1868 ccline.cmdbuff + ccline.cmdpos); | |
1869 #endif | |
1870 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1871 } | |
1456 | 1872 while (ccline.cmdpos > 0 |
1873 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1874 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1875 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1876 #ifdef FEAT_MBYTE | |
1877 if (has_mbyte) | |
1878 set_cmdspos_cursor(); | |
1879 #endif | |
1880 goto cmdline_not_changed; | |
1881 | |
1882 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
|
1883 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1884 goto cmdline_not_changed; |
7 | 1885 |
625 | 1886 #ifdef FEAT_GUI_W32 |
1887 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1888 * cancelled. */ | |
1889 case K_F4: | |
1890 if (mod_mask == MOD_MASK_ALT) | |
1891 { | |
1892 redrawcmd(); /* somehow the cmdline is cleared */ | |
1893 goto cmdline_not_changed; | |
1894 } | |
1895 break; | |
1896 #endif | |
1897 | |
7 | 1898 #ifdef FEAT_MOUSE |
1899 case K_MIDDLEDRAG: | |
1900 case K_MIDDLERELEASE: | |
1901 goto cmdline_not_changed; /* Ignore mouse */ | |
1902 | |
1903 case K_MIDDLEMOUSE: | |
1904 # ifdef FEAT_GUI | |
1905 /* When GUI is active, also paste when 'mouse' is empty */ | |
1906 if (!gui.in_use) | |
1907 # endif | |
1908 if (!mouse_has(MOUSE_COMMAND)) | |
1909 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1910 # ifdef FEAT_CLIPBOARD |
7 | 1911 if (clip_star.available) |
1015 | 1912 cmdline_paste('*', TRUE, TRUE); |
7 | 1913 else |
692 | 1914 # endif |
1015 | 1915 cmdline_paste(0, TRUE, TRUE); |
7 | 1916 redrawcmd(); |
1917 goto cmdline_changed; | |
1918 | |
692 | 1919 # ifdef FEAT_DND |
7 | 1920 case K_DROP: |
1015 | 1921 cmdline_paste('~', TRUE, FALSE); |
7 | 1922 redrawcmd(); |
1923 goto cmdline_changed; | |
692 | 1924 # endif |
7 | 1925 |
1926 case K_LEFTDRAG: | |
1927 case K_LEFTRELEASE: | |
1928 case K_RIGHTDRAG: | |
1929 case K_RIGHTRELEASE: | |
1930 /* Ignore drag and release events when the button-down wasn't | |
1931 * seen before. */ | |
1932 if (ignore_drag_release) | |
1933 goto cmdline_not_changed; | |
1934 /* FALLTHROUGH */ | |
1935 case K_LEFTMOUSE: | |
1936 case K_RIGHTMOUSE: | |
1937 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1938 ignore_drag_release = TRUE; | |
1939 else | |
1940 ignore_drag_release = FALSE; | |
1941 # ifdef FEAT_GUI | |
1942 /* When GUI is active, also move when 'mouse' is empty */ | |
1943 if (!gui.in_use) | |
1944 # endif | |
1945 if (!mouse_has(MOUSE_COMMAND)) | |
1946 goto cmdline_not_changed; /* Ignore mouse */ | |
1947 # ifdef FEAT_CLIPBOARD | |
1948 if (mouse_row < cmdline_row && clip_star.available) | |
1949 { | |
1950 int button, is_click, is_drag; | |
1951 | |
1952 /* | |
1953 * Handle modeless selection. | |
1954 */ | |
1955 button = get_mouse_button(KEY2TERMCAP1(c), | |
1956 &is_click, &is_drag); | |
1957 if (mouse_model_popup() && button == MOUSE_LEFT | |
1958 && (mod_mask & MOD_MASK_SHIFT)) | |
1959 { | |
1960 /* Translate shift-left to right button. */ | |
1961 button = MOUSE_RIGHT; | |
1962 mod_mask &= ~MOD_MASK_SHIFT; | |
1963 } | |
1964 clip_modeless(button, is_click, is_drag); | |
1965 goto cmdline_not_changed; | |
1966 } | |
1967 # endif | |
1968 | |
1969 set_cmdspos(); | |
1970 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1971 ++ccline.cmdpos) | |
1972 { | |
1973 i = cmdline_charsize(ccline.cmdpos); | |
1974 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1975 && mouse_col < ccline.cmdspos % Columns + i) | |
1976 break; | |
692 | 1977 # ifdef FEAT_MBYTE |
7 | 1978 if (has_mbyte) |
1979 { | |
1980 /* Count ">" for double-wide char that doesn't fit. */ | |
1981 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1982 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1983 + ccline.cmdpos) - 1; |
1984 } | |
692 | 1985 # endif |
7 | 1986 ccline.cmdspos += i; |
1987 } | |
1988 goto cmdline_not_changed; | |
1989 | |
1990 /* Mouse scroll wheel: ignored here */ | |
1991 case K_MOUSEDOWN: | |
1992 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1993 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1994 case K_MOUSERIGHT: |
7 | 1995 /* Alternate buttons ignored here */ |
1996 case K_X1MOUSE: | |
1997 case K_X1DRAG: | |
1998 case K_X1RELEASE: | |
1999 case K_X2MOUSE: | |
2000 case K_X2DRAG: | |
2001 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2002 case K_MOUSEMOVE: |
7 | 2003 goto cmdline_not_changed; |
2004 | |
2005 #endif /* FEAT_MOUSE */ | |
2006 | |
2007 #ifdef FEAT_GUI | |
2008 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2009 case K_LEFTRELEASE_NM: | |
2010 goto cmdline_not_changed; | |
2011 | |
2012 case K_VER_SCROLLBAR: | |
540 | 2013 if (msg_scrolled == 0) |
7 | 2014 { |
2015 gui_do_scroll(); | |
2016 redrawcmd(); | |
2017 } | |
2018 goto cmdline_not_changed; | |
2019 | |
2020 case K_HOR_SCROLLBAR: | |
540 | 2021 if (msg_scrolled == 0) |
7 | 2022 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2023 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2024 redrawcmd(); |
2025 } | |
2026 goto cmdline_not_changed; | |
2027 #endif | |
692 | 2028 #ifdef FEAT_GUI_TABLINE |
2029 case K_TABLINE: | |
2030 case K_TABMENU: | |
2031 /* Don't want to change any tabs here. Make sure the same tab | |
2032 * is still selected. */ | |
2033 if (gui_use_tabline()) | |
2034 gui_mch_set_curtab(tabpage_index(curtab)); | |
2035 goto cmdline_not_changed; | |
2036 #endif | |
2037 | |
7 | 2038 case K_SELECT: /* end of Select mode mapping - ignore */ |
2039 goto cmdline_not_changed; | |
2040 | |
2041 case Ctrl_B: /* begin of command line */ | |
2042 case K_HOME: | |
2043 case K_KHOME: | |
2044 case K_S_HOME: | |
2045 case K_C_HOME: | |
2046 ccline.cmdpos = 0; | |
2047 set_cmdspos(); | |
2048 goto cmdline_not_changed; | |
2049 | |
2050 case Ctrl_E: /* end of command line */ | |
2051 case K_END: | |
2052 case K_KEND: | |
2053 case K_S_END: | |
2054 case K_C_END: | |
2055 ccline.cmdpos = ccline.cmdlen; | |
2056 set_cmdspos_cursor(); | |
2057 goto cmdline_not_changed; | |
2058 | |
2059 case Ctrl_A: /* all matches */ | |
3961 | 2060 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2061 break; |
2062 goto cmdline_changed; | |
2063 | |
772 | 2064 case Ctrl_L: |
2065 #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
|
2066 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2067 goto cmdline_not_changed; |
2068 #endif | |
2069 | |
2070 /* completion: longest common part */ | |
3961 | 2071 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2072 break; |
2073 goto cmdline_changed; | |
2074 | |
2075 case Ctrl_N: /* next match */ | |
2076 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2077 if (xpc.xp_numfiles > 0) |
7 | 2078 { |
3961 | 2079 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2080 0, firstc != '@') == FAIL) | |
7 | 2081 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2082 goto cmdline_not_changed; |
7 | 2083 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2084 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2085 /* FALLTHROUGH */ |
7 | 2086 case K_UP: |
2087 case K_DOWN: | |
2088 case K_S_UP: | |
2089 case K_S_DOWN: | |
2090 case K_PAGEUP: | |
2091 case K_KPAGEUP: | |
2092 case K_PAGEDOWN: | |
2093 case K_KPAGEDOWN: | |
2094 if (hislen == 0 || firstc == NUL) /* no history */ | |
2095 goto cmdline_not_changed; | |
2096 | |
2097 i = hiscnt; | |
2098 | |
2099 /* save current command string so it can be restored later */ | |
2100 if (lookfor == NULL) | |
2101 { | |
2102 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2103 goto cmdline_not_changed; | |
2104 lookfor[ccline.cmdpos] = NUL; | |
2105 } | |
2106 | |
2107 j = (int)STRLEN(lookfor); | |
2108 for (;;) | |
2109 { | |
2110 /* one step backwards */ | |
230 | 2111 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2112 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2113 { |
2114 if (hiscnt == hislen) /* first time */ | |
2115 hiscnt = hisidx[histype]; | |
2116 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2117 hiscnt = hislen - 1; | |
2118 else if (hiscnt != hisidx[histype] + 1) | |
2119 --hiscnt; | |
2120 else /* at top of list */ | |
2121 { | |
2122 hiscnt = i; | |
2123 break; | |
2124 } | |
2125 } | |
2126 else /* one step forwards */ | |
2127 { | |
2128 /* on last entry, clear the line */ | |
2129 if (hiscnt == hisidx[histype]) | |
2130 { | |
2131 hiscnt = hislen; | |
2132 break; | |
2133 } | |
2134 | |
2135 /* not on a history line, nothing to do */ | |
2136 if (hiscnt == hislen) | |
2137 break; | |
2138 if (hiscnt == hislen - 1) /* wrap around */ | |
2139 hiscnt = 0; | |
2140 else | |
2141 ++hiscnt; | |
2142 } | |
2143 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2144 { | |
2145 hiscnt = i; | |
2146 break; | |
2147 } | |
230 | 2148 if ((c != K_UP && c != K_DOWN) |
180 | 2149 || hiscnt == i |
7 | 2150 || STRNCMP(history[histype][hiscnt].hisstr, |
2151 lookfor, (size_t)j) == 0) | |
2152 break; | |
2153 } | |
2154 | |
2155 if (hiscnt != i) /* jumped to other entry */ | |
2156 { | |
2157 char_u *p; | |
2158 int len; | |
2159 int old_firstc; | |
2160 | |
2161 vim_free(ccline.cmdbuff); | |
1718 | 2162 xpc.xp_context = EXPAND_NOTHING; |
7 | 2163 if (hiscnt == hislen) |
2164 p = lookfor; /* back to the old one */ | |
2165 else | |
2166 p = history[histype][hiscnt].hisstr; | |
2167 | |
2168 if (histype == HIST_SEARCH | |
2169 && p != lookfor | |
2170 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2171 { | |
2172 /* Correct for the separator character used when | |
2173 * adding the history entry vs the one used now. | |
2174 * First loop: count length. | |
2175 * Second loop: copy the characters. */ | |
2176 for (i = 0; i <= 1; ++i) | |
2177 { | |
2178 len = 0; | |
2179 for (j = 0; p[j] != NUL; ++j) | |
2180 { | |
2181 /* Replace old sep with new sep, unless it is | |
2182 * escaped. */ | |
2183 if (p[j] == old_firstc | |
2184 && (j == 0 || p[j - 1] != '\\')) | |
2185 { | |
2186 if (i > 0) | |
2187 ccline.cmdbuff[len] = firstc; | |
2188 } | |
2189 else | |
2190 { | |
2191 /* Escape new sep, unless it is already | |
2192 * escaped. */ | |
2193 if (p[j] == firstc | |
2194 && (j == 0 || p[j - 1] != '\\')) | |
2195 { | |
2196 if (i > 0) | |
2197 ccline.cmdbuff[len] = '\\'; | |
2198 ++len; | |
2199 } | |
2200 if (i > 0) | |
2201 ccline.cmdbuff[len] = p[j]; | |
2202 } | |
2203 ++len; | |
2204 } | |
2205 if (i == 0) | |
2206 { | |
2207 alloc_cmdbuff(len); | |
2208 if (ccline.cmdbuff == NULL) | |
2209 goto returncmd; | |
2210 } | |
2211 } | |
2212 ccline.cmdbuff[len] = NUL; | |
2213 } | |
2214 else | |
2215 { | |
2216 alloc_cmdbuff((int)STRLEN(p)); | |
2217 if (ccline.cmdbuff == NULL) | |
2218 goto returncmd; | |
2219 STRCPY(ccline.cmdbuff, p); | |
2220 } | |
2221 | |
2222 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2223 redrawcmd(); | |
2224 goto cmdline_changed; | |
2225 } | |
2226 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2227 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2228 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2229 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2230 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2231 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2232 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
|
2233 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
|
2234 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
|
2235 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2236 break; |
7 | 2237 #endif |
2238 | |
2239 case Ctrl_V: | |
2240 case Ctrl_Q: | |
2241 #ifdef FEAT_MOUSE | |
2242 ignore_drag_release = TRUE; | |
2243 #endif | |
2244 putcmdline('^', TRUE); | |
2245 c = get_literal(); /* get next (two) character(s) */ | |
2246 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
|
2247 extra_char = NUL; |
7 | 2248 #ifdef FEAT_MBYTE |
2249 /* may need to remove ^ when composing char was typed */ | |
2250 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2251 { | |
2252 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2253 msg_putchar(' '); | |
2254 cursorcmd(); | |
2255 } | |
2256 #endif | |
2257 break; | |
2258 | |
2259 #ifdef FEAT_DIGRAPHS | |
2260 case Ctrl_K: | |
2261 #ifdef FEAT_MOUSE | |
2262 ignore_drag_release = TRUE; | |
2263 #endif | |
2264 putcmdline('?', TRUE); | |
2265 #ifdef USE_ON_FLY_SCROLL | |
2266 dont_scroll = TRUE; /* disallow scrolling here */ | |
2267 #endif | |
2268 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
|
2269 extra_char = NUL; |
7 | 2270 if (c != NUL) |
2271 break; | |
2272 | |
2273 redrawcmd(); | |
2274 goto cmdline_not_changed; | |
2275 #endif /* FEAT_DIGRAPHS */ | |
2276 | |
2277 #ifdef FEAT_RIGHTLEFT | |
2278 case Ctrl__: /* CTRL-_: switch language mode */ | |
2279 if (!p_ari) | |
2280 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2281 # ifdef FEAT_FKMAP |
7 | 2282 if (p_altkeymap) |
2283 { | |
2284 cmd_fkmap = !cmd_fkmap; | |
2285 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2286 ccline.overstrike = FALSE; | |
2287 } | |
2288 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2289 # endif |
7 | 2290 cmd_hkmap = !cmd_hkmap; |
2291 goto cmdline_not_changed; | |
2292 #endif | |
2293 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2294 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
|
2295 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
|
2296 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
|
2297 |
7 | 2298 default: |
2299 #ifdef UNIX | |
2300 if (c == intr_char) | |
2301 { | |
2302 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2303 putting it in history */ | |
2304 goto returncmd; /* back to Normal mode */ | |
2305 } | |
2306 #endif | |
2307 /* | |
2308 * Normal character with no special meaning. Just set mod_mask | |
2309 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2310 * the string <S-Space>. This should only happen after ^V. | |
2311 */ | |
2312 if (!IS_SPECIAL(c)) | |
2313 mod_mask = 0x0; | |
2314 break; | |
2315 } | |
2316 /* | |
2317 * End of switch on command line character. | |
2318 * We come here if we have a normal character. | |
2319 */ | |
2320 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2321 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2322 #ifdef FEAT_MBYTE |
2323 /* Add ABBR_OFF for characters above 0x100, this is | |
2324 * what check_abbr() expects. */ | |
2325 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2326 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2327 c) || c == Ctrl_RSB)) |
7 | 2328 goto cmdline_changed; |
2329 | |
2330 /* | |
2331 * put the character in the command line | |
2332 */ | |
2333 if (IS_SPECIAL(c) || mod_mask != 0) | |
2334 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2335 else | |
2336 { | |
2337 #ifdef FEAT_MBYTE | |
2338 if (has_mbyte) | |
2339 { | |
2340 j = (*mb_char2bytes)(c, IObuff); | |
2341 IObuff[j] = NUL; /* exclude composing chars */ | |
2342 put_on_cmdline(IObuff, j, TRUE); | |
2343 } | |
2344 else | |
2345 #endif | |
2346 { | |
2347 IObuff[0] = c; | |
2348 put_on_cmdline(IObuff, 1, TRUE); | |
2349 } | |
2350 } | |
2351 goto cmdline_changed; | |
2352 | |
2353 /* | |
2354 * This part implements incremental searches for "/" and "?" | |
2355 * Jump to cmdline_not_changed when a character has been read but the command | |
2356 * line did not change. Then we only search and redraw if something changed in | |
2357 * the past. | |
2358 * Jump to cmdline_changed when the command line did change. | |
2359 * (Sorry for the goto's, I know it is ugly). | |
2360 */ | |
2361 cmdline_not_changed: | |
2362 #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
|
2363 if (!is_state.incsearch_postponed) |
7 | 2364 continue; |
2365 #endif | |
2366 | |
2367 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
|
2368 /* 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
|
2369 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
|
2370 |
7 | 2371 #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
|
2372 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2373 #endif |
2374 | |
2375 #ifdef FEAT_RIGHTLEFT | |
2376 if (cmdmsg_rl | |
2377 # ifdef FEAT_ARABIC | |
534 | 2378 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2379 # endif |
2380 ) | |
2381 /* Always redraw the whole command line to fix shaping and | |
3374 | 2382 * right-left typing. Not efficient, but it works. |
2383 * Do it only when there are no characters left to read | |
2384 * to avoid useless intermediate redraws. */ | |
2385 if (vpeekc() == NUL) | |
2386 redrawcmd(); | |
7 | 2387 #endif |
2388 } | |
2389 | |
2390 returncmd: | |
2391 | |
2392 #ifdef FEAT_RIGHTLEFT | |
2393 cmdmsg_rl = FALSE; | |
2394 #endif | |
2395 | |
2396 #ifdef FEAT_FKMAP | |
2397 cmd_fkmap = 0; | |
2398 #endif | |
2399 | |
2400 ExpandCleanup(&xpc); | |
1718 | 2401 ccline.xpc = NULL; |
7 | 2402 |
2403 #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
|
2404 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2405 #endif |
2406 | |
2407 if (ccline.cmdbuff != NULL) | |
2408 { | |
2409 /* | |
2410 * Put line in history buffer (":" and "=" only when it was typed). | |
2411 */ | |
2412 #ifdef FEAT_CMDHIST | |
2413 if (ccline.cmdlen && firstc != NUL | |
2414 && (some_key_typed || histype == HIST_SEARCH)) | |
2415 { | |
2416 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2417 histype == HIST_SEARCH ? firstc : NUL); | |
2418 if (firstc == ':') | |
2419 { | |
2420 vim_free(new_last_cmdline); | |
2421 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2422 } | |
2423 } | |
2424 #endif | |
2425 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2426 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
|
2427 abandon_cmdline(); |
7 | 2428 } |
2429 | |
2430 /* | |
2431 * If the screen was shifted up, redraw the whole screen (later). | |
2432 * If the line is too long, clear it, so ruler and shown command do | |
2433 * not get printed in the middle of it. | |
2434 */ | |
2435 msg_check(); | |
2436 msg_scroll = save_msg_scroll; | |
2437 redir_off = FALSE; | |
2438 | |
2439 /* When the command line was typed, no need for a wait-return prompt. */ | |
2440 if (some_key_typed) | |
2441 need_wait_return = FALSE; | |
2442 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2443 /* 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
|
2444 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
|
2445 |
7 | 2446 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2447 #ifdef HAVE_INPUT_METHOD |
7 | 2448 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2449 im_save_status(b_im_ptr); | |
2450 im_set_active(FALSE); | |
2451 #endif | |
2452 #ifdef FEAT_MOUSE | |
2453 setmouse(); | |
2454 #endif | |
2455 #ifdef CURSOR_SHAPE | |
2456 ui_cursor_shape(); /* may show different cursor shape */ | |
2457 #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
|
2458 sb_text_end_cmdline(); |
7 | 2459 |
95 | 2460 { |
2461 char_u *p = ccline.cmdbuff; | |
2462 | |
2463 /* Make ccline empty, getcmdline() may try to use it. */ | |
2464 ccline.cmdbuff = NULL; | |
2465 return p; | |
2466 } | |
7 | 2467 } |
2468 | |
2469 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2470 /* | |
2471 * Get a command line with a prompt. | |
2472 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2473 * f_input() when evaluating an expression from CTRL-R =). | |
2474 * Returns the command line in allocated memory, or NULL. | |
2475 */ | |
2476 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2477 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2478 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2479 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2480 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2481 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2482 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2483 { |
2484 char_u *s; | |
2485 struct cmdline_info save_ccline; | |
2486 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
|
2487 int msg_silent_save = msg_silent; |
7 | 2488 |
95 | 2489 save_cmdline(&save_ccline); |
7 | 2490 ccline.cmdprompt = prompt; |
2491 ccline.cmdattr = attr; | |
531 | 2492 # ifdef FEAT_EVAL |
2493 ccline.xp_context = xp_context; | |
2494 ccline.xp_arg = xp_arg; | |
2495 ccline.input_fn = (firstc == '@'); | |
2496 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2497 msg_silent = 0; |
7 | 2498 s = getcmdline(firstc, 1L, 0); |
95 | 2499 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2500 msg_silent = msg_silent_save; |
3020 | 2501 /* Restore msg_col, the prompt from input() may have changed it. |
2502 * But only if called recursively and the commandline is therefore being | |
2503 * restored to an old one; if not, the input() prompt stays on the screen, | |
2504 * so we need its modified msg_col left intact. */ | |
2505 if (ccline.cmdbuff != NULL) | |
2506 msg_col = msg_col_save; | |
7 | 2507 |
2508 return s; | |
2509 } | |
2510 #endif | |
2511 | |
632 | 2512 /* |
634 | 2513 * Return TRUE when the text must not be changed and we can't switch to |
2514 * another window or buffer. Used when editing the command line, evaluating | |
2515 * 'balloonexpr', etc. | |
632 | 2516 */ |
2517 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2518 text_locked(void) |
632 | 2519 { |
2520 #ifdef FEAT_CMDWIN | |
2521 if (cmdwin_type != 0) | |
2522 return TRUE; | |
2523 #endif | |
634 | 2524 return textlock != 0; |
632 | 2525 } |
2526 | |
2527 /* | |
2528 * Give an error message for a command that isn't allowed while the cmdline | |
2529 * window is open or editing the cmdline in another way. | |
2530 */ | |
2531 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2532 text_locked_msg(void) |
632 | 2533 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2534 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2535 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2536 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2537 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2538 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2539 { |
632 | 2540 #ifdef FEAT_CMDWIN |
2541 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2542 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2543 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2544 return e_secure; |
632 | 2545 } |
2546 | |
819 | 2547 /* |
1834 | 2548 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2549 * and give an error message. | |
819 | 2550 */ |
2551 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2552 curbuf_locked(void) |
819 | 2553 { |
2554 if (curbuf_lock > 0) | |
2555 { | |
2556 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2557 return TRUE; | |
2558 } | |
1834 | 2559 return allbuf_locked(); |
2560 } | |
2561 | |
2562 /* | |
2563 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2564 * message. | |
2565 */ | |
2566 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2567 allbuf_locked(void) |
1834 | 2568 { |
2569 if (allbuf_lock > 0) | |
2570 { | |
2571 EMSG(_("E811: Not allowed to change buffer information now")); | |
2572 return TRUE; | |
2573 } | |
819 | 2574 return FALSE; |
2575 } | |
2576 | |
7 | 2577 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2578 cmdline_charsize(int idx) |
7 | 2579 { |
2580 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2581 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2582 return 1; | |
2583 #endif | |
2584 return ptr2cells(ccline.cmdbuff + idx); | |
2585 } | |
2586 | |
2587 /* | |
2588 * Compute the offset of the cursor on the command line for the prompt and | |
2589 * indent. | |
2590 */ | |
2591 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2592 set_cmdspos(void) |
7 | 2593 { |
531 | 2594 if (ccline.cmdfirstc != NUL) |
7 | 2595 ccline.cmdspos = 1 + ccline.cmdindent; |
2596 else | |
2597 ccline.cmdspos = 0 + ccline.cmdindent; | |
2598 } | |
2599 | |
2600 /* | |
2601 * Compute the screen position for the cursor on the command line. | |
2602 */ | |
2603 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2604 set_cmdspos_cursor(void) |
7 | 2605 { |
2606 int i, m, c; | |
2607 | |
2608 set_cmdspos(); | |
2609 if (KeyTyped) | |
534 | 2610 { |
7 | 2611 m = Columns * Rows; |
534 | 2612 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2613 m = MAXCOL; | |
2614 } | |
7 | 2615 else |
2616 m = MAXCOL; | |
2617 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2618 { | |
2619 c = cmdline_charsize(i); | |
2620 #ifdef FEAT_MBYTE | |
2621 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2622 if (has_mbyte) | |
2623 correct_cmdspos(i, c); | |
2624 #endif | |
1612 | 2625 /* If the cmdline doesn't fit, show cursor on last visible char. |
2626 * Don't move the cursor itself, so we can still append. */ | |
7 | 2627 if ((ccline.cmdspos += c) >= m) |
2628 { | |
2629 ccline.cmdspos -= c; | |
2630 break; | |
2631 } | |
2632 #ifdef FEAT_MBYTE | |
2633 if (has_mbyte) | |
474 | 2634 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2635 #endif |
2636 } | |
2637 } | |
2638 | |
2639 #ifdef FEAT_MBYTE | |
2640 /* | |
2641 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2642 * character that doesn't fit, so that a ">" must be displayed. | |
2643 */ | |
2644 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2645 correct_cmdspos(int idx, int cells) |
7 | 2646 { |
474 | 2647 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2648 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2649 && ccline.cmdspos % Columns + cells > Columns) | |
2650 ccline.cmdspos++; | |
2651 } | |
2652 #endif | |
2653 | |
2654 /* | |
2655 * Get an Ex command line for the ":" command. | |
2656 */ | |
2657 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2658 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2659 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2660 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2661 int indent) /* indent for inside conditionals */ |
7 | 2662 { |
2663 /* When executing a register, remove ':' that's in front of each line. */ | |
2664 if (exec_from_reg && vpeekc() == ':') | |
2665 (void)vgetc(); | |
2666 return getcmdline(c, 1L, indent); | |
2667 } | |
2668 | |
2669 /* | |
2670 * Get an Ex command line for Ex mode. | |
2671 * In Ex mode we only use the OS supplied line editing features and no | |
2672 * mappings or abbreviations. | |
168 | 2673 * Returns a string in allocated memory or NULL. |
7 | 2674 */ |
2675 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2676 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2677 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2678 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2679 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2680 int indent) /* indent for inside conditionals */ |
7 | 2681 { |
168 | 2682 garray_T line_ga; |
2683 char_u *pend; | |
2684 int startcol = 0; | |
1329 | 2685 int c1 = 0; |
168 | 2686 int escaped = FALSE; /* CTRL-V typed */ |
2687 int vcol = 0; | |
2688 char_u *p; | |
1329 | 2689 int prev_char; |
5966 | 2690 int len; |
7 | 2691 |
2692 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2693 * confuses the system function that computes tabstops. */ | |
2694 cursor_on(); | |
2695 | |
2696 /* always start in column 0; write a newline if necessary */ | |
2697 compute_cmdrow(); | |
168 | 2698 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2699 msg_putchar('\n'); |
168 | 2700 if (promptc == ':') |
7 | 2701 { |
164 | 2702 /* indent that is only displayed, not in the line itself */ |
168 | 2703 if (p_prompt) |
2704 msg_putchar(':'); | |
7 | 2705 while (indent-- > 0) |
2706 msg_putchar(' '); | |
2707 startcol = msg_col; | |
2708 } | |
2709 | |
2710 ga_init2(&line_ga, 1, 30); | |
2711 | |
164 | 2712 /* autoindent for :insert and :append is in the line itself */ |
168 | 2713 if (promptc <= 0) |
164 | 2714 { |
2715 vcol = indent; | |
2716 while (indent >= 8) | |
2717 { | |
2718 ga_append(&line_ga, TAB); | |
2719 msg_puts((char_u *)" "); | |
2720 indent -= 8; | |
2721 } | |
2722 while (indent-- > 0) | |
2723 { | |
2724 ga_append(&line_ga, ' '); | |
2725 msg_putchar(' '); | |
2726 } | |
2727 } | |
168 | 2728 ++no_mapping; |
2729 ++allow_keys; | |
164 | 2730 |
7 | 2731 /* |
2732 * Get the line, one character at a time. | |
2733 */ | |
2734 got_int = FALSE; | |
168 | 2735 while (!got_int) |
7 | 2736 { |
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
|
2737 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
|
2738 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
|
2739 |
7 | 2740 if (ga_grow(&line_ga, 40) == FAIL) |
2741 break; | |
2742 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2743 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2744 * 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
|
2745 */ |
1329 | 2746 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
|
2747 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2748 /* 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
|
2749 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
|
2750 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
|
2751 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2752 c1 = vgetc(); |
7 | 2753 |
2754 /* | |
168 | 2755 * Handle line editing. |
2756 * Previously this was left to the system, putting the terminal in | |
2757 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2758 */ |
168 | 2759 if (got_int) |
2760 { | |
2761 msg_putchar('\n'); | |
2762 break; | |
2763 } | |
2764 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2765 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
|
2766 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2767 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
|
2768 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
|
2769 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2770 |
168 | 2771 if (!escaped) |
7 | 2772 { |
168 | 2773 /* CR typed means "enter", which is NL */ |
2774 if (c1 == '\r') | |
2775 c1 = '\n'; | |
2776 | |
2777 if (c1 == BS || c1 == K_BS | |
2778 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2779 { |
168 | 2780 if (line_ga.ga_len > 0) |
2781 { | |
5966 | 2782 #ifdef FEAT_MBYTE |
2783 if (has_mbyte) | |
2784 { | |
2785 p = (char_u *)line_ga.ga_data; | |
2786 p[line_ga.ga_len] = NUL; | |
2787 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2788 line_ga.ga_len -= len; | |
2789 } | |
2790 else | |
2791 #endif | |
2792 --line_ga.ga_len; | |
168 | 2793 goto redraw; |
2794 } | |
2795 continue; | |
7 | 2796 } |
2797 | |
168 | 2798 if (c1 == Ctrl_U) |
7 | 2799 { |
168 | 2800 msg_col = startcol; |
2801 msg_clr_eos(); | |
2802 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
|
2803 goto redraw; |
168 | 2804 } |
2805 | |
2806 if (c1 == Ctrl_T) | |
2807 { | |
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
|
2808 sw = get_sw_value(curbuf); |
168 | 2809 p = (char_u *)line_ga.ga_data; |
2810 p[line_ga.ga_len] = NUL; | |
5995 | 2811 indent = get_indent_str(p, 8, FALSE); |
3740 | 2812 indent += sw - indent % sw; |
168 | 2813 add_indent: |
5995 | 2814 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2815 { |
7009 | 2816 (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
|
2817 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
|
2818 s = skipwhite(p); |
168 | 2819 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2820 *s = ' '; | |
2821 ++line_ga.ga_len; | |
7 | 2822 } |
168 | 2823 redraw: |
2824 /* redraw the line */ | |
2825 msg_col = startcol; | |
2826 vcol = 0; | |
5966 | 2827 p = (char_u *)line_ga.ga_data; |
2828 p[line_ga.ga_len] = NUL; | |
2829 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2830 { |
168 | 2831 if (*p == TAB) |
7 | 2832 { |
168 | 2833 do |
7 | 2834 { |
168 | 2835 msg_putchar(' '); |
2836 } while (++vcol % 8); | |
5966 | 2837 ++p; |
7 | 2838 } |
168 | 2839 else |
164 | 2840 { |
5966 | 2841 len = MB_PTR2LEN(p); |
2842 msg_outtrans_len(p, len); | |
2843 vcol += ptr2cells(p); | |
2844 p += len; | |
7 | 2845 } |
2846 } | |
168 | 2847 msg_clr_eos(); |
1329 | 2848 windgoto(msg_row, msg_col); |
168 | 2849 continue; |
2850 } | |
2851 | |
2852 if (c1 == Ctrl_D) | |
2853 { | |
2854 /* Delete one shiftwidth. */ | |
2855 p = (char_u *)line_ga.ga_data; | |
2856 if (prev_char == '0' || prev_char == '^') | |
7 | 2857 { |
168 | 2858 if (prev_char == '^') |
2859 ex_keep_indent = TRUE; | |
2860 indent = 0; | |
2861 p[--line_ga.ga_len] = NUL; | |
7 | 2862 } |
2863 else | |
2864 { | |
168 | 2865 p[line_ga.ga_len] = NUL; |
5995 | 2866 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
|
2867 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
|
2868 { |
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 --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
|
2870 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
|
2871 } |
168 | 2872 } |
5995 | 2873 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2874 { |
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
|
2875 s = skipwhite(p); |
168 | 2876 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2877 --line_ga.ga_len; | |
7 | 2878 } |
168 | 2879 goto add_indent; |
2880 } | |
2881 | |
2882 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2883 { | |
2884 escaped = TRUE; | |
2885 continue; | |
7 | 2886 } |
168 | 2887 |
2888 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2889 if (IS_SPECIAL(c1)) | |
2890 continue; | |
7 | 2891 } |
168 | 2892 |
2893 if (IS_SPECIAL(c1)) | |
2894 c1 = '?'; | |
5966 | 2895 #ifdef FEAT_MBYTE |
2896 if (has_mbyte) | |
2897 len = (*mb_char2bytes)(c1, | |
2898 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2899 else | |
2900 #endif | |
2901 { | |
2902 len = 1; | |
2903 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2904 } | |
168 | 2905 if (c1 == '\n') |
2906 msg_putchar('\n'); | |
2907 else if (c1 == TAB) | |
2908 { | |
2909 /* Don't use chartabsize(), 'ts' can be different */ | |
2910 do | |
2911 { | |
2912 msg_putchar(' '); | |
2913 } while (++vcol % 8); | |
2914 } | |
7 | 2915 else |
2916 { | |
168 | 2917 msg_outtrans_len( |
5966 | 2918 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2919 vcol += char2cells(c1); |
7 | 2920 } |
5966 | 2921 line_ga.ga_len += len; |
168 | 2922 escaped = FALSE; |
2923 | |
2924 windgoto(msg_row, msg_col); | |
164 | 2925 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2926 |
2590 | 2927 /* We are done when a NL is entered, but not when it comes after an |
2928 * odd number of backslashes, that results in a NUL. */ | |
2929 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2930 { |
2590 | 2931 int bcount = 0; |
2932 | |
2933 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2934 ++bcount; | |
2935 | |
2936 if (bcount > 0) | |
2937 { | |
2938 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2939 * "\NL", etc. */ | |
2940 line_ga.ga_len -= (bcount + 1) / 2; | |
2941 pend -= (bcount + 1) / 2; | |
2942 pend[-1] = '\n'; | |
2943 } | |
2944 | |
2945 if ((bcount & 1) == 0) | |
2946 { | |
2947 --line_ga.ga_len; | |
2948 --pend; | |
2949 *pend = NUL; | |
2950 break; | |
2951 } | |
7 | 2952 } |
2953 } | |
2954 | |
168 | 2955 --no_mapping; |
2956 --allow_keys; | |
2957 | |
7 | 2958 /* make following messages go to the next line */ |
2959 msg_didout = FALSE; | |
2960 msg_col = 0; | |
2961 if (msg_row < Rows - 1) | |
2962 ++msg_row; | |
2963 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2964 | |
2965 if (got_int) | |
2966 ga_clear(&line_ga); | |
2967 | |
2968 return (char_u *)line_ga.ga_data; | |
2969 } | |
2970 | |
502 | 2971 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2972 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2973 /* |
2974 * Return TRUE if ccline.overstrike is on. | |
2975 */ | |
2976 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2977 cmdline_overstrike(void) |
7 | 2978 { |
2979 return ccline.overstrike; | |
2980 } | |
2981 | |
2982 /* | |
2983 * Return TRUE if the cursor is at the end of the cmdline. | |
2984 */ | |
2985 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2986 cmdline_at_end(void) |
7 | 2987 { |
2988 return (ccline.cmdpos >= ccline.cmdlen); | |
2989 } | |
2990 #endif | |
2991 | |
574 | 2992 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2993 /* |
2994 * Return the virtual column number at the current cursor position. | |
2995 * This is used by the IM code to obtain the start of the preedit string. | |
2996 */ | |
2997 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2998 cmdline_getvcol_cursor(void) |
7 | 2999 { |
3000 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3001 return MAXCOL; | |
3002 | |
3003 # ifdef FEAT_MBYTE | |
3004 if (has_mbyte) | |
3005 { | |
3006 colnr_T col; | |
3007 int i = 0; | |
3008 | |
3009 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3010 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3011 |
3012 return col; | |
3013 } | |
3014 else | |
3015 # endif | |
3016 return ccline.cmdpos; | |
3017 } | |
3018 #endif | |
3019 | |
3020 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3021 /* | |
3022 * If part of the command line is an IM preedit string, redraw it with | |
3023 * IM feedback attributes. The cursor position is restored after drawing. | |
3024 */ | |
3025 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3026 redrawcmd_preedit(void) |
7 | 3027 { |
3028 if ((State & CMDLINE) | |
3029 && xic != NULL | |
976 | 3030 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3031 && !p_imdisable |
3032 && im_is_preediting()) | |
3033 { | |
3034 int cmdpos = 0; | |
3035 int cmdspos; | |
3036 int old_row; | |
3037 int old_col; | |
3038 colnr_T col; | |
3039 | |
3040 old_row = msg_row; | |
3041 old_col = msg_col; | |
531 | 3042 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3043 |
3044 # ifdef FEAT_MBYTE | |
3045 if (has_mbyte) | |
3046 { | |
3047 for (col = 0; col < preedit_start_col | |
3048 && cmdpos < ccline.cmdlen; ++col) | |
3049 { | |
3050 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3051 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3052 } |
3053 } | |
3054 else | |
3055 # endif | |
3056 { | |
3057 cmdspos += preedit_start_col; | |
3058 cmdpos += preedit_start_col; | |
3059 } | |
3060 | |
3061 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3062 msg_col = cmdspos % (int)Columns; | |
3063 if (msg_row >= Rows) | |
3064 msg_row = Rows - 1; | |
3065 | |
3066 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3067 { | |
3068 int char_len; | |
3069 int char_attr; | |
3070 | |
3071 char_attr = im_get_feedback_attr(col); | |
3072 if (char_attr < 0) | |
3073 break; /* end of preedit string */ | |
3074 | |
3075 # ifdef FEAT_MBYTE | |
3076 if (has_mbyte) | |
474 | 3077 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3078 else |
3079 # endif | |
3080 char_len = 1; | |
3081 | |
3082 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3083 cmdpos += char_len; | |
3084 } | |
3085 | |
3086 msg_row = old_row; | |
3087 msg_col = old_col; | |
3088 } | |
3089 } | |
3090 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3091 | |
3092 /* | |
3093 * Allocate a new command line buffer. | |
3094 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3095 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3096 */ | |
3097 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3098 alloc_cmdbuff(int len) |
7 | 3099 { |
3100 /* | |
3101 * give some extra space to avoid having to allocate all the time | |
3102 */ | |
3103 if (len < 80) | |
3104 len = 100; | |
3105 else | |
3106 len += 20; | |
3107 | |
3108 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3109 ccline.cmdbufflen = len; | |
3110 } | |
3111 | |
3112 /* | |
3113 * Re-allocate the command line to length len + something extra. | |
3114 * return FAIL for failure, OK otherwise | |
3115 */ | |
3116 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3117 realloc_cmdbuff(int len) |
7 | 3118 { |
3119 char_u *p; | |
3120 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3121 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3122 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
|
3123 |
7 | 3124 p = ccline.cmdbuff; |
3125 alloc_cmdbuff(len); /* will get some more */ | |
3126 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3127 { | |
3128 ccline.cmdbuff = p; /* keep the old one */ | |
3129 return FAIL; | |
3130 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3131 /* 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
|
3132 * 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
|
3133 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
|
3134 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3135 vim_free(p); |
1718 | 3136 |
3137 if (ccline.xpc != NULL | |
3138 && ccline.xpc->xp_pattern != NULL | |
3139 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3140 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3141 { | |
1754 | 3142 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3143 |
3144 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3145 * to point into the newly allocated memory. */ | |
3146 if (i >= 0 && i <= ccline.cmdlen) | |
3147 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3148 } | |
3149 | |
7 | 3150 return OK; |
3151 } | |
3152 | |
359 | 3153 #if defined(FEAT_ARABIC) || defined(PROTO) |
3154 static char_u *arshape_buf = NULL; | |
3155 | |
3156 # if defined(EXITFREE) || defined(PROTO) | |
3157 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3158 free_cmdline_buf(void) |
359 | 3159 { |
3160 vim_free(arshape_buf); | |
3161 } | |
3162 # endif | |
3163 #endif | |
3164 | |
7 | 3165 /* |
3166 * Draw part of the cmdline at the current cursor position. But draw stars | |
3167 * when cmdline_star is TRUE. | |
3168 */ | |
3169 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3170 draw_cmdline(int start, int len) |
7 | 3171 { |
3172 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3173 int i; | |
3174 | |
3175 if (cmdline_star > 0) | |
3176 for (i = 0; i < len; ++i) | |
3177 { | |
3178 msg_putchar('*'); | |
3179 # ifdef FEAT_MBYTE | |
3180 if (has_mbyte) | |
474 | 3181 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3182 # endif |
3183 } | |
3184 else | |
3185 #endif | |
3186 #ifdef FEAT_ARABIC | |
3187 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3188 { | |
3189 static int buflen = 0; | |
3190 char_u *p; | |
3191 int j; | |
3192 int newlen = 0; | |
3193 int mb_l; | |
719 | 3194 int pc, pc1 = 0; |
7 | 3195 int prev_c = 0; |
3196 int prev_c1 = 0; | |
714 | 3197 int u8c; |
3198 int u8cc[MAX_MCO]; | |
7 | 3199 int nc = 0; |
3200 | |
3201 /* | |
3202 * Do arabic shaping into a temporary buffer. This is very | |
3203 * inefficient! | |
3204 */ | |
507 | 3205 if (len * 2 + 2 > buflen) |
7 | 3206 { |
3207 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3208 * alloc()/free() calls. */ | |
359 | 3209 vim_free(arshape_buf); |
507 | 3210 buflen = len * 2 + 2; |
359 | 3211 arshape_buf = alloc(buflen); |
3212 if (arshape_buf == NULL) | |
7 | 3213 return; /* out of memory */ |
3214 } | |
3215 | |
507 | 3216 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3217 { | |
3218 /* Prepend a space to draw the leading composing char on. */ | |
3219 arshape_buf[0] = ' '; | |
3220 newlen = 1; | |
3221 } | |
3222 | |
7 | 3223 for (j = start; j < start + len; j += mb_l) |
3224 { | |
3225 p = ccline.cmdbuff + j; | |
714 | 3226 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3227 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3228 if (ARABIC_CHAR(u8c)) |
3229 { | |
3230 /* Do Arabic shaping. */ | |
3231 if (cmdmsg_rl) | |
3232 { | |
3233 /* displaying from right to left */ | |
3234 pc = prev_c; | |
3235 pc1 = prev_c1; | |
714 | 3236 prev_c1 = u8cc[0]; |
7 | 3237 if (j + mb_l >= start + len) |
3238 nc = NUL; | |
3239 else | |
3240 nc = utf_ptr2char(p + mb_l); | |
3241 } | |
3242 else | |
3243 { | |
3244 /* displaying from left to right */ | |
3245 if (j + mb_l >= start + len) | |
3246 pc = NUL; | |
3247 else | |
714 | 3248 { |
3249 int pcc[MAX_MCO]; | |
3250 | |
3251 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3252 start + len - j - mb_l); |
714 | 3253 pc1 = pcc[0]; |
3254 } | |
7 | 3255 nc = prev_c; |
3256 } | |
3257 prev_c = u8c; | |
3258 | |
714 | 3259 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3260 |
359 | 3261 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3262 if (u8cc[0] != 0) |
7 | 3263 { |
714 | 3264 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3265 if (u8cc[1] != 0) | |
3266 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3267 arshape_buf + newlen); |
7 | 3268 } |
3269 } | |
3270 else | |
3271 { | |
3272 prev_c = u8c; | |
359 | 3273 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3274 newlen += mb_l; |
3275 } | |
3276 } | |
3277 | |
359 | 3278 msg_outtrans_len(arshape_buf, newlen); |
7 | 3279 } |
3280 else | |
3281 #endif | |
3282 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3283 } | |
3284 | |
3285 /* | |
3286 * Put a character on the command line. Shifts the following text to the | |
3287 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3288 * "c" must be printable (fit in one display cell)! | |
3289 */ | |
3290 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3291 putcmdline(int c, int shift) |
7 | 3292 { |
3293 if (cmd_silent) | |
3294 return; | |
3295 msg_no_more = TRUE; | |
3296 msg_putchar(c); | |
3297 if (shift) | |
3298 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3299 msg_no_more = FALSE; | |
3300 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3301 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3302 extra_char_shift = shift; |
7 | 3303 } |
3304 | |
3305 /* | |
3306 * Undo a putcmdline(c, FALSE). | |
3307 */ | |
3308 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3309 unputcmdline(void) |
7 | 3310 { |
3311 if (cmd_silent) | |
3312 return; | |
3313 msg_no_more = TRUE; | |
3314 if (ccline.cmdlen == ccline.cmdpos) | |
3315 msg_putchar(' '); | |
3558 | 3316 #ifdef FEAT_MBYTE |
3317 else if (has_mbyte) | |
3318 draw_cmdline(ccline.cmdpos, | |
3319 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3320 #endif | |
7 | 3321 else |
3322 draw_cmdline(ccline.cmdpos, 1); | |
3323 msg_no_more = FALSE; | |
3324 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3325 extra_char = NUL; |
7 | 3326 } |
3327 | |
3328 /* | |
3329 * Put the given string, of the given length, onto the command line. | |
3330 * If len is -1, then STRLEN() is used to calculate the length. | |
3331 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3332 * part will be redrawn, otherwise it will not. If this function is called | |
3333 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3334 * called afterwards. | |
3335 */ | |
3336 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3337 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3338 { |
3339 int retval; | |
3340 int i; | |
3341 int m; | |
3342 int c; | |
3343 | |
3344 if (len < 0) | |
3345 len = (int)STRLEN(str); | |
3346 | |
3347 /* Check if ccline.cmdbuff needs to be longer */ | |
3348 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
|
3349 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3350 else |
3351 retval = OK; | |
3352 if (retval == OK) | |
3353 { | |
3354 if (!ccline.overstrike) | |
3355 { | |
3356 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3357 ccline.cmdbuff + ccline.cmdpos, | |
3358 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3359 ccline.cmdlen += len; | |
3360 } | |
3361 else | |
3362 { | |
3363 #ifdef FEAT_MBYTE | |
3364 if (has_mbyte) | |
3365 { | |
3366 /* Count nr of characters in the new string. */ | |
3367 m = 0; | |
474 | 3368 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3369 ++m; |
3370 /* Count nr of bytes in cmdline that are overwritten by these | |
3371 * characters. */ | |
3372 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3373 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3374 --m; |
3375 if (i < ccline.cmdlen) | |
3376 { | |
3377 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3378 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3379 ccline.cmdlen += ccline.cmdpos + len - i; | |
3380 } | |
3381 else | |
3382 ccline.cmdlen = ccline.cmdpos + len; | |
3383 } | |
3384 else | |
3385 #endif | |
3386 if (ccline.cmdpos + len > ccline.cmdlen) | |
3387 ccline.cmdlen = ccline.cmdpos + len; | |
3388 } | |
3389 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3390 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3391 | |
3392 #ifdef FEAT_MBYTE | |
3393 if (enc_utf8) | |
3394 { | |
3395 /* When the inserted text starts with a composing character, | |
3396 * backup to the character before it. There could be two of them. | |
3397 */ | |
3398 i = 0; | |
3399 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3400 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3401 { | |
3402 i = (*mb_head_off)(ccline.cmdbuff, | |
3403 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3404 ccline.cmdpos -= i; | |
3405 len += i; | |
3406 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3407 } | |
3408 # ifdef FEAT_ARABIC | |
3409 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3410 { | |
3411 /* Check the previous character for Arabic combining pair. */ | |
3412 i = (*mb_head_off)(ccline.cmdbuff, | |
3413 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3414 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3415 + ccline.cmdpos - i), c)) | |
3416 { | |
3417 ccline.cmdpos -= i; | |
3418 len += i; | |
3419 } | |
3420 else | |
3421 i = 0; | |
3422 } | |
3423 # endif | |
3424 if (i != 0) | |
3425 { | |
3426 /* Also backup the cursor position. */ | |
3427 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3428 ccline.cmdspos -= i; | |
3429 msg_col -= i; | |
3430 if (msg_col < 0) | |
3431 { | |
3432 msg_col += Columns; | |
3433 --msg_row; | |
3434 } | |
3435 } | |
3436 } | |
3437 #endif | |
3438 | |
3439 if (redraw && !cmd_silent) | |
3440 { | |
3441 msg_no_more = TRUE; | |
3442 i = cmdline_row; | |
3114 | 3443 cursorcmd(); |
7 | 3444 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3445 /* Avoid clearing the rest of the line too often. */ | |
3446 if (cmdline_row != i || ccline.overstrike) | |
3447 msg_clr_eos(); | |
3448 msg_no_more = FALSE; | |
3449 } | |
3450 #ifdef FEAT_FKMAP | |
3451 /* | |
3452 * If we are in Farsi command mode, the character input must be in | |
3453 * Insert mode. So do not advance the cmdpos. | |
3454 */ | |
3455 if (!cmd_fkmap) | |
3456 #endif | |
3457 { | |
3458 if (KeyTyped) | |
534 | 3459 { |
7 | 3460 m = Columns * Rows; |
534 | 3461 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3462 m = MAXCOL; | |
3463 } | |
7 | 3464 else |
3465 m = MAXCOL; | |
3466 for (i = 0; i < len; ++i) | |
3467 { | |
3468 c = cmdline_charsize(ccline.cmdpos); | |
3469 #ifdef FEAT_MBYTE | |
3470 /* count ">" for a double-wide char that doesn't fit. */ | |
3471 if (has_mbyte) | |
3472 correct_cmdspos(ccline.cmdpos, c); | |
3473 #endif | |
1612 | 3474 /* Stop cursor at the end of the screen, but do increment the |
3475 * insert position, so that entering a very long command | |
3476 * works, even though you can't see it. */ | |
3477 if (ccline.cmdspos + c < m) | |
3478 ccline.cmdspos += c; | |
7 | 3479 #ifdef FEAT_MBYTE |
3480 if (has_mbyte) | |
3481 { | |
474 | 3482 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3483 if (c > len - i - 1) |
3484 c = len - i - 1; | |
3485 ccline.cmdpos += c; | |
3486 i += c; | |
3487 } | |
3488 #endif | |
3489 ++ccline.cmdpos; | |
3490 } | |
3491 } | |
3492 } | |
3493 if (redraw) | |
3494 msg_check(); | |
3495 return retval; | |
3496 } | |
3497 | |
95 | 3498 static struct cmdline_info prev_ccline; |
3499 static int prev_ccline_used = FALSE; | |
3500 | |
3501 /* | |
3502 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3503 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3504 * available globally in prev_ccline. | |
3505 */ | |
3506 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3507 save_cmdline(struct cmdline_info *ccp) |
95 | 3508 { |
3509 if (!prev_ccline_used) | |
3510 { | |
3511 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3512 prev_ccline_used = TRUE; | |
3513 } | |
3514 *ccp = prev_ccline; | |
3515 prev_ccline = ccline; | |
3516 ccline.cmdbuff = NULL; | |
3517 ccline.cmdprompt = NULL; | |
1718 | 3518 ccline.xpc = NULL; |
95 | 3519 } |
3520 | |
3521 /* | |
1214 | 3522 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3523 */ |
3524 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3525 restore_cmdline(struct cmdline_info *ccp) |
95 | 3526 { |
3527 ccline = prev_ccline; | |
3528 prev_ccline = *ccp; | |
3529 } | |
3530 | |
849 | 3531 #if defined(FEAT_EVAL) || defined(PROTO) |
3532 /* | |
3533 * Save the command line into allocated memory. Returns a pointer to be | |
3534 * passed to restore_cmdline_alloc() later. | |
3535 * Returns NULL when failed. | |
3536 */ | |
3537 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3538 save_cmdline_alloc(void) |
849 | 3539 { |
3540 struct cmdline_info *p; | |
3541 | |
3542 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3543 if (p != NULL) | |
3544 save_cmdline(p); | |
3545 return (char_u *)p; | |
3546 } | |
3547 | |
3548 /* | |
3549 * Restore the command line from the return value of save_cmdline_alloc(). | |
3550 */ | |
3551 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3552 restore_cmdline_alloc(char_u *p) |
849 | 3553 { |
3554 if (p != NULL) | |
3555 { | |
3556 restore_cmdline((struct cmdline_info *)p); | |
3557 vim_free(p); | |
3558 } | |
3559 } | |
3560 #endif | |
3561 | |
15 | 3562 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3563 * 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
|
3564 * Used by CTRL-R command in command-line mode. |
15 | 3565 * insert_reg() can't be used here, because special characters from the |
3566 * register contents will be interpreted as commands. | |
3567 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3568 * Return FAIL for failure, OK otherwise. |
15 | 3569 */ |
3570 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3571 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3572 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3573 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
|
3574 int remcr) /* remove trailing CR */ |
15 | 3575 { |
3576 long i; | |
3577 char_u *arg; | |
772 | 3578 char_u *p; |
15 | 3579 int allocated; |
3580 struct cmdline_info save_ccline; | |
3581 | |
3582 /* check for valid regname; also accept special characters for CTRL-R in | |
3583 * the command line */ | |
3584 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
|
3585 && 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
|
3586 && !valid_yank_reg(regname, FALSE)) |
15 | 3587 return FAIL; |
3588 | |
3589 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3590 * CTRL-C to break the loop. */ | |
3591 line_breakcheck(); | |
3592 if (got_int) | |
3593 return FAIL; | |
3594 | |
3595 #ifdef FEAT_CLIPBOARD | |
3596 regname = may_get_selection(regname); | |
3597 #endif | |
3598 | |
634 | 3599 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3600 * things like going to another buffer when evaluating an expression. */ |
95 | 3601 save_cmdline(&save_ccline); |
634 | 3602 ++textlock; |
15 | 3603 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3604 --textlock; |
95 | 3605 restore_cmdline(&save_ccline); |
15 | 3606 |
3607 if (i) | |
3608 { | |
3609 /* Got the value of a special register in "arg". */ | |
3610 if (arg == NULL) | |
3611 return FAIL; | |
772 | 3612 |
3613 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3614 * part of the word. */ | |
3615 p = arg; | |
3616 if (p_is && regname == Ctrl_W) | |
3617 { | |
3618 char_u *w; | |
3619 int len; | |
3620 | |
3621 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3622 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3623 { |
3624 #ifdef FEAT_MBYTE | |
3625 if (has_mbyte) | |
3626 { | |
3627 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3628 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3629 break; | |
3630 w -= len; | |
3631 } | |
3632 else | |
3633 #endif | |
3634 { | |
3635 if (!vim_iswordc(w[-1])) | |
3636 break; | |
3637 --w; | |
3638 } | |
3639 } | |
2937 | 3640 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3641 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3642 p += len; | |
3643 } | |
3644 | |
3645 cmdline_paste_str(p, literally); | |
15 | 3646 if (allocated) |
3647 vim_free(arg); | |
3648 return OK; | |
3649 } | |
3650 | |
1015 | 3651 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3652 } |
3653 | |
3654 /* | |
3655 * Put a string on the command line. | |
3656 * When "literally" is TRUE, insert literally. | |
3657 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3658 * line. | |
3659 */ | |
3660 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3661 cmdline_paste_str(char_u *s, int literally) |
15 | 3662 { |
3663 int c, cv; | |
3664 | |
3665 if (literally) | |
3666 put_on_cmdline(s, -1, TRUE); | |
3667 else | |
3668 while (*s != NUL) | |
3669 { | |
3670 cv = *s; | |
3671 if (cv == Ctrl_V && s[1]) | |
3672 ++s; | |
3673 #ifdef FEAT_MBYTE | |
3674 if (has_mbyte) | |
1606 | 3675 c = mb_cptr2char_adv(&s); |
15 | 3676 else |
3677 #endif | |
3678 c = *s++; | |
3628 | 3679 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3680 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3681 #ifdef UNIX |
3682 || c == intr_char | |
3683 #endif | |
3684 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3685 stuffcharReadbuff(Ctrl_V); | |
3686 stuffcharReadbuff(c); | |
3687 } | |
3688 } | |
3689 | |
7 | 3690 #ifdef FEAT_WILDMENU |
3691 /* | |
3692 * Delete characters on the command line, from "from" to the current | |
3693 * position. | |
3694 */ | |
3695 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3696 cmdline_del(int from) |
7 | 3697 { |
3698 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3699 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3700 ccline.cmdlen -= ccline.cmdpos - from; | |
3701 ccline.cmdpos = from; | |
3702 } | |
3703 #endif | |
3704 | |
3705 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3706 * 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
|
3707 * 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
|
3708 * overwritten. |
7 | 3709 */ |
3710 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3711 redrawcmdline(void) |
7 | 3712 { |
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
|
3713 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
|
3714 } |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3715 |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3716 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
|
3717 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
|
3718 { |
7 | 3719 if (cmd_silent) |
3720 return; | |
3721 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
|
3722 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
|
3723 compute_cmdrow(); |
7 | 3724 redrawcmd(); |
3725 cursorcmd(); | |
3726 } | |
3727 | |
3728 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3729 redrawcmdprompt(void) |
7 | 3730 { |
3731 int i; | |
3732 | |
3733 if (cmd_silent) | |
3734 return; | |
531 | 3735 if (ccline.cmdfirstc != NUL) |
7 | 3736 msg_putchar(ccline.cmdfirstc); |
3737 if (ccline.cmdprompt != NULL) | |
3738 { | |
3739 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3740 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3741 /* do the reverse of set_cmdspos() */ | |
531 | 3742 if (ccline.cmdfirstc != NUL) |
7 | 3743 --ccline.cmdindent; |
3744 } | |
3745 else | |
3746 for (i = ccline.cmdindent; i > 0; --i) | |
3747 msg_putchar(' '); | |
3748 } | |
3749 | |
3750 /* | |
3751 * Redraw what is currently on the command line. | |
3752 */ | |
3753 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3754 redrawcmd(void) |
7 | 3755 { |
3756 if (cmd_silent) | |
3757 return; | |
3758 | |
683 | 3759 /* when 'incsearch' is set there may be no command line while redrawing */ |
3760 if (ccline.cmdbuff == NULL) | |
3761 { | |
3762 windgoto(cmdline_row, 0); | |
3763 msg_clr_eos(); | |
3764 return; | |
3765 } | |
3766 | |
7 | 3767 msg_start(); |
3768 redrawcmdprompt(); | |
3769 | |
3770 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3771 msg_no_more = TRUE; | |
3772 draw_cmdline(0, ccline.cmdlen); | |
3773 msg_clr_eos(); | |
3774 msg_no_more = FALSE; | |
3775 | |
3776 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
|
3777 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
|
3778 putcmdline(extra_char, extra_char_shift); |
7 | 3779 |
3780 /* | |
3781 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3782 * in cmdline mode we can reset them now. | |
3783 */ | |
3784 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3785 | |
3786 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3787 * in cmdline mode */ | |
3788 skip_redraw = FALSE; | |
3789 } | |
3790 | |
3791 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3792 compute_cmdrow(void) |
7 | 3793 { |
540 | 3794 if (exmode_active || msg_scrolled != 0) |
7 | 3795 cmdline_row = Rows - 1; |
3796 else | |
3797 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
|
3798 + lastwin->w_status_height; |
7 | 3799 } |
3800 | |
3801 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3802 cursorcmd(void) |
7 | 3803 { |
3804 if (cmd_silent) | |
3805 return; | |
3806 | |
3807 #ifdef FEAT_RIGHTLEFT | |
3808 if (cmdmsg_rl) | |
3809 { | |
3810 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3811 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3812 if (msg_row <= 0) | |
3813 msg_row = Rows - 1; | |
3814 } | |
3815 else | |
3816 #endif | |
3817 { | |
3818 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3819 msg_col = ccline.cmdspos % (int)Columns; | |
3820 if (msg_row >= Rows) | |
3821 msg_row = Rows - 1; | |
3822 } | |
3823 | |
3824 windgoto(msg_row, msg_col); | |
3825 #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
|
3826 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
|
3827 redrawcmd_preedit(); |
7 | 3828 #endif |
3829 #ifdef MCH_CURSOR_SHAPE | |
3830 mch_update_cursor(); | |
3831 #endif | |
3832 } | |
3833 | |
3834 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3835 gotocmdline(int clr) |
7 | 3836 { |
3837 msg_start(); | |
3838 #ifdef FEAT_RIGHTLEFT | |
3839 if (cmdmsg_rl) | |
3840 msg_col = Columns - 1; | |
3841 else | |
3842 #endif | |
3843 msg_col = 0; /* always start in column 0 */ | |
3844 if (clr) /* clear the bottom line(s) */ | |
3845 msg_clr_eos(); /* will reset clear_cmdline */ | |
3846 windgoto(cmdline_row, 0); | |
3847 } | |
3848 | |
3849 /* | |
3850 * Check the word in front of the cursor for an abbreviation. | |
3851 * Called when the non-id character "c" has been entered. | |
3852 * When an abbreviation is recognized it is removed from the text with | |
3853 * backspaces and the replacement string is inserted, followed by "c". | |
3854 */ | |
3855 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3856 ccheck_abbr(int c) |
7 | 3857 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3858 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3859 |
7 | 3860 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3861 return FALSE; | |
3862 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3863 /* 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
|
3864 * 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
|
3865 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
|
3866 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3867 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
|
3868 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3869 && 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
|
3870 && 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
|
3871 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3872 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3873 /* 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
|
3874 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3875 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3876 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3877 } |
3878 | |
3164 | 3879 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3880 static int | |
3881 #ifdef __BORLANDC__ | |
3882 _RTLENTRYF | |
3883 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3884 sort_func_compare(const void *s1, const void *s2) |
3164 | 3885 { |
3886 char_u *p1 = *(char_u **)s1; | |
3887 char_u *p2 = *(char_u **)s2; | |
3888 | |
3889 if (*p1 != '<' && *p2 == '<') return -1; | |
3890 if (*p1 == '<' && *p2 != '<') return 1; | |
3891 return STRCMP(p1, p2); | |
3892 } | |
3893 #endif | |
3894 | |
7 | 3895 /* |
3896 * Return FAIL if this is not an appropriate context in which to do | |
3897 * completion of anything, return OK if it is (even if there are no matches). | |
3898 * For the caller, this means that the character is just passed through like a | |
3899 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3900 */ | |
3901 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3902 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3903 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3904 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3905 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3906 int escape) /* if TRUE, escape the returned matches */ |
7 | 3907 { |
3908 int i, j; | |
3909 char_u *p1; | |
3910 char_u *p2; | |
3911 int difflen; | |
3912 int v; | |
3913 | |
3914 if (xp->xp_numfiles == -1) | |
3915 { | |
3916 set_expand_context(xp); | |
3917 cmd_showtail = expand_showtail(xp); | |
3918 } | |
3919 | |
3920 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3921 { | |
3922 beep_flush(); | |
3923 return OK; /* Something illegal on command line */ | |
3924 } | |
3925 if (xp->xp_context == EXPAND_NOTHING) | |
3926 { | |
3927 /* Caller can use the character as a normal char instead */ | |
3928 return FAIL; | |
3929 } | |
3930 | |
3931 MSG_PUTS("..."); /* show that we are busy */ | |
3932 out_flush(); | |
3933 | |
3934 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3935 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3936 |
3937 if (type == WILD_NEXT || type == WILD_PREV) | |
3938 { | |
3939 /* | |
3940 * Get next/previous match for a previous expanded pattern. | |
3941 */ | |
3942 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3943 } | |
3944 else | |
3945 { | |
3946 /* | |
3947 * Translate string into pattern and expand it. | |
3948 */ | |
1965 | 3949 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3950 xp->xp_context)) == NULL) | |
7 | 3951 p2 = NULL; |
3952 else | |
3953 { | |
2652 | 3954 int use_options = options | |
3961 | 3955 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3956 if (escape) | |
3957 use_options |= WILD_ESCAPE; | |
2652 | 3958 |
3959 if (p_wic) | |
3960 use_options += WILD_ICASE; | |
1965 | 3961 p2 = ExpandOne(xp, p1, |
3962 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3963 use_options, type); |
7 | 3964 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3965 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3966 if (p2 != NULL && type == WILD_LONGEST) |
3967 { | |
1965 | 3968 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3969 if (ccline.cmdbuff[i + j] == '*' |
3970 || ccline.cmdbuff[i + j] == '?') | |
3971 break; | |
3972 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
|
3973 VIM_CLEAR(p2); |
7 | 3974 } |
3975 } | |
3976 } | |
3977 | |
3978 if (p2 != NULL && !got_int) | |
3979 { | |
1965 | 3980 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
|
3981 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3982 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3983 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3984 xp->xp_pattern = ccline.cmdbuff + i; |
3985 } | |
3986 else | |
3987 v = OK; | |
3988 if (v == OK) | |
3989 { | |
323 | 3990 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3991 &ccline.cmdbuff[ccline.cmdpos], | |
3992 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3993 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3994 ccline.cmdlen += difflen; |
3995 ccline.cmdpos += difflen; | |
3996 } | |
3997 } | |
3998 vim_free(p2); | |
3999 | |
4000 redrawcmd(); | |
33 | 4001 cursorcmd(); |
7 | 4002 |
4003 /* When expanding a ":map" command and no matches are found, assume that | |
4004 * the key is supposed to be inserted literally */ | |
4005 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
4006 return FAIL; | |
4007 | |
4008 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4009 beep_flush(); | |
4010 else if (xp->xp_numfiles == 1) | |
4011 /* free expanded pattern */ | |
4012 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4013 | |
4014 return OK; | |
4015 } | |
4016 | |
4017 /* | |
4018 * Do wildcard expansion on the string 'str'. | |
4019 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4020 * Return a pointer to allocated memory containing the new string. |
7 | 4021 * Return NULL for failure. |
4022 * | |
1412 | 4023 * "orig" is the originally expanded string, copied to allocated memory. It |
4024 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4025 * WILD_PREV "orig" should be NULL. | |
4026 * | |
838 | 4027 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4028 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4029 * |
4030 * mode = WILD_FREE: just free previously expanded matches | |
4031 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4032 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4033 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4034 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4035 * mode = WILD_ALL: return all matches concatenated | |
4036 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4037 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4038 * |
4039 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4040 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4041 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4042 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4043 * options = WILD_ADD_SLASH: add a slash after directory names | |
4044 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4045 * options = WILD_SILENT: don't print warning messages | |
4046 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4047 * options = WILD_ICASE: ignore case for files |
7 | 4048 * |
4049 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4050 */ | |
4051 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4052 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4053 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4054 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4055 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
|
4056 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4057 int mode) |
7 | 4058 { |
4059 char_u *ss = NULL; | |
4060 static int findex; | |
4061 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4062 int orig_saved = FALSE; |
7 | 4063 int i; |
4064 long_u len; | |
4065 int non_suf_match; /* number without matching suffix */ | |
4066 | |
4067 /* | |
4068 * first handle the case of using an old match | |
4069 */ | |
4070 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4071 { | |
4072 if (xp->xp_numfiles > 0) | |
4073 { | |
4074 if (mode == WILD_PREV) | |
4075 { | |
4076 if (findex == -1) | |
4077 findex = xp->xp_numfiles; | |
4078 --findex; | |
4079 } | |
4080 else /* mode == WILD_NEXT */ | |
4081 ++findex; | |
4082 | |
4083 /* | |
4084 * When wrapping around, return the original string, set findex to | |
4085 * -1. | |
4086 */ | |
4087 if (findex < 0) | |
4088 { | |
4089 if (orig_save == NULL) | |
4090 findex = xp->xp_numfiles - 1; | |
4091 else | |
4092 findex = -1; | |
4093 } | |
4094 if (findex >= xp->xp_numfiles) | |
4095 { | |
4096 if (orig_save == NULL) | |
4097 findex = 0; | |
4098 else | |
4099 findex = -1; | |
4100 } | |
4101 #ifdef FEAT_WILDMENU | |
4102 if (p_wmnu) | |
4103 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4104 findex, cmd_showtail); | |
4105 #endif | |
4106 if (findex == -1) | |
4107 return vim_strsave(orig_save); | |
4108 return vim_strsave(xp->xp_files[findex]); | |
4109 } | |
4110 else | |
4111 return NULL; | |
4112 } | |
4113 | |
1412 | 4114 /* free old names */ |
7 | 4115 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4116 { | |
4117 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4118 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
|
4119 VIM_CLEAR(orig_save); |
7 | 4120 } |
4121 findex = 0; | |
4122 | |
4123 if (mode == WILD_FREE) /* only release file name */ | |
4124 return NULL; | |
4125 | |
4126 if (xp->xp_numfiles == -1) | |
4127 { | |
4128 vim_free(orig_save); | |
4129 orig_save = orig; | |
1432 | 4130 orig_saved = TRUE; |
7 | 4131 |
4132 /* | |
4133 * Do the expansion. | |
4134 */ | |
4135 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4136 options) == FAIL) | |
4137 { | |
4138 #ifdef FNAME_ILLEGAL | |
4139 /* Illegal file name has been silently skipped. But when there | |
4140 * are wildcards, the real problem is that there was no match, | |
4141 * causing the pattern to be added, which has illegal characters. | |
4142 */ | |
4143 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4144 EMSG2(_(e_nomatch2), str); | |
4145 #endif | |
4146 } | |
4147 else if (xp->xp_numfiles == 0) | |
4148 { | |
4149 if (!(options & WILD_SILENT)) | |
4150 EMSG2(_(e_nomatch2), str); | |
4151 } | |
4152 else | |
4153 { | |
4154 /* Escape the matches for use on the command line. */ | |
4155 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4156 | |
4157 /* | |
4158 * Check for matching suffixes in file names. | |
4159 */ | |
3398 | 4160 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4161 && mode != WILD_LONGEST) | |
7 | 4162 { |
4163 if (xp->xp_numfiles) | |
4164 non_suf_match = xp->xp_numfiles; | |
4165 else | |
4166 non_suf_match = 1; | |
4167 if ((xp->xp_context == EXPAND_FILES | |
4168 || xp->xp_context == EXPAND_DIRECTORIES) | |
4169 && xp->xp_numfiles > 1) | |
4170 { | |
4171 /* | |
4172 * More than one match; check suffix. | |
4173 * The files will have been sorted on matching suffix in | |
4174 * expand_wildcards, only need to check the first two. | |
4175 */ | |
4176 non_suf_match = 0; | |
4177 for (i = 0; i < 2; ++i) | |
4178 if (match_suffix(xp->xp_files[i])) | |
4179 ++non_suf_match; | |
4180 } | |
4181 if (non_suf_match != 1) | |
4182 { | |
4183 /* Can we ever get here unless it's while expanding | |
4184 * interactively? If not, we can get rid of this all | |
4185 * together. Don't really want to wait for this message | |
4186 * (and possibly have to hit return to continue!). | |
4187 */ | |
4188 if (!(options & WILD_SILENT)) | |
4189 EMSG(_(e_toomany)); | |
4190 else if (!(options & WILD_NO_BEEP)) | |
4191 beep_flush(); | |
4192 } | |
4193 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4194 ss = vim_strsave(xp->xp_files[0]); | |
4195 } | |
4196 } | |
4197 } | |
4198 | |
4199 /* Find longest common part */ | |
4200 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4201 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4202 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4203 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4204 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4205 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4206 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4207 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4208 if (has_mbyte) |
7 | 4209 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4210 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
|
4211 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
|
4212 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4213 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4214 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4215 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
|
4216 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
|
4217 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4218 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4219 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4220 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
|
4221 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4222 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4223 ci = xp->xp_files[i][len]; |
4242 | 4224 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4225 || xp->xp_context == EXPAND_FILES |
714 | 4226 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4227 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4228 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4229 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4230 break; |
4231 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4232 else if (c0 != ci) |
7 | 4233 break; |
4234 } | |
4235 if (i < xp->xp_numfiles) | |
4236 { | |
4237 if (!(options & WILD_NO_BEEP)) | |
6949 | 4238 vim_beep(BO_WILD); |
7 | 4239 break; |
4240 } | |
4241 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4242 |
7 | 4243 ss = alloc((unsigned)len + 1); |
4244 if (ss) | |
419 | 4245 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4246 findex = -1; /* next p_wc gets first one */ |
4247 } | |
4248 | |
4249 /* Concatenate all matching names */ | |
4250 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4251 { | |
4252 len = 0; | |
4253 for (i = 0; i < xp->xp_numfiles; ++i) | |
4254 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4255 ss = lalloc(len, TRUE); | |
4256 if (ss != NULL) | |
4257 { | |
4258 *ss = NUL; | |
4259 for (i = 0; i < xp->xp_numfiles; ++i) | |
4260 { | |
4261 STRCAT(ss, xp->xp_files[i]); | |
4262 if (i != xp->xp_numfiles - 1) | |
4263 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4264 } | |
4265 } | |
4266 } | |
4267 | |
4268 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4269 ExpandCleanup(xp); | |
4270 | |
1412 | 4271 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4272 if (!orig_saved) |
1412 | 4273 vim_free(orig); |
4274 | |
7 | 4275 return ss; |
4276 } | |
4277 | |
4278 /* | |
4279 * Prepare an expand structure for use. | |
4280 */ | |
4281 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4282 ExpandInit(expand_T *xp) |
7 | 4283 { |
1718 | 4284 xp->xp_pattern = NULL; |
1965 | 4285 xp->xp_pattern_len = 0; |
7 | 4286 xp->xp_backslash = XP_BS_NONE; |
632 | 4287 #ifndef BACKSLASH_IN_FILENAME |
4288 xp->xp_shell = FALSE; | |
4289 #endif | |
7 | 4290 xp->xp_numfiles = -1; |
4291 xp->xp_files = NULL; | |
632 | 4292 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4293 xp->xp_arg = NULL; | |
4294 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4295 xp->xp_line = NULL; |
7 | 4296 } |
4297 | |
4298 /* | |
4299 * Cleanup an expand structure after use. | |
4300 */ | |
4301 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4302 ExpandCleanup(expand_T *xp) |
7 | 4303 { |
4304 if (xp->xp_numfiles >= 0) | |
4305 { | |
4306 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4307 xp->xp_numfiles = -1; | |
4308 } | |
4309 } | |
4310 | |
4311 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4312 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4313 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4314 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4315 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4316 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4317 int options) |
7 | 4318 { |
4319 int i; | |
4320 char_u *p; | |
4321 | |
4322 /* | |
4323 * May change home directory back to "~" | |
4324 */ | |
4325 if (options & WILD_HOME_REPLACE) | |
4326 tilde_replace(str, numfiles, files); | |
4327 | |
4328 if (options & WILD_ESCAPE) | |
4329 { | |
4330 if (xp->xp_context == EXPAND_FILES | |
2778 | 4331 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4332 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4333 || xp->xp_context == EXPAND_BUFFERS |
4334 || xp->xp_context == EXPAND_DIRECTORIES) | |
4335 { | |
4336 /* | |
4337 * Insert a backslash into a file name before a space, \, %, # | |
4338 * and wildmatch characters, except '~'. | |
4339 */ | |
4340 for (i = 0; i < numfiles; ++i) | |
4341 { | |
4342 /* for ":set path=" we need to escape spaces twice */ | |
4343 if (xp->xp_backslash == XP_BS_THREE) | |
4344 { | |
4345 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4346 if (p != NULL) | |
4347 { | |
4348 vim_free(files[i]); | |
4349 files[i] = p; | |
719 | 4350 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4351 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4352 if (p != NULL) | |
4353 { | |
4354 vim_free(files[i]); | |
4355 files[i] = p; | |
4356 } | |
4357 #endif | |
4358 } | |
4359 } | |
1589 | 4360 #ifdef BACKSLASH_IN_FILENAME |
4361 p = vim_strsave_fnameescape(files[i], FALSE); | |
4362 #else | |
1586 | 4363 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4364 #endif |
7 | 4365 if (p != NULL) |
4366 { | |
4367 vim_free(files[i]); | |
4368 files[i] = p; | |
4369 } | |
4370 | |
4371 /* If 'str' starts with "\~", replace "~" at start of | |
4372 * files[i] with "\~". */ | |
4373 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4374 escape_fname(&files[i]); |
7 | 4375 } |
4376 xp->xp_backslash = XP_BS_NONE; | |
435 | 4377 |
4378 /* If the first file starts with a '+' escape it. Otherwise it | |
4379 * could be seen as "+cmd". */ | |
4380 if (*files[0] == '+') | |
4381 escape_fname(&files[0]); | |
7 | 4382 } |
4383 else if (xp->xp_context == EXPAND_TAGS) | |
4384 { | |
4385 /* | |
4386 * Insert a backslash before characters in a tag name that | |
4387 * would terminate the ":tag" command. | |
4388 */ | |
4389 for (i = 0; i < numfiles; ++i) | |
4390 { | |
4391 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4392 if (p != NULL) | |
4393 { | |
4394 vim_free(files[i]); | |
4395 files[i] = p; | |
4396 } | |
4397 } | |
4398 } | |
4399 } | |
4400 } | |
4401 | |
4402 /* | |
1586 | 4403 * Escape special characters in "fname" for when used as a file name argument |
4404 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4405 * Returns the result in allocated memory. | |
4406 */ | |
4407 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4408 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4409 { |
1685 | 4410 char_u *p; |
1586 | 4411 #ifdef BACKSLASH_IN_FILENAME |
4412 char_u buf[20]; | |
4413 int j = 0; | |
4414 | |
5481 | 4415 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4416 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4417 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4418 buf[j++] = *p; |
4419 buf[j] = NUL; | |
1700 | 4420 p = vim_strsave_escaped(fname, buf); |
1586 | 4421 #else |
1685 | 4422 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4423 if (shell && csh_like_shell() && p != NULL) | |
4424 { | |
4425 char_u *s; | |
4426 | |
4427 /* For csh and similar shells need to put two backslashes before '!'. | |
4428 * One is taken by Vim, one by the shell. */ | |
4429 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4430 vim_free(p); | |
4431 p = s; | |
4432 } | |
1700 | 4433 #endif |
4434 | |
4435 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4436 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4437 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4438 escape_fname(&p); |
4439 | |
1685 | 4440 return p; |
1586 | 4441 } |
4442 | |
4443 /* | |
435 | 4444 * Put a backslash before the file name in "pp", which is in allocated memory. |
4445 */ | |
4446 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4447 escape_fname(char_u **pp) |
435 | 4448 { |
4449 char_u *p; | |
4450 | |
4451 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4452 if (p != NULL) | |
4453 { | |
4454 p[0] = '\\'; | |
4455 STRCPY(p + 1, *pp); | |
4456 vim_free(*pp); | |
4457 *pp = p; | |
4458 } | |
4459 } | |
4460 | |
4461 /* | |
7 | 4462 * For each file name in files[num_files]: |
4463 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4464 */ | |
4465 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4466 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4467 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4468 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4469 char_u **files) |
7 | 4470 { |
4471 int i; | |
4472 char_u *p; | |
4473 | |
4474 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4475 { | |
4476 for (i = 0; i < num_files; ++i) | |
4477 { | |
4478 p = home_replace_save(NULL, files[i]); | |
4479 if (p != NULL) | |
4480 { | |
4481 vim_free(files[i]); | |
4482 files[i] = p; | |
4483 } | |
4484 } | |
4485 } | |
4486 } | |
4487 | |
4488 /* | |
4489 * Show all matches for completion on the command line. | |
4490 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4491 * be inserted like a normal character. | |
4492 */ | |
4493 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4494 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4495 { |
4496 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4497 int num_files; | |
4498 char_u **files_found; | |
4499 int i, j, k; | |
4500 int maxlen; | |
4501 int lines; | |
4502 int columns; | |
4503 char_u *p; | |
4504 int lastlen; | |
4505 int attr; | |
4506 int showtail; | |
4507 | |
4508 if (xp->xp_numfiles == -1) | |
4509 { | |
4510 set_expand_context(xp); | |
4511 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4512 &num_files, &files_found); | |
4513 showtail = expand_showtail(xp); | |
4514 if (i != EXPAND_OK) | |
4515 return i; | |
4516 | |
4517 } | |
4518 else | |
4519 { | |
4520 num_files = xp->xp_numfiles; | |
4521 files_found = xp->xp_files; | |
4522 showtail = cmd_showtail; | |
4523 } | |
4524 | |
4525 #ifdef FEAT_WILDMENU | |
4526 if (!wildmenu) | |
4527 { | |
4528 #endif | |
4529 msg_didany = FALSE; /* lines_left will be set */ | |
4530 msg_start(); /* prepare for paging */ | |
4531 msg_putchar('\n'); | |
4532 out_flush(); | |
4533 cmdline_row = msg_row; | |
4534 msg_didany = FALSE; /* lines_left will be set again */ | |
4535 msg_start(); /* prepare for paging */ | |
4536 #ifdef FEAT_WILDMENU | |
4537 } | |
4538 #endif | |
4539 | |
4540 if (got_int) | |
4541 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4542 #ifdef FEAT_WILDMENU | |
4543 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
|
4544 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4545 #endif |
4546 else | |
4547 { | |
4548 /* find the length of the longest file name */ | |
4549 maxlen = 0; | |
4550 for (i = 0; i < num_files; ++i) | |
4551 { | |
4552 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4553 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4554 || xp->xp_context == EXPAND_BUFFERS)) |
4555 { | |
4556 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4557 j = vim_strsize(NameBuff); | |
4558 } | |
4559 else | |
4560 j = vim_strsize(L_SHOWFILE(i)); | |
4561 if (j > maxlen) | |
4562 maxlen = j; | |
4563 } | |
4564 | |
4565 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4566 lines = num_files; | |
4567 else | |
4568 { | |
4569 /* compute the number of columns and lines for the listing */ | |
4570 maxlen += 2; /* two spaces between file names */ | |
4571 columns = ((int)Columns + 2) / maxlen; | |
4572 if (columns < 1) | |
4573 columns = 1; | |
4574 lines = (num_files + columns - 1) / columns; | |
4575 } | |
4576 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4577 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4578 |
4579 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4580 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4581 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4582 msg_clr_eos(); |
4583 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
|
4584 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4585 } |
4586 | |
4587 /* list the files line by line */ | |
4588 for (i = 0; i < lines; ++i) | |
4589 { | |
4590 lastlen = 999; | |
4591 for (k = i; k < num_files; k += lines) | |
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_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4596 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4597 msg_advance(maxlen + 1); | |
4598 msg_puts(p); | |
4599 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
|
4600 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4601 break; |
4602 } | |
4603 for (j = maxlen - lastlen; --j >= 0; ) | |
4604 msg_putchar(' '); | |
4605 if (xp->xp_context == EXPAND_FILES | |
714 | 4606 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4607 || xp->xp_context == EXPAND_BUFFERS) |
4608 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4609 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4610 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4611 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4612 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4613 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4614 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4615 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4616 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4617 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4618 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
|
4619 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4620 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4621 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4622 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4623 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4624 vim_free(halved_slash); |
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 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4627 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4628 j = mch_isdir(files_found[k]); |
7 | 4629 if (showtail) |
4630 p = L_SHOWFILE(k); | |
4631 else | |
4632 { | |
4633 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4634 TRUE); | |
4635 p = NameBuff; | |
4636 } | |
4637 } | |
4638 else | |
4639 { | |
4640 j = FALSE; | |
4641 p = L_SHOWFILE(k); | |
4642 } | |
4643 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4644 } | |
4645 if (msg_col > 0) /* when not wrapped around */ | |
4646 { | |
4647 msg_clr_eos(); | |
4648 msg_putchar('\n'); | |
4649 } | |
4650 out_flush(); /* show one line at a time */ | |
4651 if (got_int) | |
4652 { | |
4653 got_int = FALSE; | |
4654 break; | |
4655 } | |
4656 } | |
4657 | |
4658 /* | |
4659 * we redraw the command below the lines that we have just listed | |
4660 * This is a bit tricky, but it saves a lot of screen updating. | |
4661 */ | |
4662 cmdline_row = msg_row; /* will put it back later */ | |
4663 } | |
4664 | |
4665 if (xp->xp_numfiles == -1) | |
4666 FreeWild(num_files, files_found); | |
4667 | |
4668 return EXPAND_OK; | |
4669 } | |
4670 | |
4671 /* | |
4672 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4673 * Find tail of file name path, but ignore trailing "/". | |
4674 */ | |
4675 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4676 sm_gettail(char_u *s) |
7 | 4677 { |
4678 char_u *p; | |
4679 char_u *t = s; | |
4680 int had_sep = FALSE; | |
4681 | |
4682 for (p = s; *p != NUL; ) | |
4683 { | |
4684 if (vim_ispathsep(*p) | |
4685 #ifdef BACKSLASH_IN_FILENAME | |
4686 && !rem_backslash(p) | |
4687 #endif | |
4688 ) | |
4689 had_sep = TRUE; | |
4690 else if (had_sep) | |
4691 { | |
4692 t = p; | |
4693 had_sep = FALSE; | |
4694 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4695 MB_PTR_ADV(p); |
7 | 4696 } |
4697 return t; | |
4698 } | |
4699 | |
4700 /* | |
4701 * Return TRUE if we only need to show the tail of completion matches. | |
4702 * When not completing file names or there is a wildcard in the path FALSE is | |
4703 * returned. | |
4704 */ | |
4705 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4706 expand_showtail(expand_T *xp) |
7 | 4707 { |
4708 char_u *s; | |
4709 char_u *end; | |
4710 | |
4711 /* When not completing file names a "/" may mean something different. */ | |
714 | 4712 if (xp->xp_context != EXPAND_FILES |
4713 && xp->xp_context != EXPAND_SHELLCMD | |
4714 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4715 return FALSE; |
4716 | |
4717 end = gettail(xp->xp_pattern); | |
4718 if (end == xp->xp_pattern) /* there is no path separator */ | |
4719 return FALSE; | |
4720 | |
4721 for (s = xp->xp_pattern; s < end; s++) | |
4722 { | |
4723 /* Skip escaped wildcards. Only when the backslash is not a path | |
4724 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4725 if (rem_backslash(s)) | |
4726 ++s; | |
4727 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4728 return FALSE; | |
4729 } | |
4730 return TRUE; | |
4731 } | |
4732 | |
4733 /* | |
4734 * Prepare a string for expansion. | |
4735 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4736 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4737 * When expanding other names: The string will be used with regcomp(). Copy |
4738 * the name into allocated memory and prepend "^". | |
4739 */ | |
4740 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4741 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4742 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4743 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4744 int context) /* EXPAND_FILES etc. */ |
7 | 4745 { |
4746 char_u *retval; | |
4747 int i, j; | |
4748 int new_len; | |
4749 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4750 int ends_in_star; |
7 | 4751 |
714 | 4752 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4753 && context != EXPAND_FILES_IN_PATH |
714 | 4754 && context != EXPAND_SHELLCMD |
4755 && context != EXPAND_DIRECTORIES) | |
7 | 4756 { |
4757 /* | |
4758 * Matching will be done internally (on something other than files). | |
4759 * So we convert the file-matching-type wildcards into our kind for | |
4760 * use with vim_regcomp(). First work out how long it will be: | |
4761 */ | |
4762 | |
4763 /* For help tags the translation is done in find_help_tags(). | |
4764 * For a tag pattern starting with "/" no translation is needed. */ | |
4765 if (context == EXPAND_HELP | |
4766 || context == EXPAND_COLORS | |
4767 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4768 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4769 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4770 || 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
|
4771 || ((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
|
4772 || 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
|
4773 && fname[0] == '/')) |
7 | 4774 retval = vim_strnsave(fname, len); |
4775 else | |
4776 { | |
4777 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4778 for (i = 0; i < len; i++) | |
4779 { | |
4780 if (fname[i] == '*' || fname[i] == '~') | |
4781 new_len++; /* '*' needs to be replaced by ".*" | |
4782 '~' needs to be replaced by "\~" */ | |
4783 | |
4784 /* Buffer names are like file names. "." should be literal */ | |
4785 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4786 new_len++; /* "." becomes "\." */ | |
4787 | |
4788 /* Custom expansion takes care of special things, match | |
4789 * backslashes literally (perhaps also for other types?) */ | |
634 | 4790 if ((context == EXPAND_USER_DEFINED |
4791 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4792 new_len++; /* '\' becomes "\\" */ |
4793 } | |
4794 retval = alloc(new_len); | |
4795 if (retval != NULL) | |
4796 { | |
4797 retval[0] = '^'; | |
4798 j = 1; | |
4799 for (i = 0; i < len; i++, j++) | |
4800 { | |
4801 /* Skip backslash. But why? At least keep it for custom | |
4802 * expansion. */ | |
4803 if (context != EXPAND_USER_DEFINED | |
407 | 4804 && context != EXPAND_USER_LIST |
4805 && fname[i] == '\\' | |
4806 && ++i == len) | |
7 | 4807 break; |
4808 | |
4809 switch (fname[i]) | |
4810 { | |
4811 case '*': retval[j++] = '.'; | |
4812 break; | |
4813 case '~': retval[j++] = '\\'; | |
4814 break; | |
4815 case '?': retval[j] = '.'; | |
4816 continue; | |
4817 case '.': if (context == EXPAND_BUFFERS) | |
4818 retval[j++] = '\\'; | |
4819 break; | |
407 | 4820 case '\\': if (context == EXPAND_USER_DEFINED |
4821 || context == EXPAND_USER_LIST) | |
7 | 4822 retval[j++] = '\\'; |
4823 break; | |
4824 } | |
4825 retval[j] = fname[i]; | |
4826 } | |
4827 retval[j] = NUL; | |
4828 } | |
4829 } | |
4830 } | |
4831 else | |
4832 { | |
4833 retval = alloc(len + 4); | |
4834 if (retval != NULL) | |
4835 { | |
419 | 4836 vim_strncpy(retval, fname, len); |
7 | 4837 |
4838 /* | |
831 | 4839 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4840 * * would become **, which walks the whole tree. | |
7 | 4841 * ~ would be at the start of the file name, but not the tail. |
4842 * $ could be anywhere in the tail. | |
4843 * ` could be anywhere in the file name. | |
1484 | 4844 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4845 */ |
4846 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4847 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
|
4848 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4849 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4850 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4851 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4852 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4853 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4854 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4855 #endif |
7 | 4856 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4857 && !ends_in_star |
7 | 4858 && vim_strchr(tail, '$') == NULL |
4859 && vim_strchr(retval, '`') == NULL) | |
4860 retval[len++] = '*'; | |
1484 | 4861 else if (len > 0 && retval[len - 1] == '$') |
4862 --len; | |
7 | 4863 retval[len] = NUL; |
4864 } | |
4865 } | |
4866 return retval; | |
4867 } | |
4868 | |
4869 /* | |
4870 * Must parse the command line so far to work out what context we are in. | |
4871 * Completion can then be done based on that context. | |
4872 * This routine sets the variables: | |
4873 * xp->xp_pattern The start of the pattern to be expanded within | |
4874 * the command line (ends at the cursor). | |
4875 * xp->xp_context The type of thing to expand. Will be one of: | |
4876 * | |
4877 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4878 * the command line, like an unknown command. Caller | |
4879 * should beep. | |
4880 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4881 * a normal char, rather than for completion. eg | |
4882 * :s/^I/ | |
4883 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4884 * it. | |
4885 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4886 * EXPAND_FILES After command with XFILE set, or after setting | |
4887 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4888 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4889 * when we know only directories are of interest. eg | |
4890 * :set dir=^I | |
714 | 4891 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4892 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4893 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4894 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4895 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4896 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4897 * EXPAND_EVENTS Complete event names | |
4898 * EXPAND_SYNTAX Complete :syntax command arguments | |
4899 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4900 * EXPAND_AUGROUP Complete autocommand group names | |
4901 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4902 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4903 * eg :unmap a^I , :cunab x^I | |
4904 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4905 * eg :call sub^I | |
4906 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4907 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4908 * names in expressions, eg :while s^I | |
4909 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4910 * EXPAND_USER Complete user names |
7 | 4911 */ |
4912 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4913 set_expand_context(expand_T *xp) |
7 | 4914 { |
168 | 4915 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4916 if (ccline.cmdfirstc != ':' |
4917 #ifdef FEAT_EVAL | |
168 | 4918 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4919 && !ccline.input_fn |
7 | 4920 #endif |
4921 ) | |
4922 { | |
4923 xp->xp_context = EXPAND_NOTHING; | |
4924 return; | |
4925 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4926 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4927 } |
4928 | |
4929 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4930 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4931 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4932 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
|
4933 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
|
4934 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4935 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4936 { |
4937 int old_char = NUL; | |
4938 char_u *nextcomm; | |
4939 | |
4940 /* | |
4941 * Avoid a UMR warning from Purify, only save the character if it has been | |
4942 * written before. | |
4943 */ | |
4944 if (col < len) | |
4945 old_char = str[col]; | |
4946 str[col] = NUL; | |
4947 nextcomm = str; | |
168 | 4948 |
4949 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4950 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4951 { |
4952 # ifdef FEAT_CMDL_COMPL | |
168 | 4953 /* pass CMD_SIZE because there is no real command */ |
4954 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4955 # endif |
4956 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4957 else if (use_ccline && ccline.input_fn) |
531 | 4958 { |
4959 xp->xp_context = ccline.xp_context; | |
4960 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4961 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4962 xp->xp_arg = ccline.xp_arg; |
1322 | 4963 # endif |
531 | 4964 } |
168 | 4965 else |
4966 #endif | |
4967 while (nextcomm != NULL) | |
4968 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4969 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4970 /* 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
|
4971 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4972 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4973 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4974 |
7 | 4975 str[col] = old_char; |
4976 } | |
4977 | |
4978 /* | |
4979 * Expand the command line "str" from context "xp". | |
4980 * "xp" must have been set by set_cmd_context(). | |
4981 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4982 * starts. | |
4983 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4984 * cursor. | |
4985 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4986 * key that triggered expansion literally. | |
4987 * Returns EXPAND_OK otherwise. | |
4988 */ | |
4989 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4990 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4991 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4992 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
|
4993 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4994 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4995 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4996 { |
4997 char_u *file_str = NULL; | |
2652 | 4998 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4999 |
5000 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
5001 { | |
5002 beep_flush(); | |
5003 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
5004 } | |
5005 if (xp->xp_context == EXPAND_NOTHING) | |
5006 { | |
5007 /* Caller can use the character as a normal char instead */ | |
5008 return EXPAND_NOTHING; | |
5009 } | |
5010 | |
5011 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5012 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5013 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5014 if (file_str == NULL) |
5015 return EXPAND_UNSUCCESSFUL; | |
5016 | |
2652 | 5017 if (p_wic) |
5018 options += WILD_ICASE; | |
5019 | |
7 | 5020 /* find all files that match the description */ |
2652 | 5021 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5022 { |
5023 *matchcount = 0; | |
5024 *matches = NULL; | |
5025 } | |
5026 vim_free(file_str); | |
5027 | |
5028 return EXPAND_OK; | |
5029 } | |
5030 | |
5031 #ifdef FEAT_MULTI_LANG | |
5032 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5033 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5034 * 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
|
5035 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5036 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5037 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5038 |
5039 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5040 cleanup_help_tags(int num_file, char_u **file) |
7 | 5041 { |
5042 int i, j; | |
5043 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5044 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5045 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5046 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5047 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
|
5048 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5049 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5050 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5051 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5052 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5053 *p = NUL; |
7 | 5054 |
5055 for (i = 0; i < num_file; ++i) | |
5056 { | |
5057 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
|
5058 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5059 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5060 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5061 { |
5062 /* Sorting on priority means the same item in another language may | |
5063 * be anywhere. Search all items for a match up to the "@en". */ | |
5064 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
|
5065 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
|
5066 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5067 break; |
5068 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5069 /* item only exists with @en, remove it */ |
7 | 5070 file[i][len] = NUL; |
5071 } | |
5072 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5073 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5074 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5075 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
|
5076 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5077 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5078 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5079 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5080 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
|
5081 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5082 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5083 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5084 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5085 } |
7 | 5086 } |
5087 #endif | |
5088 | |
5089 /* | |
5090 * Do the expansion based on xp->xp_context and "pat". | |
5091 */ | |
5092 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5093 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5094 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5095 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5096 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5097 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5098 int options) /* EW_ flags */ |
7 | 5099 { |
5100 #ifdef FEAT_CMDL_COMPL | |
5101 regmatch_T regmatch; | |
5102 #endif | |
5103 int ret; | |
5104 int flags; | |
5105 | |
5106 flags = EW_DIR; /* include directories */ | |
5107 if (options & WILD_LIST_NOTFOUND) | |
5108 flags |= EW_NOTFOUND; | |
5109 if (options & WILD_ADD_SLASH) | |
5110 flags |= EW_ADDSLASH; | |
5111 if (options & WILD_KEEP_ALL) | |
5112 flags |= EW_KEEPALL; | |
5113 if (options & WILD_SILENT) | |
5114 flags |= EW_SILENT; | |
6659 | 5115 if (options & WILD_ALLLINKS) |
5116 flags |= EW_ALLLINKS; | |
7 | 5117 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5118 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5119 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5120 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5121 { |
5122 /* | |
5123 * Expand file or directory names. | |
5124 */ | |
5125 int free_pat = FALSE; | |
5126 int i; | |
5127 | |
5128 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5129 * space */ | |
5130 if (xp->xp_backslash != XP_BS_NONE) | |
5131 { | |
5132 free_pat = TRUE; | |
5133 pat = vim_strsave(pat); | |
5134 for (i = 0; pat[i]; ++i) | |
5135 if (pat[i] == '\\') | |
5136 { | |
5137 if (xp->xp_backslash == XP_BS_THREE | |
5138 && pat[i + 1] == '\\' | |
5139 && pat[i + 2] == '\\' | |
5140 && pat[i + 3] == ' ') | |
1621 | 5141 STRMOVE(pat + i, pat + i + 3); |
7 | 5142 if (xp->xp_backslash == XP_BS_ONE |
5143 && pat[i + 1] == ' ') | |
1621 | 5144 STRMOVE(pat + i, pat + i + 1); |
7 | 5145 } |
5146 } | |
5147 | |
5148 if (xp->xp_context == EXPAND_FILES) | |
5149 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5150 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
|
5151 flags |= (EW_FILE | EW_PATH); |
7 | 5152 else |
5153 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5154 if (options & WILD_ICASE) |
5155 flags |= EW_ICASE; | |
5156 | |
2016 | 5157 /* Expand wildcards, supporting %:h and the like. */ |
5158 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5159 if (free_pat) |
5160 vim_free(pat); | |
5161 return ret; | |
5162 } | |
5163 | |
5164 *file = (char_u **)""; | |
5165 *num_file = 0; | |
5166 if (xp->xp_context == EXPAND_HELP) | |
5167 { | |
1696 | 5168 /* With an empty argument we would get all the help tags, which is |
5169 * very slow. Get matches for "help" instead. */ | |
5170 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5171 num_file, file, FALSE) == OK) | |
7 | 5172 { |
5173 #ifdef FEAT_MULTI_LANG | |
5174 cleanup_help_tags(*num_file, *file); | |
5175 #endif | |
5176 return OK; | |
5177 } | |
5178 return FAIL; | |
5179 } | |
5180 | |
5181 #ifndef FEAT_CMDL_COMPL | |
5182 return FAIL; | |
5183 #else | |
716 | 5184 if (xp->xp_context == EXPAND_SHELLCMD) |
5185 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5186 if (xp->xp_context == EXPAND_OLD_SETTING) |
5187 return ExpandOldSetting(num_file, file); | |
5188 if (xp->xp_context == EXPAND_BUFFERS) | |
5189 return ExpandBufnames(pat, num_file, file, options); | |
5190 if (xp->xp_context == EXPAND_TAGS | |
5191 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5192 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5193 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5194 { |
5195 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5196 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
|
5197 directories); |
2929 | 5198 } |
7 | 5199 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5200 { |
3106 | 5201 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5202 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5203 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5204 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5205 { |
5206 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5207 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5208 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5209 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5210 { |
5211 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
|
5212 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5213 } |
407 | 5214 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5215 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5216 return ExpandUserList(xp, num_file, file); |
407 | 5217 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5218 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5219 return ExpandPackAddDir(pat, num_file, file); |
7 | 5220 |
5221 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5222 if (regmatch.regprog == NULL) | |
5223 return FAIL; | |
5224 | |
5225 /* set ignore-case according to p_ic, p_scs and pat */ | |
5226 regmatch.rm_ic = ignorecase(pat); | |
5227 | |
5228 if (xp->xp_context == EXPAND_SETTINGS | |
5229 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5230 ret = ExpandSettings(xp, ®match, num_file, file); | |
5231 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5232 ret = ExpandMappings(®match, num_file, file); | |
5233 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5234 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5235 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5236 # endif | |
5237 else | |
5238 { | |
5239 static struct expgen | |
5240 { | |
5241 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5242 char_u *((*func)(expand_T *, int)); |
7 | 5243 int ic; |
2849 | 5244 int escaped; |
7 | 5245 } tab[] = |
5246 { | |
2849 | 5247 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5248 {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
|
5249 {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
|
5250 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5251 #ifdef FEAT_CMDHIST |
5252 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5253 #endif | |
7 | 5254 #ifdef FEAT_USR_CMDS |
2849 | 5255 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5256 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5257 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5258 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5259 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5260 #endif |
5261 #ifdef FEAT_EVAL | |
2849 | 5262 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5263 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5264 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5265 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5266 #endif |
5267 #ifdef FEAT_MENU | |
2849 | 5268 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5269 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5270 #endif |
5271 #ifdef FEAT_SYN_HL | |
2849 | 5272 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5273 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5274 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5275 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5276 #endif |
2849 | 5277 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5278 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5279 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5280 #ifdef FEAT_CSCOPE |
2849 | 5281 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5282 #endif |
1868 | 5283 #ifdef FEAT_SIGNS |
2849 | 5284 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5285 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5286 #ifdef FEAT_PROFILE |
2849 | 5287 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5288 #endif |
7 | 5289 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5290 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5291 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5292 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5293 #endif | |
5294 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5295 {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
|
5296 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5297 }; |
5298 int i; | |
5299 | |
5300 /* | |
5301 * Find a context in the table and call the ExpandGeneric() with the | |
5302 * right function to do the expansion. | |
5303 */ | |
5304 ret = FAIL; | |
1880 | 5305 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5306 if (xp->xp_context == tab[i].context) |
5307 { | |
5308 if (tab[i].ic) | |
5309 regmatch.rm_ic = TRUE; | |
2849 | 5310 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5311 tab[i].func, tab[i].escaped); |
7 | 5312 break; |
5313 } | |
5314 } | |
5315 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5316 vim_regfree(regmatch.regprog); |
7 | 5317 |
5318 return ret; | |
5319 #endif /* FEAT_CMDL_COMPL */ | |
5320 } | |
5321 | |
5322 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5323 /* | |
5324 * Expand a list of names. | |
5325 * | |
5326 * Generic function for command line completion. It calls a function to | |
5327 * obtain strings, one by one. The strings are matched against a regexp | |
5328 * program. Matching strings are copied into an array, which is returned. | |
5329 * | |
5330 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5331 */ | |
5332 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5333 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5334 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5335 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5336 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5337 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5338 char_u *((*func)(expand_T *, int)), |
7 | 5339 /* 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
|
5340 int escaped) |
7 | 5341 { |
5342 int i; | |
5343 int count = 0; | |
480 | 5344 int round; |
7 | 5345 char_u *str; |
5346 | |
5347 /* do this loop twice: | |
480 | 5348 * round == 0: count the number of matching names |
5349 * round == 1: copy the matching names into allocated memory | |
7 | 5350 */ |
480 | 5351 for (round = 0; round <= 1; ++round) |
7 | 5352 { |
5353 for (i = 0; ; ++i) | |
5354 { | |
5355 str = (*func)(xp, i); | |
5356 if (str == NULL) /* end of list */ | |
5357 break; | |
5358 if (*str == NUL) /* skip empty strings */ | |
5359 continue; | |
5360 | |
5361 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5362 { | |
480 | 5363 if (round) |
7 | 5364 { |
2849 | 5365 if (escaped) |
5366 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5367 else | |
5368 str = vim_strsave(str); | |
7 | 5369 (*file)[count] = str; |
5370 #ifdef FEAT_MENU | |
5371 if (func == get_menu_names && str != NULL) | |
5372 { | |
5373 /* test for separator added by get_menu_names() */ | |
5374 str += STRLEN(str) - 1; | |
5375 if (*str == '\001') | |
5376 *str = '.'; | |
5377 } | |
5378 #endif | |
5379 } | |
5380 ++count; | |
5381 } | |
5382 } | |
480 | 5383 if (round == 0) |
7 | 5384 { |
5385 if (count == 0) | |
5386 return OK; | |
5387 *num_file = count; | |
5388 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5389 if (*file == NULL) | |
5390 { | |
5391 *file = (char_u **)""; | |
5392 return FAIL; | |
5393 } | |
5394 count = 0; | |
5395 } | |
5396 } | |
480 | 5397 |
828 | 5398 /* Sort the results. Keep menu's in the specified order. */ |
5399 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5400 { |
5401 if (xp->xp_context == EXPAND_EXPRESSION | |
5402 || xp->xp_context == EXPAND_FUNCTIONS | |
5403 || xp->xp_context == EXPAND_USER_FUNC) | |
5404 /* <SNR> functions should be sorted to the end. */ | |
5405 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5406 sort_func_compare); | |
5407 else | |
5408 sort_strings(*file, *num_file); | |
5409 } | |
480 | 5410 |
1322 | 5411 #ifdef FEAT_CMDL_COMPL |
5412 /* Reset the variables used for special highlight names expansion, so that | |
5413 * they don't show up when getting normal highlight names by ID. */ | |
5414 reset_expand_highlight(); | |
5415 #endif | |
5416 | |
7 | 5417 return OK; |
5418 } | |
5419 | |
716 | 5420 /* |
5421 * Complete a shell command. | |
5422 * Returns FAIL or OK; | |
5423 */ | |
5424 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5425 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5426 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
|
5427 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
|
5428 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
|
5429 int flagsarg) /* EW_ flags */ |
716 | 5430 { |
5431 char_u *pat; | |
5432 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5433 char_u *path = NULL; |
716 | 5434 int mustfree = FALSE; |
5435 garray_T ga; | |
5436 char_u *buf = alloc(MAXPATHL); | |
5437 size_t l; | |
5438 char_u *s, *e; | |
5439 int flags = flagsarg; | |
5440 int ret; | |
6695 | 5441 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5442 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5443 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5444 hash_T hash; |
716 | 5445 |
5446 if (buf == NULL) | |
5447 return FAIL; | |
5448 | |
5449 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5450 * space */ | |
5451 pat = vim_strsave(filepat); | |
5452 for (i = 0; pat[i]; ++i) | |
5453 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5454 STRMOVE(pat + i, pat + i + 1); |
716 | 5455 |
6695 | 5456 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5457 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5458 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
|
5459 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5460 path = (char_u *)"."; |
5461 else | |
2630 | 5462 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5463 /* 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
|
5464 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5465 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5466 if (path == NULL) |
5467 path = (char_u *)""; | |
5468 } | |
716 | 5469 |
5470 /* | |
5471 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5472 * collect them in "ga". When "." is not in $PATH also expand for the |
5473 * current directory, to find "subdir/cmd". | |
716 | 5474 */ |
5475 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
|
5476 hash_init(&found_ht); |
6695 | 5477 for (s = path; ; s = e) |
716 | 5478 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5479 #if defined(MSWIN) |
716 | 5480 e = vim_strchr(s, ';'); |
5481 #else | |
5482 e = vim_strchr(s, ':'); | |
5483 #endif | |
5484 if (e == NULL) | |
5485 e = s + STRLEN(s); | |
5486 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5487 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
|
5488 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5489 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
|
5490 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5491 // 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
|
5492 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
|
5493 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
|
5494 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5495 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
|
5496 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5497 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
|
5498 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
|
5499 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5500 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5501 // 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
|
5502 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
|
5503 |
716 | 5504 l = e - s; |
5505 if (l > MAXPATHL - 5) | |
5506 break; | |
5507 vim_strncpy(buf, s, l); | |
5508 add_pathsep(buf); | |
5509 l = STRLEN(buf); | |
5510 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5511 | |
5512 /* Expand matches in one directory of $PATH. */ | |
5513 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5514 if (ret == OK) | |
5515 { | |
5516 if (ga_grow(&ga, *num_file) == FAIL) | |
5517 FreeWild(*num_file, *file); | |
5518 else | |
5519 { | |
5520 for (i = 0; i < *num_file; ++i) | |
5521 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5522 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5523 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5524 if (STRLEN(name) > l) |
716 | 5525 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5526 // 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
|
5527 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5528 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
|
5529 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5530 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5531 // 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
|
5532 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5533 ((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
|
5534 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
|
5535 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5536 } |
716 | 5537 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5538 vim_free(name); |
716 | 5539 } |
5540 vim_free(*file); | |
5541 } | |
5542 } | |
5543 if (*e != NUL) | |
5544 ++e; | |
5545 } | |
5546 *file = ga.ga_data; | |
5547 *num_file = ga.ga_len; | |
5548 | |
5549 vim_free(buf); | |
5550 vim_free(pat); | |
5551 if (mustfree) | |
5552 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5553 hash_clear(&found_ht); |
716 | 5554 return OK; |
5555 } | |
5556 | |
5557 | |
7 | 5558 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5559 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5560 * 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
|
5561 * return the result (either a string or a List). |
7 | 5562 */ |
407 | 5563 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5564 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
|
5565 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
|
5566 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5567 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5568 char_u ***file) |
7 | 5569 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5570 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
|
5571 typval_T args[4]; |
7 | 5572 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5573 char_u *pat = NULL; |
407 | 5574 void *ret; |
13 | 5575 struct cmdline_info save_ccline; |
7 | 5576 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5577 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5578 return NULL; |
7 | 5579 *num_file = 0; |
5580 *file = NULL; | |
5581 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5582 if (ccline.cmdbuff != NULL) |
1518 | 5583 { |
5584 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5585 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5586 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5587 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5588 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
|
5589 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5590 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
|
5591 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
|
5592 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
|
5593 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
|
5594 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
|
5595 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
|
5596 args[3].v_type = VAR_UNKNOWN; |
7 | 5597 |
13 | 5598 /* Save the cmdline, we don't know what the function may do. */ |
5599 save_ccline = ccline; | |
5600 ccline.cmdbuff = NULL; | |
5601 ccline.cmdprompt = NULL; | |
7 | 5602 current_SID = xp->xp_scriptID; |
13 | 5603 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5604 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5605 |
5606 ccline = save_ccline; | |
7 | 5607 current_SID = save_current_SID; |
1518 | 5608 if (ccline.cmdbuff != NULL) |
5609 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5610 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5611 vim_free(pat); |
407 | 5612 return ret; |
5613 } | |
5614 | |
5615 /* | |
5616 * Expand names with a function defined by the user. | |
5617 */ | |
5618 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5619 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5620 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5621 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5622 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5623 char_u ***file) |
407 | 5624 { |
5625 char_u *retstr; | |
5626 char_u *s; | |
5627 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
|
5628 int keep; |
407 | 5629 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
|
5630 int skip; |
407 | 5631 |
5632 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5633 if (retstr == NULL) | |
7 | 5634 return FAIL; |
5635 | |
5636 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5637 for (s = retstr; *s != NUL; s = e) |
7 | 5638 { |
5639 e = vim_strchr(s, '\n'); | |
5640 if (e == NULL) | |
5641 e = s + STRLEN(s); | |
5642 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
|
5643 *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
|
5644 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5645 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
|
5646 *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
|
5647 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5648 if (!skip) |
7 | 5649 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5650 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
|
5651 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5652 ((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
|
5653 ++ga.ga_len; |
7 | 5654 } |
5655 | |
5656 if (*e != NUL) | |
5657 ++e; | |
5658 } | |
407 | 5659 vim_free(retstr); |
5660 *file = ga.ga_data; | |
5661 *num_file = ga.ga_len; | |
5662 return OK; | |
5663 } | |
5664 | |
5665 /* | |
5666 * Expand names with a list returned by a function defined by the user. | |
5667 */ | |
5668 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5669 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5670 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5671 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5672 char_u ***file) |
407 | 5673 { |
5674 list_T *retlist; | |
5675 listitem_T *li; | |
5676 garray_T ga; | |
5677 | |
5678 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5679 if (retlist == NULL) | |
5680 return FAIL; | |
5681 | |
5682 ga_init2(&ga, (int)sizeof(char *), 3); | |
5683 /* Loop over the items in the list. */ | |
5684 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5685 { | |
1917 | 5686 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5687 continue; /* Skip non-string items and empty strings */ | |
407 | 5688 |
5689 if (ga_grow(&ga, 1) == FAIL) | |
5690 break; | |
5691 | |
5692 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5693 vim_strsave(li->li_tv.vval.v_string); |
407 | 5694 ++ga.ga_len; |
5695 } | |
5696 list_unref(retlist); | |
5697 | |
7 | 5698 *file = ga.ga_data; |
5699 *num_file = ga.ga_len; | |
5700 return OK; | |
5701 } | |
5702 #endif | |
5703 | |
5704 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5705 * 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
|
5706 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5707 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5708 * 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
|
5709 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 * 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
|
5711 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5712 * "dirnames" is an array with one or more directory names. |
7 | 5713 */ |
5714 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5715 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5716 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5717 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5718 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5719 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5720 char *dirnames[]) |
7 | 5721 { |
5722 char_u *s; | |
5723 char_u *e; | |
5873 | 5724 char_u *match; |
7 | 5725 garray_T ga; |
2929 | 5726 int i; |
5727 int pat_len; | |
7 | 5728 |
5729 *num_file = 0; | |
5730 *file = NULL; | |
2931 | 5731 pat_len = (int)STRLEN(pat); |
2929 | 5732 ga_init2(&ga, (int)sizeof(char *), 10); |
5733 | |
5734 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5735 { |
2929 | 5736 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5737 if (s == NULL) | |
5738 { | |
5739 ga_clear_strings(&ga); | |
5740 return FAIL; | |
5741 } | |
5742 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5743 globpath(p_rtp, s, &ga, 0); |
2929 | 5744 vim_free(s); |
5873 | 5745 } |
5746 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5747 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5748 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
|
5749 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5750 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
|
5751 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5752 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5753 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5754 return FAIL; |
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 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
|
5757 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5758 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5759 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5760 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5761 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5762 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5763 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
|
5764 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5765 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
|
5766 if (s == NULL) |
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 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5769 return FAIL; |
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 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
|
5772 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5773 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5774 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5775 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5776 |
5873 | 5777 for (i = 0; i < ga.ga_len; ++i) |
5778 { | |
5779 match = ((char_u **)ga.ga_data)[i]; | |
5780 s = match; | |
5781 e = s + STRLEN(s); | |
5782 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5783 { |
5873 | 5784 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5785 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5786 if (s < match || vim_ispathsep(*s)) |
5787 break; | |
5788 ++s; | |
5789 *e = NUL; | |
5790 mch_memmove(match, s, e - s + 1); | |
7 | 5791 } |
5792 } | |
5873 | 5793 |
2929 | 5794 if (ga.ga_len == 0) |
3628 | 5795 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5796 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5797 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5798 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5799 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5800 |
7 | 5801 *file = ga.ga_data; |
5802 *num_file = ga.ga_len; | |
5803 return OK; | |
5804 } | |
5805 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5806 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5807 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5808 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5809 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5810 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5811 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 char_u ***file) |
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 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5817 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5818 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5819 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5820 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5821 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5822 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5823 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5824 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 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
|
5827 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5828 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5830 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5832 return FAIL; |
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 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
|
5835 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 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
|
5839 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 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
|
5841 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5842 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5843 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
|
5844 } |
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 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5847 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5849 /* 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
|
5850 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5851 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5852 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5853 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5854 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5855 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5856 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5857 |
7 | 5858 #endif |
5859 | |
5860 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5861 /* | |
5862 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5863 * Adds the matches to "ga". Caller must init "ga". |
7 | 5864 */ |
5873 | 5865 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5866 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5867 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5868 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5869 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5870 int expand_options) |
7 | 5871 { |
5872 expand_T xpc; | |
5873 char_u *buf; | |
5874 int i; | |
5875 int num_p; | |
5876 char_u **p; | |
5877 | |
5878 buf = alloc(MAXPATHL); | |
5879 if (buf == NULL) | |
5873 | 5880 return; |
7 | 5881 |
632 | 5882 ExpandInit(&xpc); |
7 | 5883 xpc.xp_context = EXPAND_FILES; |
632 | 5884 |
7 | 5885 /* Loop over all entries in {path}. */ |
5886 while (*path != NUL) | |
5887 { | |
5888 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5889 copy_option_part(&path, buf, MAXPATHL, ","); | |
5890 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5891 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5892 # 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
|
5893 /* 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
|
5894 * 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
|
5895 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
|
5896 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5897 # else |
7 | 5898 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
|
5899 # endif |
7 | 5900 STRCAT(buf, file); |
1754 | 5901 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5902 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5903 { |
1754 | 5904 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5905 |
5906 if (ga_grow(ga, num_p) == OK) | |
7 | 5907 { |
5908 for (i = 0; i < num_p; ++i) | |
5909 { | |
5873 | 5910 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5911 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5912 ++ga->ga_len; |
7 | 5913 } |
5914 } | |
5873 | 5915 |
7 | 5916 FreeWild(num_p, p); |
5917 } | |
5918 } | |
5919 } | |
5920 | |
5921 vim_free(buf); | |
5922 } | |
5923 | |
5924 #endif | |
5925 | |
5926 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5927 | |
5928 /********************************* | |
5929 * Command line history stuff * | |
5930 *********************************/ | |
5931 | |
5932 /* | |
5933 * Translate a history character to the associated type number. | |
5934 */ | |
5935 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5936 hist_char2type(int c) |
7 | 5937 { |
5938 if (c == ':') | |
5939 return HIST_CMD; | |
5940 if (c == '=') | |
5941 return HIST_EXPR; | |
5942 if (c == '@') | |
5943 return HIST_INPUT; | |
5944 if (c == '>') | |
5945 return HIST_DEBUG; | |
5946 return HIST_SEARCH; /* must be '?' or '/' */ | |
5947 } | |
5948 | |
5949 /* | |
5950 * Table of history names. | |
5951 * These names are used in :history and various hist...() functions. | |
5952 * It is sufficient to give the significant prefix of a history name. | |
5953 */ | |
5954 | |
5955 static char *(history_names[]) = | |
5956 { | |
5957 "cmd", | |
5958 "search", | |
5959 "expr", | |
5960 "input", | |
5961 "debug", | |
5962 NULL | |
5963 }; | |
5964 | |
3503 | 5965 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5966 /* | |
5967 * Function given to ExpandGeneric() to obtain the possible first | |
5968 * arguments of the ":history command. | |
5969 */ | |
5970 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5971 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5972 { |
5973 static char_u compl[2] = { NUL, NUL }; | |
5974 char *short_names = ":=@>?/"; | |
3529 | 5975 int short_names_count = (int)STRLEN(short_names); |
3503 | 5976 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5977 | |
5978 if (idx < short_names_count) | |
5979 { | |
5980 compl[0] = (char_u)short_names[idx]; | |
5981 return compl; | |
5982 } | |
5983 if (idx < short_names_count + history_name_count) | |
5984 return (char_u *)history_names[idx - short_names_count]; | |
5985 if (idx == short_names_count + history_name_count) | |
5986 return (char_u *)"all"; | |
5987 return NULL; | |
5988 } | |
5989 #endif | |
5990 | |
7 | 5991 /* |
5992 * init_history() - Initialize the command line history. | |
5993 * Also used to re-allocate the history when the size changes. | |
5994 */ | |
356 | 5995 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5996 init_history(void) |
7 | 5997 { |
5998 int newlen; /* new length of history table */ | |
5999 histentry_T *temp; | |
6000 int i; | |
6001 int j; | |
6002 int type; | |
6003 | |
6004 /* | |
6005 * If size of history table changed, reallocate it | |
6006 */ | |
6007 newlen = (int)p_hi; | |
6008 if (newlen != hislen) /* history length changed */ | |
6009 { | |
6010 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6011 { | |
6012 if (newlen) | |
6013 { | |
6014 temp = (histentry_T *)lalloc( | |
6015 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6016 if (temp == NULL) /* out of memory! */ | |
6017 { | |
6018 if (type == 0) /* first one: just keep the old length */ | |
6019 { | |
6020 newlen = hislen; | |
6021 break; | |
6022 } | |
6023 /* Already changed one table, now we can only have zero | |
6024 * length for all tables. */ | |
6025 newlen = 0; | |
6026 type = -1; | |
6027 continue; | |
6028 } | |
6029 } | |
6030 else | |
6031 temp = NULL; | |
6032 if (newlen == 0 || temp != NULL) | |
6033 { | |
6034 if (hisidx[type] < 0) /* there are no entries yet */ | |
6035 { | |
6036 for (i = 0; i < newlen; ++i) | |
4258 | 6037 clear_hist_entry(&temp[i]); |
7 | 6038 } |
6039 else if (newlen > hislen) /* array becomes bigger */ | |
6040 { | |
6041 for (i = 0; i <= hisidx[type]; ++i) | |
6042 temp[i] = history[type][i]; | |
6043 j = i; | |
6044 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6045 clear_hist_entry(&temp[i]); |
7 | 6046 for ( ; j < hislen; ++i, ++j) |
6047 temp[i] = history[type][j]; | |
6048 } | |
6049 else /* array becomes smaller or 0 */ | |
6050 { | |
6051 j = hisidx[type]; | |
6052 for (i = newlen - 1; ; --i) | |
6053 { | |
6054 if (i >= 0) /* copy newest entries */ | |
6055 temp[i] = history[type][j]; | |
6056 else /* remove older entries */ | |
6057 vim_free(history[type][j].hisstr); | |
6058 if (--j < 0) | |
6059 j = hislen - 1; | |
6060 if (j == hisidx[type]) | |
6061 break; | |
6062 } | |
6063 hisidx[type] = newlen - 1; | |
6064 } | |
6065 vim_free(history[type]); | |
6066 history[type] = temp; | |
6067 } | |
6068 } | |
6069 hislen = newlen; | |
6070 } | |
6071 } | |
6072 | |
4258 | 6073 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6074 clear_hist_entry(histentry_T *hisptr) |
4258 | 6075 { |
6076 hisptr->hisnum = 0; | |
6077 hisptr->viminfo = FALSE; | |
6078 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6079 hisptr->time_set = 0; |
4258 | 6080 } |
6081 | |
7 | 6082 /* |
6083 * Check if command line 'str' is already in history. | |
6084 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6085 */ | |
6086 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6087 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6088 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6089 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6090 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
|
6091 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6092 int writing) /* ignore entries read from viminfo */ |
7 | 6093 { |
6094 int i; | |
6095 int last_i = -1; | |
2986 | 6096 char_u *p; |
7 | 6097 |
6098 if (hisidx[type] < 0) | |
6099 return FALSE; | |
6100 i = hisidx[type]; | |
6101 do | |
6102 { | |
6103 if (history[type][i].hisstr == NULL) | |
6104 return FALSE; | |
2986 | 6105 |
6106 /* For search history, check that the separator character matches as | |
6107 * well. */ | |
6108 p = history[type][i].hisstr; | |
6109 if (STRCMP(str, p) == 0 | |
4285 | 6110 && !(writing && history[type][i].viminfo) |
2986 | 6111 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6112 { |
6113 if (!move_to_front) | |
6114 return TRUE; | |
6115 last_i = i; | |
6116 break; | |
6117 } | |
6118 if (--i < 0) | |
6119 i = hislen - 1; | |
6120 } while (i != hisidx[type]); | |
6121 | |
6122 if (last_i >= 0) | |
6123 { | |
6124 str = history[type][i].hisstr; | |
6125 while (i != hisidx[type]) | |
6126 { | |
6127 if (++i >= hislen) | |
6128 i = 0; | |
6129 history[type][last_i] = history[type][i]; | |
6130 last_i = i; | |
6131 } | |
4258 | 6132 history[type][i].hisnum = ++hisnum[type]; |
6133 history[type][i].viminfo = FALSE; | |
7 | 6134 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6135 history[type][i].time_set = vim_time(); |
7 | 6136 return TRUE; |
6137 } | |
6138 return FALSE; | |
6139 } | |
6140 | |
6141 /* | |
6142 * Convert history name (from table above) to its HIST_ equivalent. | |
6143 * When "name" is empty, return "cmd" history. | |
6144 * Returns -1 for unknown history name. | |
6145 */ | |
6146 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6147 get_histtype(char_u *name) |
7 | 6148 { |
6149 int i; | |
6150 int len = (int)STRLEN(name); | |
6151 | |
6152 /* No argument: use current history. */ | |
6153 if (len == 0) | |
6154 return hist_char2type(ccline.cmdfirstc); | |
6155 | |
6156 for (i = 0; history_names[i] != NULL; ++i) | |
6157 if (STRNICMP(name, history_names[i], len) == 0) | |
6158 return i; | |
6159 | |
6160 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6161 return hist_char2type(name[0]); | |
6162 | |
6163 return -1; | |
6164 } | |
6165 | |
6166 static int last_maptick = -1; /* last seen maptick */ | |
6167 | |
6168 /* | |
6169 * Add the given string to the given history. If the string is already in the | |
6170 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6171 * values. | |
6172 */ | |
6173 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6174 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6175 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6176 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6177 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
|
6178 int sep) /* separator character used (search hist) */ |
7 | 6179 { |
6180 histentry_T *hisptr; | |
6181 int len; | |
6182 | |
6183 if (hislen == 0) /* no history */ | |
6184 return; | |
6185 | |
5467 | 6186 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6187 return; | |
6188 | |
7 | 6189 /* |
6190 * Searches inside the same mapping overwrite each other, so that only | |
6191 * the last line is kept. Be careful not to remove a line that was moved | |
6192 * down, only lines that were added. | |
6193 */ | |
6194 if (histype == HIST_SEARCH && in_map) | |
6195 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6196 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6197 { |
6198 /* Current line is from the same mapping, remove it */ | |
6199 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6200 vim_free(hisptr->hisstr); | |
4258 | 6201 clear_hist_entry(hisptr); |
7 | 6202 --hisnum[histype]; |
6203 if (--hisidx[HIST_SEARCH] < 0) | |
6204 hisidx[HIST_SEARCH] = hislen - 1; | |
6205 } | |
6206 last_maptick = -1; | |
6207 } | |
4285 | 6208 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6209 { |
6210 if (++hisidx[histype] == hislen) | |
6211 hisidx[histype] = 0; | |
6212 hisptr = &history[histype][hisidx[histype]]; | |
6213 vim_free(hisptr->hisstr); | |
6214 | |
6215 /* Store the separator after the NUL of the string. */ | |
835 | 6216 len = (int)STRLEN(new_entry); |
7 | 6217 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6218 if (hisptr->hisstr != NULL) | |
6219 hisptr->hisstr[len + 1] = sep; | |
6220 | |
6221 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6222 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6223 hisptr->time_set = vim_time(); |
7 | 6224 if (histype == HIST_SEARCH && in_map) |
6225 last_maptick = maptick; | |
6226 } | |
6227 } | |
6228 | |
6229 #if defined(FEAT_EVAL) || defined(PROTO) | |
6230 | |
6231 /* | |
6232 * Get identifier of newest history entry. | |
6233 * "histype" may be one of the HIST_ values. | |
6234 */ | |
6235 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6236 get_history_idx(int histype) |
7 | 6237 { |
6238 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6239 || hisidx[histype] < 0) | |
6240 return -1; | |
6241 | |
6242 return history[histype][hisidx[histype]].hisnum; | |
6243 } | |
6244 | |
531 | 6245 /* |
7 | 6246 * Calculate history index from a number: |
6247 * num > 0: seen as identifying number of a history entry | |
6248 * num < 0: relative position in history wrt newest entry | |
6249 * "histype" may be one of the HIST_ values. | |
6250 */ | |
6251 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6252 calc_hist_idx(int histype, int num) |
7 | 6253 { |
6254 int i; | |
6255 histentry_T *hist; | |
6256 int wrapped = FALSE; | |
6257 | |
6258 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6259 || (i = hisidx[histype]) < 0 || num == 0) | |
6260 return -1; | |
6261 | |
6262 hist = history[histype]; | |
6263 if (num > 0) | |
6264 { | |
6265 while (hist[i].hisnum > num) | |
6266 if (--i < 0) | |
6267 { | |
6268 if (wrapped) | |
6269 break; | |
6270 i += hislen; | |
6271 wrapped = TRUE; | |
6272 } | |
6273 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6274 return i; | |
6275 } | |
6276 else if (-num <= hislen) | |
6277 { | |
6278 i += num + 1; | |
6279 if (i < 0) | |
6280 i += hislen; | |
6281 if (hist[i].hisstr != NULL) | |
6282 return i; | |
6283 } | |
6284 return -1; | |
6285 } | |
6286 | |
6287 /* | |
6288 * Get a history entry by its index. | |
6289 * "histype" may be one of the HIST_ values. | |
6290 */ | |
6291 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6292 get_history_entry(int histype, int idx) |
7 | 6293 { |
6294 idx = calc_hist_idx(histype, idx); | |
6295 if (idx >= 0) | |
6296 return history[histype][idx].hisstr; | |
6297 else | |
6298 return (char_u *)""; | |
6299 } | |
6300 | |
6301 /* | |
6302 * Clear all entries of a history. | |
6303 * "histype" may be one of the HIST_ values. | |
6304 */ | |
6305 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6306 clr_history(int histype) |
7 | 6307 { |
6308 int i; | |
6309 histentry_T *hisptr; | |
6310 | |
6311 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6312 { | |
6313 hisptr = history[histype]; | |
6314 for (i = hislen; i--;) | |
6315 { | |
6316 vim_free(hisptr->hisstr); | |
4258 | 6317 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6318 hisptr++; |
7 | 6319 } |
6320 hisidx[histype] = -1; /* mark history as cleared */ | |
6321 hisnum[histype] = 0; /* reset identifier counter */ | |
6322 return OK; | |
6323 } | |
6324 return FAIL; | |
6325 } | |
6326 | |
6327 /* | |
6328 * Remove all entries matching {str} from a history. | |
6329 * "histype" may be one of the HIST_ values. | |
6330 */ | |
6331 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6332 del_history_entry(int histype, char_u *str) |
7 | 6333 { |
6334 regmatch_T regmatch; | |
6335 histentry_T *hisptr; | |
6336 int idx; | |
6337 int i; | |
6338 int last; | |
6339 int found = FALSE; | |
6340 | |
6341 regmatch.regprog = NULL; | |
6342 regmatch.rm_ic = FALSE; /* always match case */ | |
6343 if (hislen != 0 | |
6344 && histype >= 0 | |
6345 && histype < HIST_COUNT | |
6346 && *str != NUL | |
6347 && (idx = hisidx[histype]) >= 0 | |
6348 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6349 != NULL) | |
6350 { | |
6351 i = last = idx; | |
6352 do | |
6353 { | |
6354 hisptr = &history[histype][i]; | |
6355 if (hisptr->hisstr == NULL) | |
6356 break; | |
6357 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6358 { | |
6359 found = TRUE; | |
6360 vim_free(hisptr->hisstr); | |
4258 | 6361 clear_hist_entry(hisptr); |
7 | 6362 } |
6363 else | |
6364 { | |
6365 if (i != last) | |
6366 { | |
6367 history[histype][last] = *hisptr; | |
4258 | 6368 clear_hist_entry(hisptr); |
7 | 6369 } |
6370 if (--last < 0) | |
6371 last += hislen; | |
6372 } | |
6373 if (--i < 0) | |
6374 i += hislen; | |
6375 } while (i != idx); | |
6376 if (history[histype][idx].hisstr == NULL) | |
6377 hisidx[histype] = -1; | |
6378 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6379 vim_regfree(regmatch.regprog); |
7 | 6380 return found; |
6381 } | |
6382 | |
6383 /* | |
6384 * Remove an indexed entry from a history. | |
6385 * "histype" may be one of the HIST_ values. | |
6386 */ | |
6387 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6388 del_history_idx(int histype, int idx) |
7 | 6389 { |
6390 int i, j; | |
6391 | |
6392 i = calc_hist_idx(histype, idx); | |
6393 if (i < 0) | |
6394 return FALSE; | |
6395 idx = hisidx[histype]; | |
6396 vim_free(history[histype][i].hisstr); | |
6397 | |
6398 /* When deleting the last added search string in a mapping, reset | |
6399 * last_maptick, so that the last added search string isn't deleted again. | |
6400 */ | |
6401 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6402 last_maptick = -1; | |
6403 | |
6404 while (i != idx) | |
6405 { | |
6406 j = (i + 1) % hislen; | |
6407 history[histype][i] = history[histype][j]; | |
6408 i = j; | |
6409 } | |
4258 | 6410 clear_hist_entry(&history[histype][i]); |
7 | 6411 if (--i < 0) |
6412 i += hislen; | |
6413 hisidx[histype] = i; | |
6414 return TRUE; | |
6415 } | |
6416 | |
6417 #endif /* FEAT_EVAL */ | |
6418 | |
6419 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6420 /* | |
6421 * Very specific function to remove the value in ":set key=val" from the | |
6422 * history. | |
6423 */ | |
6424 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6425 remove_key_from_history(void) |
7 | 6426 { |
6427 char_u *p; | |
6428 int i; | |
6429 | |
6430 i = hisidx[HIST_CMD]; | |
6431 if (i < 0) | |
6432 return; | |
6433 p = history[HIST_CMD][i].hisstr; | |
6434 if (p != NULL) | |
6435 for ( ; *p; ++p) | |
6436 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6437 { | |
6438 p = vim_strchr(p + 3, '='); | |
6439 if (p == NULL) | |
6440 break; | |
6441 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6442 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6443 if (p[i] == '\\' && p[i + 1]) |
6444 ++i; | |
1621 | 6445 STRMOVE(p, p + i); |
7 | 6446 --p; |
6447 } | |
6448 } | |
6449 #endif | |
6450 | |
6451 #endif /* FEAT_CMDHIST */ | |
6452 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6453 #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
|
6454 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6455 * Get pointer to the command line info to use. cmdline_paste() may clear |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6456 * 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
|
6457 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6463 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 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
|
6466 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6469 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6470 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6471 #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
|
6472 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 * 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
|
6474 * 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
|
6475 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6478 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 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
|
6481 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 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
|
6485 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6486 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6487 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6488 * 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
|
6489 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6490 * 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
|
6491 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 get_cmdline_pos(void) |
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 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
|
6497 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6498 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6500 return p->cmdpos; |
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 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6503 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6504 * 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
|
6505 * 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
|
6506 * 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
|
6507 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6509 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6510 int pos) |
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 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
|
6513 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6514 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6515 return 1; |
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 /* 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
|
6518 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6519 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6521 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6522 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6524 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6525 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6526 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6527 #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
|
6528 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6529 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 * 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
|
6532 * Returns NUL when something is wrong. |
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 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6535 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6536 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6537 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
|
6538 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6539 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6541 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6542 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6543 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6544 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6545 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6546 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6547 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6548 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6549 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6550 |
7 | 6551 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6552 /* | |
6553 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6554 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6555 * Returns OK if parsed successfully, otherwise FAIL. | |
6556 */ | |
6557 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6558 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6559 { |
6560 int len; | |
6561 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6562 varnumber_T num; |
7 | 6563 |
6564 *str = skipwhite(*str); | |
6565 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6566 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6567 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6568 *str += len; |
6569 *num1 = (int)num; | |
6570 first = TRUE; | |
6571 } | |
6572 *str = skipwhite(*str); | |
6573 if (**str == ',') /* parse "to" part of range */ | |
6574 { | |
6575 *str = skipwhite(*str + 1); | |
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 if (len > 0) |
6578 { | |
6579 *num2 = (int)num; | |
6580 *str = skipwhite(*str + len); | |
6581 } | |
6582 else if (!first) /* no number given at all */ | |
6583 return FAIL; | |
6584 } | |
6585 else if (first) /* only one number given */ | |
6586 *num2 = *num1; | |
6587 return OK; | |
6588 } | |
6589 #endif | |
6590 | |
6591 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6592 /* | |
6593 * :history command - print a history | |
6594 */ | |
6595 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6596 ex_history(exarg_T *eap) |
7 | 6597 { |
6598 histentry_T *hist; | |
6599 int histype1 = HIST_CMD; | |
6600 int histype2 = HIST_CMD; | |
6601 int hisidx1 = 1; | |
6602 int hisidx2 = -1; | |
6603 int idx; | |
6604 int i, j, k; | |
6605 char_u *end; | |
6606 char_u *arg = eap->arg; | |
6607 | |
6608 if (hislen == 0) | |
6609 { | |
6610 MSG(_("'history' option is zero")); | |
6611 return; | |
6612 } | |
6613 | |
6614 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6615 { | |
6616 end = arg; | |
6617 while (ASCII_ISALPHA(*end) | |
6618 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6619 end++; | |
6620 i = *end; | |
6621 *end = NUL; | |
6622 histype1 = get_histtype(arg); | |
6623 if (histype1 == -1) | |
6624 { | |
1853 | 6625 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6626 { |
6627 histype1 = 0; | |
6628 histype2 = HIST_COUNT-1; | |
6629 } | |
6630 else | |
6631 { | |
6632 *end = i; | |
6633 EMSG(_(e_trailing)); | |
6634 return; | |
6635 } | |
6636 } | |
6637 else | |
6638 histype2 = histype1; | |
6639 *end = i; | |
6640 } | |
6641 else | |
6642 end = arg; | |
6643 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6644 { | |
6645 EMSG(_(e_trailing)); | |
6646 return; | |
6647 } | |
6648 | |
6649 for (; !got_int && histype1 <= histype2; ++histype1) | |
6650 { | |
6651 STRCPY(IObuff, "\n # "); | |
6652 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6653 MSG_PUTS_TITLE(IObuff); | |
6654 idx = hisidx[histype1]; | |
6655 hist = history[histype1]; | |
6656 j = hisidx1; | |
6657 k = hisidx2; | |
6658 if (j < 0) | |
6659 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6660 if (k < 0) | |
6661 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6662 if (idx >= 0 && j <= k) | |
6663 for (i = idx + 1; !got_int; ++i) | |
6664 { | |
6665 if (i == hislen) | |
6666 i = 0; | |
6667 if (hist[i].hisstr != NULL | |
6668 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6669 { | |
6670 msg_putchar('\n'); | |
6671 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6672 hist[i].hisnum); | |
6673 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6674 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6675 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6676 else |
6677 STRCAT(IObuff, hist[i].hisstr); | |
6678 msg_outtrans(IObuff); | |
6679 out_flush(); | |
6680 } | |
6681 if (i == idx) | |
6682 break; | |
6683 } | |
6684 } | |
6685 } | |
6686 #endif | |
6687 | |
6688 #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
|
6689 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6690 * 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
|
6691 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6692 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
|
6693 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6694 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
|
6695 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6696 static int viminfo_add_at_front = FALSE; |
6697 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6698 static int hist_type2char(int type, int use_question); |
7 | 6699 |
6700 /* | |
6701 * Translate a history type number to the associated character. | |
6702 */ | |
6703 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6704 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6705 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6706 int use_question) /* use '?' instead of '/' */ |
7 | 6707 { |
6708 if (type == HIST_CMD) | |
6709 return ':'; | |
6710 if (type == HIST_SEARCH) | |
6711 { | |
6712 if (use_question) | |
6713 return '?'; | |
6714 else | |
6715 return '/'; | |
6716 } | |
6717 if (type == HIST_EXPR) | |
6718 return '='; | |
6719 return '@'; | |
6720 } | |
6721 | |
6722 /* | |
6723 * Prepare for reading the history from the viminfo file. | |
6724 * This allocates history arrays to store the read history lines. | |
6725 */ | |
6726 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6727 prepare_viminfo_history(int asklen, int writing) |
7 | 6728 { |
6729 int i; | |
6730 int num; | |
6731 int type; | |
6732 int len; | |
6733 | |
6734 init_history(); | |
4285 | 6735 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6736 if (asklen > hislen) |
6737 asklen = hislen; | |
6738 | |
6739 for (type = 0; type < HIST_COUNT; ++type) | |
6740 { | |
4258 | 6741 /* Count the number of empty spaces in the history list. Entries read |
6742 * from viminfo previously are also considered empty. If there are | |
6743 * more spaces available than we request, then fill them up. */ | |
7 | 6744 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6745 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6746 num++; |
6747 len = asklen; | |
6748 if (num > len) | |
6749 len = num; | |
6750 if (len <= 0) | |
6751 viminfo_history[type] = NULL; | |
6752 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6753 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6754 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6755 if (viminfo_history[type] == NULL) |
6756 len = 0; | |
6757 viminfo_hislen[type] = len; | |
6758 viminfo_hisidx[type] = 0; | |
6759 } | |
6760 } | |
6761 | |
6762 /* | |
6763 * Accept a line from the viminfo, store it in the history array when it's | |
6764 * new. | |
6765 */ | |
6766 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6767 read_viminfo_history(vir_T *virp, int writing) |
7 | 6768 { |
6769 int type; | |
6770 long_u len; | |
6771 char_u *val; | |
6772 char_u *p; | |
6773 | |
6774 type = hist_char2type(virp->vir_line[0]); | |
6775 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6776 { | |
6777 val = viminfo_readstring(virp, 1, TRUE); | |
6778 if (val != NULL && *val != NUL) | |
6779 { | |
3316 | 6780 int sep = (*val == ' ' ? NUL : *val); |
6781 | |
7 | 6782 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6783 viminfo_add_at_front, sep, writing)) |
7 | 6784 { |
6785 /* Need to re-allocate to append the separator byte. */ | |
6786 len = STRLEN(val); | |
6787 p = lalloc(len + 2, TRUE); | |
6788 if (p != NULL) | |
6789 { | |
6790 if (type == HIST_SEARCH) | |
6791 { | |
6792 /* Search entry: Move the separator from the first | |
6793 * column to after the NUL. */ | |
6794 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6795 p[len] = sep; |
7 | 6796 } |
6797 else | |
6798 { | |
6799 /* Not a search entry: No separator in the viminfo | |
6800 * file, add a NUL separator. */ | |
6801 mch_memmove(p, val, (size_t)len + 1); | |
6802 p[len + 1] = NUL; | |
6803 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6804 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
|
6805 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
|
6806 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
|
6807 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
|
6808 viminfo_hisidx[type]++; |
7 | 6809 } |
6810 } | |
6811 } | |
6812 vim_free(val); | |
6813 } | |
6814 return viminfo_readline(virp); | |
6815 } | |
6816 | |
4285 | 6817 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 * 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
|
6819 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6820 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6821 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6823 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6824 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6830 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
|
6831 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6832 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6834 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6835 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6836 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6837 || (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
|
6838 || 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
|
6839 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6841 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6842 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6843 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6844 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
|
6845 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6846 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6849 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
|
6850 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6851 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 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
|
6855 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6856 /* 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
|
6857 * 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
|
6858 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
|
6859 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6862 && (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
|
6863 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6864 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6865 break; |
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 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6868 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6869 if (!overwrite) |
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 /* 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
|
6872 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6873 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6874 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6875 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6876 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6877 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6878 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6879 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
|
6880 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6881 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6882 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
|
6883 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6885 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
|
6886 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 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
|
6888 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6889 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6890 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6891 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6892 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6893 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6894 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6895 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6896 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 * 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
|
6898 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 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
|
6928 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 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
|
6931 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 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
|
6933 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 idx = hislen - 1; |
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 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 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
|
6939 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 idx %= hislen; |
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 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 #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
|
6946 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 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
|
6951 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 if (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
|
6956 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
|
6957 return 0; |
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 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6962 * 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
|
6963 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6965 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 merge_history(int type) |
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 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 /* 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
|
6975 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 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
|
6977 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
|
6978 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
|
6979 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6982 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6983 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6984 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
|
6985 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
|
6986 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 tot_hist[len++] = &history[type][i]; |
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 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 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
|
6993 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6996 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6997 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6999 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7000 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 new_hist[i].hisnum = ++hisnum[type]; |
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 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7005 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7007 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
|
7008 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7009 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7010 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
|
7011 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
|
7012 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7013 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7014 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7015 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7016 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7017 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7018 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 /* |
4285 | 7020 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7021 */ | |
7 | 7022 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7023 finish_viminfo_history(vir_T *virp) |
7 | 7024 { |
7025 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7026 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7027 |
7028 for (type = 0; type < HIST_COUNT; ++type) | |
7029 { | |
7030 if (history[type] == NULL) | |
4283 | 7031 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7032 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7033 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7034 merge_history(type); |
7 | 7035 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7036 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7037 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7038 VIM_CLEAR(viminfo_history[type]); |
4327 | 7039 viminfo_hisidx[type] = 0; |
7 | 7040 } |
7041 } | |
7042 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7043 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7044 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7045 * 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
|
7046 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7047 * 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
|
7048 */ |
7 | 7049 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7050 write_viminfo_history(FILE *fp, int merge) |
7 | 7051 { |
7052 int i; | |
7053 int type; | |
7054 int num_saved; | |
4283 | 7055 int round; |
7 | 7056 |
7057 init_history(); | |
7058 if (hislen == 0) | |
7059 return; | |
7060 for (type = 0; type < HIST_COUNT; ++type) | |
7061 { | |
7062 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7063 if (num_saved == 0) | |
7064 continue; | |
7065 if (num_saved < 0) /* Use default */ | |
7066 num_saved = hislen; | |
7067 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7068 type == HIST_CMD ? _("Command Line") : | |
7069 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7070 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7071 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7072 _("Debug Line")); |
7 | 7073 if (num_saved > hislen) |
7074 num_saved = hislen; | |
4283 | 7075 |
7076 /* | |
7077 * Merge typed and viminfo history: | |
7078 * round 1: history of typed commands. | |
7079 * round 2: history from recently read viminfo. | |
7080 */ | |
7081 for (round = 1; round <= 2; ++round) | |
7082 { | |
4307 | 7083 if (round == 1) |
7084 /* start at newest entry, somewhere in the list */ | |
7085 i = hisidx[type]; | |
7086 else if (viminfo_hisidx[type] > 0) | |
7087 /* start at newest entry, first in the list */ | |
7088 i = 0; | |
7089 else | |
7090 /* empty list */ | |
7091 i = -1; | |
4283 | 7092 if (i >= 0) |
7093 while (num_saved > 0 | |
7094 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7095 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7096 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7097 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7098 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7099 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7100 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7101 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7102 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7103 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7104 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7105 else |
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 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7108 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7109 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7110 : viminfo_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 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7113 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7114 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7115 || !history[type][i].viminfo)) |
7 | 7116 { |
4283 | 7117 --num_saved; |
7118 fputc(hist_type2char(type, TRUE), fp); | |
7119 /* For the search history: put the separator in the | |
7120 * second column; use a space if there isn't one. */ | |
7121 if (type == HIST_SEARCH) | |
7122 { | |
7123 c = p[STRLEN(p) + 1]; | |
7124 putc(c == NUL ? ' ' : c, fp); | |
7125 } | |
7126 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7127 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7128 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7129 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7130 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7131 /* 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
|
7132 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7133 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7134 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7135 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7136 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7137 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
|
7138 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7139 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7140 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7141 } |
7 | 7142 } |
4283 | 7143 if (round == 1) |
7144 { | |
7145 /* Decrement index, loop around and stop when back at | |
7146 * the start. */ | |
7147 if (--i < 0) | |
7148 i = hislen - 1; | |
7149 if (i == hisidx[type]) | |
7150 break; | |
7151 } | |
7152 else | |
7153 { | |
7154 /* Increment index. Stop at the end in the while. */ | |
7155 ++i; | |
7156 } | |
7 | 7157 } |
4283 | 7158 } |
4285 | 7159 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7160 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7161 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
|
7162 VIM_CLEAR(viminfo_history[type]); |
4311 | 7163 viminfo_hisidx[type] = 0; |
7 | 7164 } |
7165 } | |
7166 #endif /* FEAT_VIMINFO */ | |
7167 | |
7168 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7169 /* | |
7170 * Write a character at the current cursor+offset position. | |
7171 * It is directly written into the command buffer block. | |
7172 */ | |
7173 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7174 cmd_pchar(int c, int offset) |
7 | 7175 { |
7176 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7177 { | |
7178 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7179 return; | |
7180 } | |
7181 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7182 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7183 } | |
7184 | |
7185 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7186 cmd_gchar(int offset) |
7 | 7187 { |
7188 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7189 { | |
7190 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7191 return NUL; | |
7192 } | |
7193 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7194 } | |
7195 #endif | |
7196 | |
7197 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7198 /* | |
7199 * Open a window on the current command line and history. Allow editing in | |
7200 * the window. Returns when the window is closed. | |
7201 * Returns: | |
7202 * CR if the command is to be executed | |
7203 * Ctrl_C if it is to be abandoned | |
7204 * K_IGNORE if editing continues | |
7205 */ | |
7206 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
|
7207 open_cmdwin(void) |
7 | 7208 { |
7209 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7210 bufref_T old_curbuf; |
7 | 7211 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7212 bufref_T bufref; |
7 | 7213 win_T *wp; |
7214 int i; | |
7215 linenr_T lnum; | |
7216 int histtype; | |
7217 garray_T winsizes; | |
7218 int save_restart_edit = restart_edit; | |
7219 int save_State = State; | |
7220 int save_exmode = exmode_active; | |
510 | 7221 #ifdef FEAT_RIGHTLEFT |
7222 int save_cmdmsg_rl = cmdmsg_rl; | |
7223 #endif | |
6145 | 7224 #ifdef FEAT_FOLDING |
7225 int save_KeyTyped; | |
7226 #endif | |
7 | 7227 |
7228 /* Can't do this recursively. Can't do it when typing a password. */ | |
7229 if (cmdwin_type != 0 | |
7230 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7231 || cmdline_star > 0 | |
7232 # endif | |
7233 ) | |
7234 { | |
7235 beep_flush(); | |
7236 return K_IGNORE; | |
7237 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7238 set_bufref(&old_curbuf, curbuf); |
7 | 7239 |
7240 /* Save current window sizes. */ | |
7241 win_size_save(&winsizes); | |
7242 | |
7243 /* Don't execute autocommands while creating the window. */ | |
1410 | 7244 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7245 |
683 | 7246 /* don't use a new tab page */ |
7247 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
|
7248 cmdmod.noswapfile = 1; |
683 | 7249 |
7 | 7250 /* Create a window for the command-line buffer. */ |
7251 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7252 { | |
7253 beep_flush(); | |
1410 | 7254 unblock_autocmds(); |
7 | 7255 return K_IGNORE; |
7256 } | |
1831 | 7257 cmdwin_type = get_cmdline_type(); |
7 | 7258 |
7259 /* Create the command-line buffer empty. */ | |
1743 | 7260 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7261 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7262 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7263 curbuf->b_p_ma = TRUE; | |
1865 | 7264 #ifdef FEAT_FOLDING |
7265 curwin->w_p_fen = FALSE; | |
7266 #endif | |
7 | 7267 # ifdef FEAT_RIGHTLEFT |
510 | 7268 curwin->w_p_rl = cmdmsg_rl; |
7269 cmdmsg_rl = FALSE; | |
7 | 7270 # endif |
2583 | 7271 RESET_BINDING(curwin); |
7 | 7272 |
7273 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7274 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7275 /* 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
|
7276 ++curbuf_lock; |
7 | 7277 |
510 | 7278 /* Showing the prompt may have set need_wait_return, reset it. */ |
7279 need_wait_return = FALSE; | |
7280 | |
1831 | 7281 histtype = hist_char2type(cmdwin_type); |
7 | 7282 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7283 { | |
7284 if (p_wc == TAB) | |
7285 { | |
7286 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7287 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7288 } | |
7289 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7290 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7291 --curbuf_lock; |
7 | 7292 |
10 | 7293 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7294 * sets 'textwidth' to 78). */ | |
7295 curbuf->b_p_tw = 0; | |
7296 | |
7 | 7297 /* Fill the buffer with the history. */ |
7298 init_history(); | |
7299 if (hislen > 0) | |
7300 { | |
7301 i = hisidx[histtype]; | |
7302 if (i >= 0) | |
7303 { | |
7304 lnum = 0; | |
7305 do | |
7306 { | |
7307 if (++i == hislen) | |
7308 i = 0; | |
7309 if (history[histtype][i].hisstr != NULL) | |
7310 ml_append(lnum++, history[histtype][i].hisstr, | |
7311 (colnr_T)0, FALSE); | |
7312 } | |
7313 while (i != hisidx[histtype]); | |
7314 } | |
7315 } | |
7316 | |
7317 /* Replace the empty last line with the current command-line and put the | |
7318 * cursor there. */ | |
7319 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7320 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7321 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7322 changed_line_abv_curs(); |
7323 invalidate_botline(); | |
743 | 7324 redraw_later(SOME_VALID); |
7 | 7325 |
7326 /* Save the command line info, can be used recursively. */ | |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7327 save_cmdline(&save_ccline); |
7 | 7328 |
7329 /* No Ex mode here! */ | |
7330 exmode_active = 0; | |
7331 | |
7332 State = NORMAL; | |
7333 # ifdef FEAT_MOUSE | |
7334 setmouse(); | |
7335 # endif | |
7336 | |
7337 /* 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
|
7338 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7339 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7340 stuffcharReadbuff(K_NOP); | |
7 | 7341 |
7342 i = RedrawingDisabled; | |
7343 RedrawingDisabled = 0; | |
7344 | |
7345 /* | |
7346 * Call the main loop until <CR> or CTRL-C is typed. | |
7347 */ | |
7348 cmdwin_result = 0; | |
168 | 7349 main_loop(TRUE, FALSE); |
7 | 7350 |
7351 RedrawingDisabled = i; | |
7352 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7353 # ifdef FEAT_FOLDING |
6145 | 7354 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7355 # endif |
6145 | 7356 |
7 | 7357 /* 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
|
7358 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7359 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7360 # ifdef FEAT_FOLDING |
6145 | 7361 /* Restore KeyTyped in case it is modified by autocommands */ |
7362 KeyTyped = save_KeyTyped; | |
7 | 7363 # endif |
7364 | |
1214 | 7365 /* Restore the command line info. */ |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7366 restore_cmdline(&save_ccline); |
7 | 7367 cmdwin_type = 0; |
7368 | |
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 } |