Mercurial > vim
annotate src/ex_getln.c @ 14848:45d8aa272dbe v8.1.0436
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
commit https://github.com/vim/vim/commit/ee91c33570008aefd2d62b8f88b22db751acacbe
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 25 22:27:35 2018 +0200
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Problem: Can get the text of inputsecret() with getcmdline(). (Tommy Allen)
Solution: Don't return the text.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 25 Sep 2018 22:30:06 +0200 |
parents | 7379bc1c3498 |
children | 3b72808fbb0d |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
1718 | 47 /* The current cmdline_info. It is initialized in getcmdline() and after that |
48 * used by other functions. When invoking getcmdline() recursively it needs | |
49 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
50 * TODO: make it local to getcmdline() and pass it around. */ | |
51 static struct cmdline_info ccline; | |
7 | 52 |
53 static int cmd_showtail; /* Only show path tail in lists ? */ | |
54 | |
55 #ifdef FEAT_EVAL | |
56 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
57 #endif | |
58 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
60 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
62 |
7 | 63 #ifdef FEAT_CMDHIST |
64 typedef struct hist_entry | |
65 { | |
66 int hisnum; /* identifying number */ | |
4258 | 67 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 68 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
69 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 70 } histentry_T; |
71 | |
72 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
73 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
74 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
75 /* identifying (unique) number of newest history entry */ | |
76 static int hislen = 0; /* actual length of history tables */ | |
77 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
80 static int in_history(int, char_u *, int, int, int); |
7 | 81 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
82 static int calc_hist_idx(int histype, int num); |
7 | 83 # endif |
84 #endif | |
85 | |
86 #ifdef FEAT_RIGHTLEFT | |
87 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
88 #endif | |
89 | |
90 #ifdef FEAT_FKMAP | |
91 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
92 #endif | |
93 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
117 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
119 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
123 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
129 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
156 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
157 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
159 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
274 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
276 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
279 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
281 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
283 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
285 char_u *end; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 char_u *dummy; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
288 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
289 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
290 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
333 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
337 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
343 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
347 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
350 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
351 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
353 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
354 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
355 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
356 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
357 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
358 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
359 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
360 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
362 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
363 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
364 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
365 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
366 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
368 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
369 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
371 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
372 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
374 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
376 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
377 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
378 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
379 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
380 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
381 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
382 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
383 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 curwin->w_cursor = is_state->search_start; |
14760
fd69edd2c67e
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
391 parse_cmd_address(&ea, &dummy, TRUE); |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
397 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
398 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
401 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
402 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
403 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
404 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
405 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
406 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
407 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
408 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
409 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
410 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
411 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
412 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
413 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
414 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
416 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
430 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
436 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
440 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
441 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
442 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
443 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
444 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
445 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
446 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 validate_cursor(); /* needed for TAB */ |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
448 redraw_all_later(SOME_VALID); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
449 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
|
450 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
|
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; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
464 int found; // do_search() result |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
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 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
473 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
474 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
475 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
476 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
|
477 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
478 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
479 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
|
480 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
481 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 // 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
|
484 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
486 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 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
|
488 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 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
|
491 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
492 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
|
493 // 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
|
494 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
|
495 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
496 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
497 // 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
|
498 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
|
499 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
|
500 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
502 // 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
|
503 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
|
504 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
|
505 && 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
|
506 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
507 // 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
|
508 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
|
509 { |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
510 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 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
|
512 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
|
513 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 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
|
517 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 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
|
519 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 ++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
|
521 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 // 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
|
523 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
|
524 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 ccline.cmdbuff[skiplen + patlen] = NUL; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
530 found = do_search(NULL, firstc == ':' ? '/' : firstc, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
531 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
|
532 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
538 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
|
539 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
541 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
|
542 || 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
|
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 // match outside of address range |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
545 found = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
546 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
|
547 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
548 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 // 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
|
550 if (got_int) |
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 (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
|
553 got_int = FALSE; // don't abandon the command line |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
554 found = 0; |
14503
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 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
|
557 // 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
|
558 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
|
559 } |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
560 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 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
|
562 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
563 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
|
564 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 // 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
|
566 // 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
|
567 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
|
568 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
|
569 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
571 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
573 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
|
574 |
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_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
|
576 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
|
577 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 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
|
584 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
585 // 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
|
586 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
587 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
588 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
589 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
590 ccline.cmdbuff[skiplen + patlen] = NUL; |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
591 if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
592 { |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
593 redraw_all_later(SOME_VALID); |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
594 set_no_hlsearch(TRUE); |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
595 } |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
596 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
597 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
598 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 // 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
|
601 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
|
602 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
|
603 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 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
|
605 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
|
606 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
|
607 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
|
608 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
609 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
610 // end of the pattern, e.g. for ":s/pat/". |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
611 if (ccline.cmdbuff[skiplen + patlen] != NUL) |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
612 curwin->w_cursor = is_state->search_start; |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
613 else if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 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
|
615 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 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
|
619 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 * May adjust 'incsearch' highlighting 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
|
623 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 * 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
|
625 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 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
|
628 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
|
629 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 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
|
631 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
633 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
640 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
641 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
642 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
643 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
644 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
645 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
647 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
648 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
649 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
650 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
652 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
654 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
|
655 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 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
|
657 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
658 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
|
659 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 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
|
661 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
|
662 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 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
|
666 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 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
|
668 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
|
669 // 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
|
670 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
675 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
|
676 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 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
|
678 ++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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 --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
|
686 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
|
687 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 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
|
693 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
694 // 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
|
695 // 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
|
696 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
|
697 (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
|
698 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
699 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
|
700 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
701 // 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
|
702 // 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
|
703 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
|
704 (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
|
705 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 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
|
707 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
709 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
|
710 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
711 (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
|
712 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 (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
|
714 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
715 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
720 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
721 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 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
|
723 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
|
724 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
726 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
727 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
|
728 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
|
729 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
731 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
732 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 * 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
|
734 * 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
|
735 * 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
|
736 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
737 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
738 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
|
739 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
740 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
|
741 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
742 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
743 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
744 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
745 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
746 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
747 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
748 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
749 } |
14503
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 // 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
|
752 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
|
753 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
754 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
|
755 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
|
756 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
757 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
758 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
759 // 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
|
760 // 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
|
761 // 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
|
762 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
|
763 *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
|
764 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
765 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
766 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
|
767 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
|
768 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
769 // 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
|
770 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
771 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
772 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
773 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
774 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
775 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
776 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
777 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
778 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
779 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
780 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
781 /* |
7 | 782 * getcmdline() - accept a command line starting with firstc. |
783 * | |
784 * firstc == ':' get ":" command line. | |
785 * firstc == '/' or '?' get search pattern | |
786 * firstc == '=' get expression | |
787 * firstc == '@' get text for input() function | |
788 * firstc == '>' get text for debug mode | |
789 * firstc == NUL get text for :insert command | |
790 * firstc == -1 like NUL, and break on CTRL-C | |
791 * | |
792 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
793 * command line. | |
794 * | |
795 * Careful: getcmdline() can be called recursively! | |
796 * | |
797 * Return pointer to allocated string if there is a commandline, NULL | |
798 * otherwise. | |
799 */ | |
800 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
801 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
802 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
803 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
|
804 int indent) /* indent for inside conditionals */ |
7 | 805 { |
806 int c; | |
807 int i; | |
808 int j; | |
809 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
810 int do_abbr; /* when TRUE check for abbr. */ | |
811 #ifdef FEAT_CMDHIST | |
812 char_u *lookfor = NULL; /* string to match */ | |
813 int hiscnt; /* current history line in use */ | |
814 int histype; /* history type to be used */ | |
815 #endif | |
816 #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
|
817 incsearch_state_T is_state; |
7 | 818 #endif |
819 int did_wild_list = FALSE; /* did wild_list() recently */ | |
820 int wim_index = 0; /* index in wim_flags[] */ | |
821 int res; | |
822 int save_msg_scroll = msg_scroll; | |
823 int save_State = State; /* remember State when called */ | |
824 int some_key_typed = FALSE; /* one of the keys was typed */ | |
825 #ifdef FEAT_MOUSE | |
826 /* mouse drag and release events are ignored, unless they are | |
827 * preceded with a mouse down event */ | |
828 int ignore_drag_release = TRUE; | |
829 #endif | |
830 #ifdef FEAT_EVAL | |
831 int break_ctrl_c = FALSE; | |
832 #endif | |
833 expand_T xpc; | |
834 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
|
835 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 836 /* Everything that may work recursively should save and restore the |
837 * current command line in save_ccline. That includes update_screen(), a | |
838 * custom status line may invoke ":normal". */ | |
839 struct cmdline_info save_ccline; | |
840 #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
|
841 int cmdline_type; |
7 | 842 |
843 #ifdef FEAT_EVAL | |
844 if (firstc == -1) | |
845 { | |
846 firstc = NUL; | |
847 break_ctrl_c = TRUE; | |
848 } | |
849 #endif | |
850 #ifdef FEAT_RIGHTLEFT | |
851 /* start without Hebrew mapping for a command line */ | |
852 if (firstc == ':' || firstc == '=' || firstc == '>') | |
853 cmd_hkmap = 0; | |
854 #endif | |
855 | |
856 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
|
857 |
7 | 858 #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
|
859 init_incsearch_state(&is_state); |
7 | 860 #endif |
861 | |
862 /* | |
863 * set some variables for redrawcmd() | |
864 */ | |
865 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 866 ccline.cmdindent = (firstc > 0 ? indent : 0); |
867 | |
868 /* alloc initial ccline.cmdbuff */ | |
869 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 870 if (ccline.cmdbuff == NULL) |
871 return NULL; /* out of memory */ | |
872 ccline.cmdlen = ccline.cmdpos = 0; | |
873 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
|
874 sb_text_start_cmdline(); |
7 | 875 |
164 | 876 /* autoindent for :insert and :append */ |
877 if (firstc <= 0) | |
878 { | |
6929 | 879 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 880 ccline.cmdbuff[indent] = NUL; |
881 ccline.cmdpos = indent; | |
882 ccline.cmdspos = indent; | |
883 ccline.cmdlen = indent; | |
884 } | |
885 | |
7 | 886 ExpandInit(&xpc); |
1718 | 887 ccline.xpc = &xpc; |
7 | 888 |
889 #ifdef FEAT_RIGHTLEFT | |
890 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
891 && (firstc == '/' || firstc == '?')) | |
892 cmdmsg_rl = TRUE; | |
893 else | |
894 cmdmsg_rl = FALSE; | |
895 #endif | |
896 | |
897 redir_off = TRUE; /* don't redirect the typed command */ | |
898 if (!cmd_silent) | |
899 { | |
900 i = msg_scrolled; | |
901 msg_scrolled = 0; /* avoid wait_return message */ | |
902 gotocmdline(TRUE); | |
903 msg_scrolled += i; | |
904 redrawcmdprompt(); /* draw prompt or indent */ | |
905 set_cmdspos(); | |
906 } | |
907 xpc.xp_context = EXPAND_NOTHING; | |
908 xpc.xp_backslash = XP_BS_NONE; | |
632 | 909 #ifndef BACKSLASH_IN_FILENAME |
910 xpc.xp_shell = FALSE; | |
911 #endif | |
7 | 912 |
531 | 913 #if defined(FEAT_EVAL) |
914 if (ccline.input_fn) | |
915 { | |
916 xpc.xp_context = ccline.xp_context; | |
917 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 918 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 919 xpc.xp_arg = ccline.xp_arg; |
1322 | 920 # endif |
531 | 921 } |
922 #endif | |
923 | |
7 | 924 /* |
925 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
926 * doing ":@0" when register 0 doesn't contain a CR. | |
927 */ | |
928 msg_scroll = FALSE; | |
929 | |
930 State = CMDLINE; | |
931 | |
932 if (firstc == '/' || firstc == '?' || firstc == '@') | |
933 { | |
934 /* Use ":lmap" mappings for search pattern and input(). */ | |
935 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
936 b_im_ptr = &curbuf->b_p_iminsert; | |
937 else | |
938 b_im_ptr = &curbuf->b_p_imsearch; | |
939 if (*b_im_ptr == B_IMODE_LMAP) | |
940 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
941 #ifdef HAVE_INPUT_METHOD |
7 | 942 im_set_active(*b_im_ptr == B_IMODE_IM); |
943 #endif | |
944 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
945 #ifdef HAVE_INPUT_METHOD |
7 | 946 else if (p_imcmdline) |
947 im_set_active(TRUE); | |
948 #endif | |
949 | |
950 #ifdef FEAT_MOUSE | |
951 setmouse(); | |
952 #endif | |
953 #ifdef CURSOR_SHAPE | |
954 ui_cursor_shape(); /* may show different cursor shape */ | |
955 #endif | |
956 | |
571 | 957 /* When inside an autocommand for writing "exiting" may be set and |
958 * terminal mode set to cooked. Need to set raw mode here then. */ | |
959 settmode(TMODE_RAW); | |
960 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
961 /* 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
|
962 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
|
963 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
|
964 |
7 | 965 #ifdef FEAT_CMDHIST |
966 init_history(); | |
967 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
968 histype = hist_char2type(firstc); | |
969 #endif | |
970 | |
971 #ifdef FEAT_DIGRAPHS | |
1868 | 972 do_digraph(-1); /* init digraph typeahead */ |
7 | 973 #endif |
974 | |
5993 | 975 /* If something above caused an error, reset the flags, we do want to type |
976 * and execute commands. Display may be messed up a bit. */ | |
977 if (did_emsg) | |
978 redrawcmd(); | |
979 did_emsg = FALSE; | |
980 got_int = FALSE; | |
981 | |
7 | 982 /* |
983 * Collect the command string, handling editing keys. | |
984 */ | |
985 for (;;) | |
986 { | |
972 | 987 redir_off = TRUE; /* Don't redirect the typed command. |
988 Repeated, because a ":redir" inside | |
989 completion may switch it on. */ | |
7 | 990 #ifdef USE_ON_FLY_SCROLL |
991 dont_scroll = FALSE; /* allow scrolling here */ | |
992 #endif | |
993 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
994 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
995 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
|
996 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
|
997 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
|
998 |
7 | 999 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 1000 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
1001 /* 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
|
1002 * anything, such as stop completion. */ |
1472 | 1003 do |
1004 { | |
1005 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
|
1006 } while (c == K_IGNORE || c == K_NOP); |
1472 | 1007 |
7 | 1008 if (KeyTyped) |
1009 { | |
1010 some_key_typed = TRUE; | |
1011 #ifdef FEAT_RIGHTLEFT | |
1012 if (cmd_hkmap) | |
1013 c = hkmap(c); | |
1014 # ifdef FEAT_FKMAP | |
1015 if (cmd_fkmap) | |
1016 c = cmdl_fkmap(c); | |
1017 # endif | |
1018 if (cmdmsg_rl && !KeyStuffed) | |
1019 { | |
1020 /* Invert horizontal movements and operations. Only when | |
1021 * typed by the user directly, not when the result of a | |
1022 * mapping. */ | |
1023 switch (c) | |
1024 { | |
1025 case K_RIGHT: c = K_LEFT; break; | |
1026 case K_S_RIGHT: c = K_S_LEFT; break; | |
1027 case K_C_RIGHT: c = K_C_LEFT; break; | |
1028 case K_LEFT: c = K_RIGHT; break; | |
1029 case K_S_LEFT: c = K_S_RIGHT; break; | |
1030 case K_C_LEFT: c = K_C_RIGHT; break; | |
1031 } | |
1032 } | |
1033 #endif | |
1034 } | |
1035 | |
1036 /* | |
1037 * Ignore got_int when CTRL-C was typed here. | |
1038 * Don't ignore it in :global, we really need to break then, e.g., for | |
1039 * ":g/pat/normal /pat" (without the <CR>). | |
1040 * Don't ignore it for the input() function. | |
1041 */ | |
1042 if ((c == Ctrl_C | |
1043 #ifdef UNIX | |
1044 || c == intr_char | |
1045 #endif | |
1046 ) | |
1047 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1048 && firstc != '@' | |
1049 #endif | |
1050 #ifdef FEAT_EVAL | |
1051 && !break_ctrl_c | |
1052 #endif | |
1053 && !global_busy) | |
1054 got_int = FALSE; | |
1055 | |
1056 #ifdef FEAT_CMDHIST | |
1057 /* free old command line when finished moving around in the history | |
1058 * list */ | |
1059 if (lookfor != NULL | |
180 | 1060 && c != K_S_DOWN && c != K_S_UP |
230 | 1061 && c != K_DOWN && c != K_UP |
7 | 1062 && c != K_PAGEDOWN && c != K_PAGEUP |
1063 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1064 && c != K_LEFT && c != K_RIGHT |
7 | 1065 && (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
|
1066 VIM_CLEAR(lookfor); |
7 | 1067 #endif |
1068 | |
1069 /* | |
1718 | 1070 * When there are matching completions to select <S-Tab> works like |
1071 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1072 */ |
1718 | 1073 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1074 c = Ctrl_P; |
1075 | |
1076 #ifdef FEAT_WILDMENU | |
1077 /* Special translations for 'wildmenu' */ | |
1078 if (did_wild_list && p_wmnu) | |
1079 { | |
230 | 1080 if (c == K_LEFT) |
7 | 1081 c = Ctrl_P; |
230 | 1082 else if (c == K_RIGHT) |
7 | 1083 c = Ctrl_N; |
1084 } | |
1085 /* Hitting CR after "emenu Name.": complete submenu */ | |
1086 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1087 && ccline.cmdpos > 1 | |
1088 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1089 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1090 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1091 c = K_DOWN; | |
1092 #endif | |
1093 | |
1094 /* free expanded names when finished walking through matches */ | |
1095 if (xpc.xp_numfiles != -1 | |
1096 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1097 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1098 && c != Ctrl_L) | |
1099 { | |
1100 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1101 did_wild_list = FALSE; | |
1102 #ifdef FEAT_WILDMENU | |
230 | 1103 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1104 #endif |
1105 xpc.xp_context = EXPAND_NOTHING; | |
1106 wim_index = 0; | |
1107 #ifdef FEAT_WILDMENU | |
1108 if (p_wmnu && wild_menu_showing != 0) | |
1109 { | |
1110 int skt = KeyTyped; | |
532 | 1111 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1112 |
1113 if (ccline.input_fn) | |
1114 RedrawingDisabled = 0; | |
7 | 1115 |
1116 if (wild_menu_showing == WM_SCROLLED) | |
1117 { | |
1118 /* Entered command line, move it up */ | |
1119 cmdline_row--; | |
1120 redrawcmd(); | |
1121 } | |
1122 else if (save_p_ls != -1) | |
1123 { | |
1124 /* restore 'laststatus' and 'winminheight' */ | |
1125 p_ls = save_p_ls; | |
1126 p_wmh = save_p_wmh; | |
1127 last_status(FALSE); | |
195 | 1128 save_cmdline(&save_ccline); |
7 | 1129 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1130 restore_cmdline(&save_ccline); |
7 | 1131 redrawcmd(); |
1132 save_p_ls = -1; | |
1133 } | |
1134 else | |
1135 { | |
1136 win_redraw_last_status(topframe); | |
1137 redraw_statuslines(); | |
1138 } | |
532 | 1139 KeyTyped = skt; |
1140 wild_menu_showing = 0; | |
531 | 1141 if (ccline.input_fn) |
1142 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1143 } |
1144 #endif | |
1145 } | |
1146 | |
1147 #ifdef FEAT_WILDMENU | |
1148 /* Special translations for 'wildmenu' */ | |
1149 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1150 { | |
1151 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1152 if (c == K_DOWN && ccline.cmdpos > 0 |
1153 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1154 c = p_wc; |
230 | 1155 else if (c == K_UP) |
7 | 1156 { |
1157 /* Hitting <Up>: Remove one submenu name in front of the | |
1158 * cursor */ | |
1159 int found = FALSE; | |
1160 | |
1161 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1162 i = 0; | |
1163 while (--j > 0) | |
1164 { | |
1165 /* check for start of menu name */ | |
1166 if (ccline.cmdbuff[j] == ' ' | |
1167 && ccline.cmdbuff[j - 1] != '\\') | |
1168 { | |
1169 i = j + 1; | |
1170 break; | |
1171 } | |
1172 /* check for start of submenu name */ | |
1173 if (ccline.cmdbuff[j] == '.' | |
1174 && ccline.cmdbuff[j - 1] != '\\') | |
1175 { | |
1176 if (found) | |
1177 { | |
1178 i = j + 1; | |
1179 break; | |
1180 } | |
1181 else | |
1182 found = TRUE; | |
1183 } | |
1184 } | |
1185 if (i > 0) | |
1186 cmdline_del(i); | |
1187 c = p_wc; | |
1188 xpc.xp_context = EXPAND_NOTHING; | |
1189 } | |
1190 } | |
714 | 1191 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1192 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1193 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1194 { |
1195 char_u upseg[5]; | |
1196 | |
1197 upseg[0] = PATHSEP; | |
1198 upseg[1] = '.'; | |
1199 upseg[2] = '.'; | |
1200 upseg[3] = PATHSEP; | |
1201 upseg[4] = NUL; | |
1202 | |
1318 | 1203 if (c == K_DOWN |
1204 && ccline.cmdpos > 0 | |
1205 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1206 && (ccline.cmdpos < 3 | |
1207 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1208 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1209 { | |
1210 /* go down a directory */ | |
1211 c = p_wc; | |
1212 } | |
230 | 1213 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1214 { |
1215 /* If in a direct ancestor, strip off one ../ to go down */ | |
1216 int found = FALSE; | |
1217 | |
1218 j = ccline.cmdpos; | |
1219 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1220 while (--j > i) | |
1221 { | |
39 | 1222 #ifdef FEAT_MBYTE |
1223 if (has_mbyte) | |
1224 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1225 #endif | |
7 | 1226 if (vim_ispathsep(ccline.cmdbuff[j])) |
1227 { | |
1228 found = TRUE; | |
1229 break; | |
1230 } | |
1231 } | |
1232 if (found | |
1233 && ccline.cmdbuff[j - 1] == '.' | |
1234 && ccline.cmdbuff[j - 2] == '.' | |
1235 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1236 { | |
1237 cmdline_del(j - 2); | |
1238 c = p_wc; | |
1239 } | |
1240 } | |
230 | 1241 else if (c == K_UP) |
7 | 1242 { |
1243 /* go up a directory */ | |
1244 int found = FALSE; | |
1245 | |
1246 j = ccline.cmdpos - 1; | |
1247 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1248 while (--j > i) | |
1249 { | |
1250 #ifdef FEAT_MBYTE | |
1251 if (has_mbyte) | |
1252 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1253 #endif | |
1254 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1255 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1256 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1257 ccline.cmdbuff[j + 1]) == NULL |
7 | 1258 #endif |
1259 ) | |
1260 { | |
1261 if (found) | |
1262 { | |
1263 i = j + 1; | |
1264 break; | |
1265 } | |
1266 else | |
1267 found = TRUE; | |
1268 } | |
1269 } | |
1270 | |
1271 if (!found) | |
1272 j = i; | |
1273 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1274 j += 4; | |
1275 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1276 && j == i) | |
1277 j += 3; | |
1278 else | |
1279 j = 0; | |
1280 if (j > 0) | |
1281 { | |
1282 /* TODO this is only for DOS/UNIX systems - need to put in | |
1283 * machine-specific stuff here and in upseg init */ | |
1284 cmdline_del(j); | |
1285 put_on_cmdline(upseg + 1, 3, FALSE); | |
1286 } | |
1287 else if (ccline.cmdpos > i) | |
1288 cmdline_del(i); | |
3204 | 1289 |
1290 /* Now complete in the new directory. Set KeyTyped in case the | |
1291 * Up key came from a mapping. */ | |
7 | 1292 c = p_wc; |
3204 | 1293 KeyTyped = TRUE; |
7 | 1294 } |
1295 } | |
1296 | |
1297 #endif /* FEAT_WILDMENU */ | |
1298 | |
1299 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1300 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1301 if (c == Ctrl_BSL) | |
1302 { | |
1303 ++no_mapping; | |
1304 ++allow_keys; | |
1389 | 1305 c = plain_vgetc(); |
7 | 1306 --no_mapping; |
1307 --allow_keys; | |
3859 | 1308 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1309 * is in a mapping. */ | |
1310 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1311 || (ccline.cmdfirstc == '=' && KeyTyped) |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1312 #ifdef FEAT_EVAL |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1313 || cmdline_star > 0 |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1314 #endif |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1315 )) |
7 | 1316 { |
1317 vungetc(c); | |
1318 c = Ctrl_BSL; | |
1319 } | |
1320 #ifdef FEAT_EVAL | |
1321 else if (c == 'e') | |
1322 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1323 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1324 int len; |
7 | 1325 |
1326 /* | |
1327 * Replace the command line with the result of an expression. | |
625 | 1328 * Need to save and restore the current command line, to be |
1329 * able to enter a new one... | |
7 | 1330 */ |
1331 if (ccline.cmdpos == ccline.cmdlen) | |
1332 new_cmdpos = 99999; /* keep it at the end */ | |
1333 else | |
1334 new_cmdpos = ccline.cmdpos; | |
95 | 1335 |
1336 save_cmdline(&save_ccline); | |
7 | 1337 c = get_expr_register(); |
95 | 1338 restore_cmdline(&save_ccline); |
7 | 1339 if (c == '=') |
1340 { | |
634 | 1341 /* Need to save and restore ccline. And set "textlock" |
632 | 1342 * to avoid nasty things like going to another buffer when |
1343 * evaluating an expression. */ | |
95 | 1344 save_cmdline(&save_ccline); |
634 | 1345 ++textlock; |
7 | 1346 p = get_expr_line(); |
634 | 1347 --textlock; |
95 | 1348 restore_cmdline(&save_ccline); |
2617 | 1349 |
1350 if (p != NULL) | |
7 | 1351 { |
2617 | 1352 len = (int)STRLEN(p); |
1353 if (realloc_cmdbuff(len + 1) == OK) | |
1354 { | |
1355 ccline.cmdlen = len; | |
1356 STRCPY(ccline.cmdbuff, p); | |
1357 vim_free(p); | |
1358 | |
1359 /* Restore the cursor or use the position set with | |
1360 * set_cmdline_pos(). */ | |
1361 if (new_cmdpos > ccline.cmdlen) | |
1362 ccline.cmdpos = ccline.cmdlen; | |
1363 else | |
1364 ccline.cmdpos = new_cmdpos; | |
1365 | |
1366 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1367 redrawcmd(); | |
1368 goto cmdline_changed; | |
1369 } | |
7 | 1370 } |
1371 } | |
1372 beep_flush(); | |
2636 | 1373 got_int = FALSE; /* don't abandon the command line */ |
1374 did_emsg = FALSE; | |
1375 emsg_on_display = FALSE; | |
1376 redrawcmd(); | |
1377 goto cmdline_not_changed; | |
7 | 1378 } |
1379 #endif | |
1380 else | |
1381 { | |
1382 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1383 restart_edit = 'a'; | |
1384 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1385 in history */ | |
1386 goto returncmd; /* back to Normal mode */ | |
1387 } | |
1388 } | |
1389 | |
1390 #ifdef FEAT_CMDWIN | |
1391 if (c == cedit_key || c == K_CMDWIN) | |
1392 { | |
6211 | 1393 if (ex_normal_busy == 0 && got_int == FALSE) |
1394 { | |
1395 /* | |
1396 * Open a window to edit the command line (and history). | |
1397 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1398 c = open_cmdwin(); |
6211 | 1399 some_key_typed = TRUE; |
1400 } | |
7 | 1401 } |
1402 # ifdef FEAT_DIGRAPHS | |
1403 else | |
1404 # endif | |
1405 #endif | |
1406 #ifdef FEAT_DIGRAPHS | |
1407 c = do_digraph(c); | |
1408 #endif | |
1409 | |
1410 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1411 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1412 { | |
168 | 1413 /* In Ex mode a backslash escapes a newline. */ |
1414 if (exmode_active | |
1415 && c != ESC | |
1318 | 1416 && ccline.cmdpos == ccline.cmdlen |
168 | 1417 && ccline.cmdpos > 0 |
1418 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1419 { | |
1420 if (c == K_KENTER) | |
1421 c = '\n'; | |
1422 } | |
1423 else | |
7 | 1424 { |
168 | 1425 gotesc = FALSE; /* Might have typed ESC previously, don't |
1426 truncate the cmdline now. */ | |
1427 if (ccheck_abbr(c + ABBR_OFF)) | |
1428 goto cmdline_changed; | |
1429 if (!cmd_silent) | |
1430 { | |
1431 windgoto(msg_row, 0); | |
1432 out_flush(); | |
1433 } | |
1434 break; | |
7 | 1435 } |
1436 } | |
1437 | |
1438 /* | |
1439 * Completion for 'wildchar' or 'wildcharm' key. | |
1440 * - hitting <ESC> twice means: abandon command line. | |
1441 * - wildcard expansion is only done when the 'wildchar' key is really | |
1442 * typed, not when it comes from a macro | |
1443 */ | |
1444 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1445 { | |
1446 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1447 { | |
1448 /* if 'wildmode' contains "list" may still need to list */ | |
1449 if (xpc.xp_numfiles > 1 | |
1450 && !did_wild_list | |
1451 && (wim_flags[wim_index] & WIM_LIST)) | |
1452 { | |
1453 (void)showmatches(&xpc, FALSE); | |
1454 redrawcmd(); | |
1455 did_wild_list = TRUE; | |
1456 } | |
1457 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1458 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1459 firstc != '@'); | |
7 | 1460 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1461 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1462 firstc != '@'); | |
7 | 1463 else |
1464 res = OK; /* don't insert 'wildchar' now */ | |
1465 } | |
1466 else /* typed p_wc first time */ | |
1467 { | |
1468 wim_index = 0; | |
1469 j = ccline.cmdpos; | |
1470 /* if 'wildmode' first contains "longest", get longest | |
1471 * common part */ | |
1472 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1473 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1474 firstc != '@'); | |
7 | 1475 else |
3961 | 1476 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1477 firstc != '@'); | |
7 | 1478 |
1479 /* if interrupted while completing, behave like it failed */ | |
1480 if (got_int) | |
1481 { | |
1482 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1483 got_int = FALSE; /* don't abandon the command line */ | |
1484 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1485 #ifdef FEAT_WILDMENU | |
1486 xpc.xp_context = EXPAND_NOTHING; | |
1487 #endif | |
1488 goto cmdline_changed; | |
1489 } | |
1490 | |
1491 /* when more than one match, and 'wildmode' first contains | |
1492 * "list", or no change and 'wildmode' contains "longest,list", | |
1493 * list all matches */ | |
1494 if (res == OK && xpc.xp_numfiles > 1) | |
1495 { | |
1496 /* a "longest" that didn't do anything is skipped (but not | |
1497 * "list:longest") */ | |
1498 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1499 wim_index = 1; | |
1500 if ((wim_flags[wim_index] & WIM_LIST) | |
1501 #ifdef FEAT_WILDMENU | |
1502 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1503 #endif | |
1504 ) | |
1505 { | |
1506 if (!(wim_flags[0] & WIM_LONGEST)) | |
1507 { | |
1508 #ifdef FEAT_WILDMENU | |
1509 int p_wmnu_save = p_wmnu; | |
1510 p_wmnu = 0; | |
1511 #endif | |
3961 | 1512 /* remove match */ |
1513 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1514 #ifdef FEAT_WILDMENU |
1515 p_wmnu = p_wmnu_save; | |
1516 #endif | |
1517 } | |
1518 #ifdef FEAT_WILDMENU | |
1519 (void)showmatches(&xpc, p_wmnu | |
1520 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1521 #else | |
1522 (void)showmatches(&xpc, FALSE); | |
1523 #endif | |
1524 redrawcmd(); | |
1525 did_wild_list = TRUE; | |
1526 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1527 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1528 firstc != '@'); | |
7 | 1529 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1530 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1531 firstc != '@'); | |
7 | 1532 } |
1533 else | |
6949 | 1534 vim_beep(BO_WILD); |
7 | 1535 } |
1536 #ifdef FEAT_WILDMENU | |
1537 else if (xpc.xp_numfiles == -1) | |
1538 xpc.xp_context = EXPAND_NOTHING; | |
1539 #endif | |
1540 } | |
1541 if (wim_index < 3) | |
1542 ++wim_index; | |
1543 if (c == ESC) | |
1544 gotesc = TRUE; | |
1545 if (res == OK) | |
1546 goto cmdline_changed; | |
1547 } | |
1548 | |
1549 gotesc = FALSE; | |
1550 | |
1551 /* <S-Tab> goes to last match, in a clumsy way */ | |
1552 if (c == K_S_TAB && KeyTyped) | |
1553 { | |
3961 | 1554 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1555 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1556 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1557 goto cmdline_changed; |
1558 } | |
1559 | |
1560 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1561 c = NL; | |
1562 | |
1563 do_abbr = TRUE; /* default: check for abbreviation */ | |
1564 | |
1565 /* | |
1566 * Big switch for a typed command line character. | |
1567 */ | |
1568 switch (c) | |
1569 { | |
1570 case K_BS: | |
1571 case Ctrl_H: | |
1572 case K_DEL: | |
1573 case K_KDEL: | |
1574 case Ctrl_W: | |
1575 #ifdef FEAT_FKMAP | |
1576 if (cmd_fkmap && c == K_BS) | |
1577 c = K_DEL; | |
1578 #endif | |
1579 if (c == K_KDEL) | |
1580 c = K_DEL; | |
1581 | |
1582 /* | |
1583 * delete current character is the same as backspace on next | |
1584 * character, except at end of line | |
1585 */ | |
1586 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1587 ++ccline.cmdpos; | |
1588 #ifdef FEAT_MBYTE | |
1589 if (has_mbyte && c == K_DEL) | |
1590 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1591 ccline.cmdbuff + ccline.cmdpos); | |
1592 #endif | |
1593 if (ccline.cmdpos > 0) | |
1594 { | |
1595 char_u *p; | |
1596 | |
1597 j = ccline.cmdpos; | |
1598 p = ccline.cmdbuff + j; | |
1599 #ifdef FEAT_MBYTE | |
1600 if (has_mbyte) | |
1601 { | |
1602 p = mb_prevptr(ccline.cmdbuff, p); | |
1603 if (c == Ctrl_W) | |
1604 { | |
1605 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1606 p = mb_prevptr(ccline.cmdbuff, p); | |
1607 i = mb_get_class(p); | |
1608 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1609 p = mb_prevptr(ccline.cmdbuff, p); | |
1610 if (mb_get_class(p) != i) | |
474 | 1611 p += (*mb_ptr2len)(p); |
7 | 1612 } |
1613 } | |
1614 else | |
1615 #endif | |
1616 if (c == Ctrl_W) | |
1617 { | |
1618 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1619 --p; | |
1620 i = vim_iswordc(p[-1]); | |
1621 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1622 && vim_iswordc(p[-1]) == i) | |
1623 --p; | |
1624 } | |
1625 else | |
1626 --p; | |
1627 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1628 ccline.cmdlen -= j - ccline.cmdpos; | |
1629 i = ccline.cmdpos; | |
1630 while (i < ccline.cmdlen) | |
1631 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1632 | |
1633 /* Truncate at the end, required for multi-byte chars. */ | |
1634 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1635 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1636 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1637 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1638 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
|
1639 /* 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
|
1640 * 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
|
1641 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
|
1642 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1643 #endif |
7 | 1644 redrawcmd(); |
1645 } | |
1646 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1647 && ccline.cmdprompt == NULL && indent == 0) | |
1648 { | |
1649 /* In ex and debug mode it doesn't make sense to return. */ | |
1650 if (exmode_active | |
1651 #ifdef FEAT_EVAL | |
1652 || ccline.cmdfirstc == '>' | |
1653 #endif | |
1654 ) | |
1655 goto cmdline_not_changed; | |
1656 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1657 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1658 if (!cmd_silent) |
1659 { | |
1660 #ifdef FEAT_RIGHTLEFT | |
1661 if (cmdmsg_rl) | |
1662 msg_col = Columns; | |
1663 else | |
1664 #endif | |
1665 msg_col = 0; | |
1666 msg_putchar(' '); /* delete ':' */ | |
1667 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1668 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1669 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
|
1670 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
|
1671 #endif |
7 | 1672 redraw_cmdline = TRUE; |
1673 goto returncmd; /* back to cmd mode */ | |
1674 } | |
1675 goto cmdline_changed; | |
1676 | |
1677 case K_INS: | |
1678 case K_KINS: | |
1679 #ifdef FEAT_FKMAP | |
1680 /* if Farsi mode set, we are in reverse insert mode - | |
1681 Do not change the mode */ | |
1682 if (cmd_fkmap) | |
1683 beep_flush(); | |
1684 else | |
1685 #endif | |
1686 ccline.overstrike = !ccline.overstrike; | |
1687 #ifdef CURSOR_SHAPE | |
1688 ui_cursor_shape(); /* may show different cursor shape */ | |
1689 #endif | |
1690 goto cmdline_not_changed; | |
1691 | |
1692 case Ctrl_HAT: | |
782 | 1693 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1694 { |
1695 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1696 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1697 #ifdef HAVE_INPUT_METHOD |
7 | 1698 im_set_active(FALSE); /* Disable input method */ |
1699 #endif | |
1700 if (b_im_ptr != NULL) | |
1701 { | |
1702 if (State & LANGMAP) | |
1703 *b_im_ptr = B_IMODE_LMAP; | |
1704 else | |
1705 *b_im_ptr = B_IMODE_NONE; | |
1706 } | |
1707 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1708 #ifdef HAVE_INPUT_METHOD |
7 | 1709 else |
1710 { | |
1711 /* There are no ":lmap" mappings, toggle IM. When | |
1712 * 'imdisable' is set don't try getting the status, it's | |
1713 * always off. */ | |
1714 if ((p_imdisable && b_im_ptr != NULL) | |
1715 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1716 { | |
1717 im_set_active(FALSE); /* Disable input method */ | |
1718 if (b_im_ptr != NULL) | |
1719 *b_im_ptr = B_IMODE_NONE; | |
1720 } | |
1721 else | |
1722 { | |
1723 im_set_active(TRUE); /* Enable input method */ | |
1724 if (b_im_ptr != NULL) | |
1725 *b_im_ptr = B_IMODE_IM; | |
1726 } | |
1727 } | |
1728 #endif | |
1729 if (b_im_ptr != NULL) | |
1730 { | |
1731 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1732 set_iminsert_global(); | |
1733 else | |
1734 set_imsearch_global(); | |
1735 } | |
1736 #ifdef CURSOR_SHAPE | |
1737 ui_cursor_shape(); /* may show different cursor shape */ | |
1738 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1739 #if defined(FEAT_KEYMAP) |
7 | 1740 /* Show/unshow value of 'keymap' in status lines later. */ |
1741 status_redraw_curbuf(); | |
1742 #endif | |
1743 goto cmdline_not_changed; | |
1744 | |
1745 /* case '@': only in very old vi */ | |
1746 case Ctrl_U: | |
1747 /* delete all characters left of the cursor */ | |
1748 j = ccline.cmdpos; | |
1749 ccline.cmdlen -= j; | |
1750 i = ccline.cmdpos = 0; | |
1751 while (i < ccline.cmdlen) | |
1752 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1753 /* Truncate at the end, required for multi-byte chars. */ | |
1754 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1755 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1756 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
|
1757 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
|
1758 #endif |
7 | 1759 redrawcmd(); |
1760 goto cmdline_changed; | |
1761 | |
1762 #ifdef FEAT_CLIPBOARD | |
1763 case Ctrl_Y: | |
1764 /* Copy the modeless selection, if there is one. */ | |
1765 if (clip_star.state != SELECT_CLEARED) | |
1766 { | |
1767 if (clip_star.state == SELECT_DONE) | |
1768 clip_copy_modeless_selection(TRUE); | |
1769 goto cmdline_not_changed; | |
1770 } | |
1771 break; | |
1772 #endif | |
1773 | |
1774 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1775 case Ctrl_C: | |
571 | 1776 /* In exmode it doesn't make sense to return. Except when |
161 | 1777 * ":normal" runs out of characters. */ |
1778 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1779 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1780 goto cmdline_not_changed; |
1781 | |
1782 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1783 putting it in history */ | |
1784 goto returncmd; /* back to cmd mode */ | |
1785 | |
1786 case Ctrl_R: /* insert register */ | |
1787 #ifdef USE_ON_FLY_SCROLL | |
1788 dont_scroll = TRUE; /* disallow scrolling here */ | |
1789 #endif | |
1790 putcmdline('"', TRUE); | |
1791 ++no_mapping; | |
1389 | 1792 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1793 if (i == Ctrl_O) |
1794 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1795 if (i == Ctrl_R) | |
1389 | 1796 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
|
1797 extra_char = NUL; |
7 | 1798 --no_mapping; |
1799 #ifdef FEAT_EVAL | |
1800 /* | |
1801 * Insert the result of an expression. | |
1802 * Need to save the current command line, to be able to enter | |
1803 * a new one... | |
1804 */ | |
1805 new_cmdpos = -1; | |
1806 if (c == '=') | |
1807 { | |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1808 if (ccline.cmdfirstc == '=' // can't do this recursively |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1809 || cmdline_star > 0) // or when typing a password |
7 | 1810 { |
1811 beep_flush(); | |
1812 c = ESC; | |
1813 } | |
1814 else | |
1815 { | |
95 | 1816 save_cmdline(&save_ccline); |
7 | 1817 c = get_expr_register(); |
95 | 1818 restore_cmdline(&save_ccline); |
7 | 1819 } |
1820 } | |
1821 #endif | |
1822 if (c != ESC) /* use ESC to cancel inserting register */ | |
1823 { | |
1015 | 1824 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1825 |
613 | 1826 #ifdef FEAT_EVAL |
606 | 1827 /* When there was a serious error abort getting the |
1828 * command line. */ | |
1829 if (aborting()) | |
1830 { | |
1831 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1832 putting it in history */ | |
1833 goto returncmd; /* back to cmd mode */ | |
1834 } | |
613 | 1835 #endif |
7 | 1836 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1837 #ifdef FEAT_EVAL | |
1838 if (new_cmdpos >= 0) | |
1839 { | |
1840 /* set_cmdline_pos() was used */ | |
1841 if (new_cmdpos > ccline.cmdlen) | |
1842 ccline.cmdpos = ccline.cmdlen; | |
1843 else | |
1844 ccline.cmdpos = new_cmdpos; | |
1845 } | |
1846 #endif | |
1847 } | |
1848 redrawcmd(); | |
1849 goto cmdline_changed; | |
1850 | |
1851 case Ctrl_D: | |
1852 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1853 break; /* Use ^D as normal char instead */ | |
1854 | |
1855 redrawcmd(); | |
1856 continue; /* don't do incremental search now */ | |
1857 | |
1858 case K_RIGHT: | |
1859 case K_S_RIGHT: | |
1860 case K_C_RIGHT: | |
1861 do | |
1862 { | |
1863 if (ccline.cmdpos >= ccline.cmdlen) | |
1864 break; | |
1865 i = cmdline_charsize(ccline.cmdpos); | |
1866 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1867 break; | |
1868 ccline.cmdspos += i; | |
1869 #ifdef FEAT_MBYTE | |
1870 if (has_mbyte) | |
474 | 1871 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1872 + ccline.cmdpos); |
1873 else | |
1874 #endif | |
1875 ++ccline.cmdpos; | |
1876 } | |
180 | 1877 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1878 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1879 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1880 #ifdef FEAT_MBYTE | |
1881 if (has_mbyte) | |
1882 set_cmdspos_cursor(); | |
1883 #endif | |
1884 goto cmdline_not_changed; | |
1885 | |
1886 case K_LEFT: | |
1887 case K_S_LEFT: | |
1888 case K_C_LEFT: | |
1456 | 1889 if (ccline.cmdpos == 0) |
1890 goto cmdline_not_changed; | |
7 | 1891 do |
1892 { | |
1893 --ccline.cmdpos; | |
1894 #ifdef FEAT_MBYTE | |
1895 if (has_mbyte) /* move to first byte of char */ | |
1896 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1897 ccline.cmdbuff + ccline.cmdpos); | |
1898 #endif | |
1899 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1900 } | |
1456 | 1901 while (ccline.cmdpos > 0 |
1902 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1903 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1904 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1905 #ifdef FEAT_MBYTE | |
1906 if (has_mbyte) | |
1907 set_cmdspos_cursor(); | |
1908 #endif | |
1909 goto cmdline_not_changed; | |
1910 | |
1911 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
|
1912 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1913 goto cmdline_not_changed; |
7 | 1914 |
625 | 1915 #ifdef FEAT_GUI_W32 |
1916 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1917 * cancelled. */ | |
1918 case K_F4: | |
1919 if (mod_mask == MOD_MASK_ALT) | |
1920 { | |
1921 redrawcmd(); /* somehow the cmdline is cleared */ | |
1922 goto cmdline_not_changed; | |
1923 } | |
1924 break; | |
1925 #endif | |
1926 | |
7 | 1927 #ifdef FEAT_MOUSE |
1928 case K_MIDDLEDRAG: | |
1929 case K_MIDDLERELEASE: | |
1930 goto cmdline_not_changed; /* Ignore mouse */ | |
1931 | |
1932 case K_MIDDLEMOUSE: | |
1933 # ifdef FEAT_GUI | |
1934 /* When GUI is active, also paste when 'mouse' is empty */ | |
1935 if (!gui.in_use) | |
1936 # endif | |
1937 if (!mouse_has(MOUSE_COMMAND)) | |
1938 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1939 # ifdef FEAT_CLIPBOARD |
7 | 1940 if (clip_star.available) |
1015 | 1941 cmdline_paste('*', TRUE, TRUE); |
7 | 1942 else |
692 | 1943 # endif |
1015 | 1944 cmdline_paste(0, TRUE, TRUE); |
7 | 1945 redrawcmd(); |
1946 goto cmdline_changed; | |
1947 | |
692 | 1948 # ifdef FEAT_DND |
7 | 1949 case K_DROP: |
1015 | 1950 cmdline_paste('~', TRUE, FALSE); |
7 | 1951 redrawcmd(); |
1952 goto cmdline_changed; | |
692 | 1953 # endif |
7 | 1954 |
1955 case K_LEFTDRAG: | |
1956 case K_LEFTRELEASE: | |
1957 case K_RIGHTDRAG: | |
1958 case K_RIGHTRELEASE: | |
1959 /* Ignore drag and release events when the button-down wasn't | |
1960 * seen before. */ | |
1961 if (ignore_drag_release) | |
1962 goto cmdline_not_changed; | |
1963 /* FALLTHROUGH */ | |
1964 case K_LEFTMOUSE: | |
1965 case K_RIGHTMOUSE: | |
1966 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1967 ignore_drag_release = TRUE; | |
1968 else | |
1969 ignore_drag_release = FALSE; | |
1970 # ifdef FEAT_GUI | |
1971 /* When GUI is active, also move when 'mouse' is empty */ | |
1972 if (!gui.in_use) | |
1973 # endif | |
1974 if (!mouse_has(MOUSE_COMMAND)) | |
1975 goto cmdline_not_changed; /* Ignore mouse */ | |
1976 # ifdef FEAT_CLIPBOARD | |
1977 if (mouse_row < cmdline_row && clip_star.available) | |
1978 { | |
1979 int button, is_click, is_drag; | |
1980 | |
1981 /* | |
1982 * Handle modeless selection. | |
1983 */ | |
1984 button = get_mouse_button(KEY2TERMCAP1(c), | |
1985 &is_click, &is_drag); | |
1986 if (mouse_model_popup() && button == MOUSE_LEFT | |
1987 && (mod_mask & MOD_MASK_SHIFT)) | |
1988 { | |
1989 /* Translate shift-left to right button. */ | |
1990 button = MOUSE_RIGHT; | |
1991 mod_mask &= ~MOD_MASK_SHIFT; | |
1992 } | |
1993 clip_modeless(button, is_click, is_drag); | |
1994 goto cmdline_not_changed; | |
1995 } | |
1996 # endif | |
1997 | |
1998 set_cmdspos(); | |
1999 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
2000 ++ccline.cmdpos) | |
2001 { | |
2002 i = cmdline_charsize(ccline.cmdpos); | |
2003 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
2004 && mouse_col < ccline.cmdspos % Columns + i) | |
2005 break; | |
692 | 2006 # ifdef FEAT_MBYTE |
7 | 2007 if (has_mbyte) |
2008 { | |
2009 /* Count ">" for double-wide char that doesn't fit. */ | |
2010 correct_cmdspos(ccline.cmdpos, i); | |
474 | 2011 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 2012 + ccline.cmdpos) - 1; |
2013 } | |
692 | 2014 # endif |
7 | 2015 ccline.cmdspos += i; |
2016 } | |
2017 goto cmdline_not_changed; | |
2018 | |
2019 /* Mouse scroll wheel: ignored here */ | |
2020 case K_MOUSEDOWN: | |
2021 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2022 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2023 case K_MOUSERIGHT: |
7 | 2024 /* Alternate buttons ignored here */ |
2025 case K_X1MOUSE: | |
2026 case K_X1DRAG: | |
2027 case K_X1RELEASE: | |
2028 case K_X2MOUSE: | |
2029 case K_X2DRAG: | |
2030 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2031 case K_MOUSEMOVE: |
7 | 2032 goto cmdline_not_changed; |
2033 | |
2034 #endif /* FEAT_MOUSE */ | |
2035 | |
2036 #ifdef FEAT_GUI | |
2037 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2038 case K_LEFTRELEASE_NM: | |
2039 goto cmdline_not_changed; | |
2040 | |
2041 case K_VER_SCROLLBAR: | |
540 | 2042 if (msg_scrolled == 0) |
7 | 2043 { |
2044 gui_do_scroll(); | |
2045 redrawcmd(); | |
2046 } | |
2047 goto cmdline_not_changed; | |
2048 | |
2049 case K_HOR_SCROLLBAR: | |
540 | 2050 if (msg_scrolled == 0) |
7 | 2051 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2052 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2053 redrawcmd(); |
2054 } | |
2055 goto cmdline_not_changed; | |
2056 #endif | |
692 | 2057 #ifdef FEAT_GUI_TABLINE |
2058 case K_TABLINE: | |
2059 case K_TABMENU: | |
2060 /* Don't want to change any tabs here. Make sure the same tab | |
2061 * is still selected. */ | |
2062 if (gui_use_tabline()) | |
2063 gui_mch_set_curtab(tabpage_index(curtab)); | |
2064 goto cmdline_not_changed; | |
2065 #endif | |
2066 | |
7 | 2067 case K_SELECT: /* end of Select mode mapping - ignore */ |
2068 goto cmdline_not_changed; | |
2069 | |
2070 case Ctrl_B: /* begin of command line */ | |
2071 case K_HOME: | |
2072 case K_KHOME: | |
2073 case K_S_HOME: | |
2074 case K_C_HOME: | |
2075 ccline.cmdpos = 0; | |
2076 set_cmdspos(); | |
2077 goto cmdline_not_changed; | |
2078 | |
2079 case Ctrl_E: /* end of command line */ | |
2080 case K_END: | |
2081 case K_KEND: | |
2082 case K_S_END: | |
2083 case K_C_END: | |
2084 ccline.cmdpos = ccline.cmdlen; | |
2085 set_cmdspos_cursor(); | |
2086 goto cmdline_not_changed; | |
2087 | |
2088 case Ctrl_A: /* all matches */ | |
3961 | 2089 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2090 break; |
2091 goto cmdline_changed; | |
2092 | |
772 | 2093 case Ctrl_L: |
2094 #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
|
2095 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2096 goto cmdline_not_changed; |
2097 #endif | |
2098 | |
2099 /* completion: longest common part */ | |
3961 | 2100 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2101 break; |
2102 goto cmdline_changed; | |
2103 | |
2104 case Ctrl_N: /* next match */ | |
2105 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2106 if (xpc.xp_numfiles > 0) |
7 | 2107 { |
3961 | 2108 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2109 0, firstc != '@') == FAIL) | |
7 | 2110 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2111 goto cmdline_not_changed; |
7 | 2112 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2113 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2114 /* FALLTHROUGH */ |
7 | 2115 case K_UP: |
2116 case K_DOWN: | |
2117 case K_S_UP: | |
2118 case K_S_DOWN: | |
2119 case K_PAGEUP: | |
2120 case K_KPAGEUP: | |
2121 case K_PAGEDOWN: | |
2122 case K_KPAGEDOWN: | |
2123 if (hislen == 0 || firstc == NUL) /* no history */ | |
2124 goto cmdline_not_changed; | |
2125 | |
2126 i = hiscnt; | |
2127 | |
2128 /* save current command string so it can be restored later */ | |
2129 if (lookfor == NULL) | |
2130 { | |
2131 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2132 goto cmdline_not_changed; | |
2133 lookfor[ccline.cmdpos] = NUL; | |
2134 } | |
2135 | |
2136 j = (int)STRLEN(lookfor); | |
2137 for (;;) | |
2138 { | |
2139 /* one step backwards */ | |
230 | 2140 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2141 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2142 { |
2143 if (hiscnt == hislen) /* first time */ | |
2144 hiscnt = hisidx[histype]; | |
2145 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2146 hiscnt = hislen - 1; | |
2147 else if (hiscnt != hisidx[histype] + 1) | |
2148 --hiscnt; | |
2149 else /* at top of list */ | |
2150 { | |
2151 hiscnt = i; | |
2152 break; | |
2153 } | |
2154 } | |
2155 else /* one step forwards */ | |
2156 { | |
2157 /* on last entry, clear the line */ | |
2158 if (hiscnt == hisidx[histype]) | |
2159 { | |
2160 hiscnt = hislen; | |
2161 break; | |
2162 } | |
2163 | |
2164 /* not on a history line, nothing to do */ | |
2165 if (hiscnt == hislen) | |
2166 break; | |
2167 if (hiscnt == hislen - 1) /* wrap around */ | |
2168 hiscnt = 0; | |
2169 else | |
2170 ++hiscnt; | |
2171 } | |
2172 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2173 { | |
2174 hiscnt = i; | |
2175 break; | |
2176 } | |
230 | 2177 if ((c != K_UP && c != K_DOWN) |
180 | 2178 || hiscnt == i |
7 | 2179 || STRNCMP(history[histype][hiscnt].hisstr, |
2180 lookfor, (size_t)j) == 0) | |
2181 break; | |
2182 } | |
2183 | |
2184 if (hiscnt != i) /* jumped to other entry */ | |
2185 { | |
2186 char_u *p; | |
2187 int len; | |
2188 int old_firstc; | |
2189 | |
2190 vim_free(ccline.cmdbuff); | |
1718 | 2191 xpc.xp_context = EXPAND_NOTHING; |
7 | 2192 if (hiscnt == hislen) |
2193 p = lookfor; /* back to the old one */ | |
2194 else | |
2195 p = history[histype][hiscnt].hisstr; | |
2196 | |
2197 if (histype == HIST_SEARCH | |
2198 && p != lookfor | |
2199 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2200 { | |
2201 /* Correct for the separator character used when | |
2202 * adding the history entry vs the one used now. | |
2203 * First loop: count length. | |
2204 * Second loop: copy the characters. */ | |
2205 for (i = 0; i <= 1; ++i) | |
2206 { | |
2207 len = 0; | |
2208 for (j = 0; p[j] != NUL; ++j) | |
2209 { | |
2210 /* Replace old sep with new sep, unless it is | |
2211 * escaped. */ | |
2212 if (p[j] == old_firstc | |
2213 && (j == 0 || p[j - 1] != '\\')) | |
2214 { | |
2215 if (i > 0) | |
2216 ccline.cmdbuff[len] = firstc; | |
2217 } | |
2218 else | |
2219 { | |
2220 /* Escape new sep, unless it is already | |
2221 * escaped. */ | |
2222 if (p[j] == firstc | |
2223 && (j == 0 || p[j - 1] != '\\')) | |
2224 { | |
2225 if (i > 0) | |
2226 ccline.cmdbuff[len] = '\\'; | |
2227 ++len; | |
2228 } | |
2229 if (i > 0) | |
2230 ccline.cmdbuff[len] = p[j]; | |
2231 } | |
2232 ++len; | |
2233 } | |
2234 if (i == 0) | |
2235 { | |
2236 alloc_cmdbuff(len); | |
2237 if (ccline.cmdbuff == NULL) | |
2238 goto returncmd; | |
2239 } | |
2240 } | |
2241 ccline.cmdbuff[len] = NUL; | |
2242 } | |
2243 else | |
2244 { | |
2245 alloc_cmdbuff((int)STRLEN(p)); | |
2246 if (ccline.cmdbuff == NULL) | |
2247 goto returncmd; | |
2248 STRCPY(ccline.cmdbuff, p); | |
2249 } | |
2250 | |
2251 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2252 redrawcmd(); | |
2253 goto cmdline_changed; | |
2254 } | |
2255 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2256 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2257 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2258 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2259 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2260 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2261 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
|
2262 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
|
2263 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
|
2264 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2265 break; |
7 | 2266 #endif |
2267 | |
2268 case Ctrl_V: | |
2269 case Ctrl_Q: | |
2270 #ifdef FEAT_MOUSE | |
2271 ignore_drag_release = TRUE; | |
2272 #endif | |
2273 putcmdline('^', TRUE); | |
2274 c = get_literal(); /* get next (two) character(s) */ | |
2275 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
|
2276 extra_char = NUL; |
7 | 2277 #ifdef FEAT_MBYTE |
2278 /* may need to remove ^ when composing char was typed */ | |
2279 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2280 { | |
2281 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2282 msg_putchar(' '); | |
2283 cursorcmd(); | |
2284 } | |
2285 #endif | |
2286 break; | |
2287 | |
2288 #ifdef FEAT_DIGRAPHS | |
2289 case Ctrl_K: | |
2290 #ifdef FEAT_MOUSE | |
2291 ignore_drag_release = TRUE; | |
2292 #endif | |
2293 putcmdline('?', TRUE); | |
2294 #ifdef USE_ON_FLY_SCROLL | |
2295 dont_scroll = TRUE; /* disallow scrolling here */ | |
2296 #endif | |
2297 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
|
2298 extra_char = NUL; |
7 | 2299 if (c != NUL) |
2300 break; | |
2301 | |
2302 redrawcmd(); | |
2303 goto cmdline_not_changed; | |
2304 #endif /* FEAT_DIGRAPHS */ | |
2305 | |
2306 #ifdef FEAT_RIGHTLEFT | |
2307 case Ctrl__: /* CTRL-_: switch language mode */ | |
2308 if (!p_ari) | |
2309 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2310 # ifdef FEAT_FKMAP |
7 | 2311 if (p_altkeymap) |
2312 { | |
2313 cmd_fkmap = !cmd_fkmap; | |
2314 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2315 ccline.overstrike = FALSE; | |
2316 } | |
2317 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2318 # endif |
7 | 2319 cmd_hkmap = !cmd_hkmap; |
2320 goto cmdline_not_changed; | |
2321 #endif | |
2322 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2323 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
|
2324 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
|
2325 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
|
2326 |
7 | 2327 default: |
2328 #ifdef UNIX | |
2329 if (c == intr_char) | |
2330 { | |
2331 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2332 putting it in history */ | |
2333 goto returncmd; /* back to Normal mode */ | |
2334 } | |
2335 #endif | |
2336 /* | |
2337 * Normal character with no special meaning. Just set mod_mask | |
2338 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2339 * the string <S-Space>. This should only happen after ^V. | |
2340 */ | |
2341 if (!IS_SPECIAL(c)) | |
2342 mod_mask = 0x0; | |
2343 break; | |
2344 } | |
2345 /* | |
2346 * End of switch on command line character. | |
2347 * We come here if we have a normal character. | |
2348 */ | |
2349 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2350 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2351 #ifdef FEAT_MBYTE |
2352 /* Add ABBR_OFF for characters above 0x100, this is | |
2353 * what check_abbr() expects. */ | |
2354 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2355 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2356 c) || c == Ctrl_RSB)) |
7 | 2357 goto cmdline_changed; |
2358 | |
2359 /* | |
2360 * put the character in the command line | |
2361 */ | |
2362 if (IS_SPECIAL(c) || mod_mask != 0) | |
2363 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2364 else | |
2365 { | |
2366 #ifdef FEAT_MBYTE | |
2367 if (has_mbyte) | |
2368 { | |
2369 j = (*mb_char2bytes)(c, IObuff); | |
2370 IObuff[j] = NUL; /* exclude composing chars */ | |
2371 put_on_cmdline(IObuff, j, TRUE); | |
2372 } | |
2373 else | |
2374 #endif | |
2375 { | |
2376 IObuff[0] = c; | |
2377 put_on_cmdline(IObuff, 1, TRUE); | |
2378 } | |
2379 } | |
2380 goto cmdline_changed; | |
2381 | |
2382 /* | |
2383 * This part implements incremental searches for "/" and "?" | |
2384 * Jump to cmdline_not_changed when a character has been read but the command | |
2385 * line did not change. Then we only search and redraw if something changed in | |
2386 * the past. | |
2387 * Jump to cmdline_changed when the command line did change. | |
2388 * (Sorry for the goto's, I know it is ugly). | |
2389 */ | |
2390 cmdline_not_changed: | |
2391 #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
|
2392 if (!is_state.incsearch_postponed) |
7 | 2393 continue; |
2394 #endif | |
2395 | |
2396 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
|
2397 /* 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
|
2398 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
|
2399 |
7 | 2400 #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
|
2401 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2402 #endif |
2403 | |
2404 #ifdef FEAT_RIGHTLEFT | |
2405 if (cmdmsg_rl | |
2406 # ifdef FEAT_ARABIC | |
534 | 2407 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2408 # endif |
2409 ) | |
2410 /* Always redraw the whole command line to fix shaping and | |
3374 | 2411 * right-left typing. Not efficient, but it works. |
2412 * Do it only when there are no characters left to read | |
2413 * to avoid useless intermediate redraws. */ | |
2414 if (vpeekc() == NUL) | |
2415 redrawcmd(); | |
7 | 2416 #endif |
2417 } | |
2418 | |
2419 returncmd: | |
2420 | |
2421 #ifdef FEAT_RIGHTLEFT | |
2422 cmdmsg_rl = FALSE; | |
2423 #endif | |
2424 | |
2425 #ifdef FEAT_FKMAP | |
2426 cmd_fkmap = 0; | |
2427 #endif | |
2428 | |
2429 ExpandCleanup(&xpc); | |
1718 | 2430 ccline.xpc = NULL; |
7 | 2431 |
2432 #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
|
2433 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2434 #endif |
2435 | |
2436 if (ccline.cmdbuff != NULL) | |
2437 { | |
2438 /* | |
2439 * Put line in history buffer (":" and "=" only when it was typed). | |
2440 */ | |
2441 #ifdef FEAT_CMDHIST | |
2442 if (ccline.cmdlen && firstc != NUL | |
2443 && (some_key_typed || histype == HIST_SEARCH)) | |
2444 { | |
2445 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2446 histype == HIST_SEARCH ? firstc : NUL); | |
2447 if (firstc == ':') | |
2448 { | |
2449 vim_free(new_last_cmdline); | |
2450 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2451 } | |
2452 } | |
2453 #endif | |
2454 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2455 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
|
2456 abandon_cmdline(); |
7 | 2457 } |
2458 | |
2459 /* | |
2460 * If the screen was shifted up, redraw the whole screen (later). | |
2461 * If the line is too long, clear it, so ruler and shown command do | |
2462 * not get printed in the middle of it. | |
2463 */ | |
2464 msg_check(); | |
2465 msg_scroll = save_msg_scroll; | |
2466 redir_off = FALSE; | |
2467 | |
2468 /* When the command line was typed, no need for a wait-return prompt. */ | |
2469 if (some_key_typed) | |
2470 need_wait_return = FALSE; | |
2471 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2472 /* 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
|
2473 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
|
2474 |
7 | 2475 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2476 #ifdef HAVE_INPUT_METHOD |
7 | 2477 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2478 im_save_status(b_im_ptr); | |
2479 im_set_active(FALSE); | |
2480 #endif | |
2481 #ifdef FEAT_MOUSE | |
2482 setmouse(); | |
2483 #endif | |
2484 #ifdef CURSOR_SHAPE | |
2485 ui_cursor_shape(); /* may show different cursor shape */ | |
2486 #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
|
2487 sb_text_end_cmdline(); |
7 | 2488 |
95 | 2489 { |
2490 char_u *p = ccline.cmdbuff; | |
2491 | |
2492 /* Make ccline empty, getcmdline() may try to use it. */ | |
2493 ccline.cmdbuff = NULL; | |
2494 return p; | |
2495 } | |
7 | 2496 } |
2497 | |
2498 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2499 /* | |
2500 * Get a command line with a prompt. | |
2501 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2502 * f_input() when evaluating an expression from CTRL-R =). | |
2503 * Returns the command line in allocated memory, or NULL. | |
2504 */ | |
2505 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2506 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2507 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2508 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2509 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2510 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2511 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2512 { |
2513 char_u *s; | |
2514 struct cmdline_info save_ccline; | |
2515 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
|
2516 int msg_silent_save = msg_silent; |
7 | 2517 |
95 | 2518 save_cmdline(&save_ccline); |
7 | 2519 ccline.cmdprompt = prompt; |
2520 ccline.cmdattr = attr; | |
531 | 2521 # ifdef FEAT_EVAL |
2522 ccline.xp_context = xp_context; | |
2523 ccline.xp_arg = xp_arg; | |
2524 ccline.input_fn = (firstc == '@'); | |
2525 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2526 msg_silent = 0; |
7 | 2527 s = getcmdline(firstc, 1L, 0); |
95 | 2528 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2529 msg_silent = msg_silent_save; |
3020 | 2530 /* Restore msg_col, the prompt from input() may have changed it. |
2531 * But only if called recursively and the commandline is therefore being | |
2532 * restored to an old one; if not, the input() prompt stays on the screen, | |
2533 * so we need its modified msg_col left intact. */ | |
2534 if (ccline.cmdbuff != NULL) | |
2535 msg_col = msg_col_save; | |
7 | 2536 |
2537 return s; | |
2538 } | |
2539 #endif | |
2540 | |
632 | 2541 /* |
634 | 2542 * Return TRUE when the text must not be changed and we can't switch to |
2543 * another window or buffer. Used when editing the command line, evaluating | |
2544 * 'balloonexpr', etc. | |
632 | 2545 */ |
2546 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2547 text_locked(void) |
632 | 2548 { |
2549 #ifdef FEAT_CMDWIN | |
2550 if (cmdwin_type != 0) | |
2551 return TRUE; | |
2552 #endif | |
634 | 2553 return textlock != 0; |
632 | 2554 } |
2555 | |
2556 /* | |
2557 * Give an error message for a command that isn't allowed while the cmdline | |
2558 * window is open or editing the cmdline in another way. | |
2559 */ | |
2560 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2561 text_locked_msg(void) |
632 | 2562 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2563 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2564 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2565 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2566 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2567 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2568 { |
632 | 2569 #ifdef FEAT_CMDWIN |
2570 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2571 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2572 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2573 return e_secure; |
632 | 2574 } |
2575 | |
819 | 2576 /* |
1834 | 2577 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2578 * and give an error message. | |
819 | 2579 */ |
2580 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2581 curbuf_locked(void) |
819 | 2582 { |
2583 if (curbuf_lock > 0) | |
2584 { | |
2585 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2586 return TRUE; | |
2587 } | |
1834 | 2588 return allbuf_locked(); |
2589 } | |
2590 | |
2591 /* | |
2592 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2593 * message. | |
2594 */ | |
2595 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2596 allbuf_locked(void) |
1834 | 2597 { |
2598 if (allbuf_lock > 0) | |
2599 { | |
2600 EMSG(_("E811: Not allowed to change buffer information now")); | |
2601 return TRUE; | |
2602 } | |
819 | 2603 return FALSE; |
2604 } | |
2605 | |
7 | 2606 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2607 cmdline_charsize(int idx) |
7 | 2608 { |
2609 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2610 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2611 return 1; | |
2612 #endif | |
2613 return ptr2cells(ccline.cmdbuff + idx); | |
2614 } | |
2615 | |
2616 /* | |
2617 * Compute the offset of the cursor on the command line for the prompt and | |
2618 * indent. | |
2619 */ | |
2620 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2621 set_cmdspos(void) |
7 | 2622 { |
531 | 2623 if (ccline.cmdfirstc != NUL) |
7 | 2624 ccline.cmdspos = 1 + ccline.cmdindent; |
2625 else | |
2626 ccline.cmdspos = 0 + ccline.cmdindent; | |
2627 } | |
2628 | |
2629 /* | |
2630 * Compute the screen position for the cursor on the command line. | |
2631 */ | |
2632 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2633 set_cmdspos_cursor(void) |
7 | 2634 { |
2635 int i, m, c; | |
2636 | |
2637 set_cmdspos(); | |
2638 if (KeyTyped) | |
534 | 2639 { |
7 | 2640 m = Columns * Rows; |
534 | 2641 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2642 m = MAXCOL; | |
2643 } | |
7 | 2644 else |
2645 m = MAXCOL; | |
2646 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2647 { | |
2648 c = cmdline_charsize(i); | |
2649 #ifdef FEAT_MBYTE | |
2650 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2651 if (has_mbyte) | |
2652 correct_cmdspos(i, c); | |
2653 #endif | |
1612 | 2654 /* If the cmdline doesn't fit, show cursor on last visible char. |
2655 * Don't move the cursor itself, so we can still append. */ | |
7 | 2656 if ((ccline.cmdspos += c) >= m) |
2657 { | |
2658 ccline.cmdspos -= c; | |
2659 break; | |
2660 } | |
2661 #ifdef FEAT_MBYTE | |
2662 if (has_mbyte) | |
474 | 2663 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2664 #endif |
2665 } | |
2666 } | |
2667 | |
2668 #ifdef FEAT_MBYTE | |
2669 /* | |
2670 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2671 * character that doesn't fit, so that a ">" must be displayed. | |
2672 */ | |
2673 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2674 correct_cmdspos(int idx, int cells) |
7 | 2675 { |
474 | 2676 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2677 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2678 && ccline.cmdspos % Columns + cells > Columns) | |
2679 ccline.cmdspos++; | |
2680 } | |
2681 #endif | |
2682 | |
2683 /* | |
2684 * Get an Ex command line for the ":" command. | |
2685 */ | |
2686 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2687 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2688 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2689 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2690 int indent) /* indent for inside conditionals */ |
7 | 2691 { |
2692 /* When executing a register, remove ':' that's in front of each line. */ | |
2693 if (exec_from_reg && vpeekc() == ':') | |
2694 (void)vgetc(); | |
2695 return getcmdline(c, 1L, indent); | |
2696 } | |
2697 | |
2698 /* | |
2699 * Get an Ex command line for Ex mode. | |
2700 * In Ex mode we only use the OS supplied line editing features and no | |
2701 * mappings or abbreviations. | |
168 | 2702 * Returns a string in allocated memory or NULL. |
7 | 2703 */ |
2704 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2705 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2706 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2707 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2708 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2709 int indent) /* indent for inside conditionals */ |
7 | 2710 { |
168 | 2711 garray_T line_ga; |
2712 char_u *pend; | |
2713 int startcol = 0; | |
1329 | 2714 int c1 = 0; |
168 | 2715 int escaped = FALSE; /* CTRL-V typed */ |
2716 int vcol = 0; | |
2717 char_u *p; | |
1329 | 2718 int prev_char; |
5966 | 2719 int len; |
7 | 2720 |
2721 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2722 * confuses the system function that computes tabstops. */ | |
2723 cursor_on(); | |
2724 | |
2725 /* always start in column 0; write a newline if necessary */ | |
2726 compute_cmdrow(); | |
168 | 2727 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2728 msg_putchar('\n'); |
168 | 2729 if (promptc == ':') |
7 | 2730 { |
164 | 2731 /* indent that is only displayed, not in the line itself */ |
168 | 2732 if (p_prompt) |
2733 msg_putchar(':'); | |
7 | 2734 while (indent-- > 0) |
2735 msg_putchar(' '); | |
2736 startcol = msg_col; | |
2737 } | |
2738 | |
2739 ga_init2(&line_ga, 1, 30); | |
2740 | |
164 | 2741 /* autoindent for :insert and :append is in the line itself */ |
168 | 2742 if (promptc <= 0) |
164 | 2743 { |
2744 vcol = indent; | |
2745 while (indent >= 8) | |
2746 { | |
2747 ga_append(&line_ga, TAB); | |
2748 msg_puts((char_u *)" "); | |
2749 indent -= 8; | |
2750 } | |
2751 while (indent-- > 0) | |
2752 { | |
2753 ga_append(&line_ga, ' '); | |
2754 msg_putchar(' '); | |
2755 } | |
2756 } | |
168 | 2757 ++no_mapping; |
2758 ++allow_keys; | |
164 | 2759 |
7 | 2760 /* |
2761 * Get the line, one character at a time. | |
2762 */ | |
2763 got_int = FALSE; | |
168 | 2764 while (!got_int) |
7 | 2765 { |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2766 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
|
2767 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
|
2768 |
7 | 2769 if (ga_grow(&line_ga, 40) == FAIL) |
2770 break; | |
2771 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2772 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2773 * 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
|
2774 */ |
1329 | 2775 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
|
2776 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2777 /* 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
|
2778 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
|
2779 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
|
2780 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2781 c1 = vgetc(); |
7 | 2782 |
2783 /* | |
168 | 2784 * Handle line editing. |
2785 * Previously this was left to the system, putting the terminal in | |
2786 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2787 */ |
168 | 2788 if (got_int) |
2789 { | |
2790 msg_putchar('\n'); | |
2791 break; | |
2792 } | |
2793 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2794 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
|
2795 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2796 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
|
2797 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
|
2798 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2799 |
168 | 2800 if (!escaped) |
7 | 2801 { |
168 | 2802 /* CR typed means "enter", which is NL */ |
2803 if (c1 == '\r') | |
2804 c1 = '\n'; | |
2805 | |
2806 if (c1 == BS || c1 == K_BS | |
2807 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2808 { |
168 | 2809 if (line_ga.ga_len > 0) |
2810 { | |
5966 | 2811 #ifdef FEAT_MBYTE |
2812 if (has_mbyte) | |
2813 { | |
2814 p = (char_u *)line_ga.ga_data; | |
2815 p[line_ga.ga_len] = NUL; | |
2816 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2817 line_ga.ga_len -= len; | |
2818 } | |
2819 else | |
2820 #endif | |
2821 --line_ga.ga_len; | |
168 | 2822 goto redraw; |
2823 } | |
2824 continue; | |
7 | 2825 } |
2826 | |
168 | 2827 if (c1 == Ctrl_U) |
7 | 2828 { |
168 | 2829 msg_col = startcol; |
2830 msg_clr_eos(); | |
2831 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
|
2832 goto redraw; |
168 | 2833 } |
2834 | |
2835 if (c1 == Ctrl_T) | |
2836 { | |
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
|
2837 sw = get_sw_value(curbuf); |
168 | 2838 p = (char_u *)line_ga.ga_data; |
2839 p[line_ga.ga_len] = NUL; | |
5995 | 2840 indent = get_indent_str(p, 8, FALSE); |
3740 | 2841 indent += sw - indent % sw; |
168 | 2842 add_indent: |
5995 | 2843 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2844 { |
7009 | 2845 (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
|
2846 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
|
2847 s = skipwhite(p); |
168 | 2848 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2849 *s = ' '; | |
2850 ++line_ga.ga_len; | |
7 | 2851 } |
168 | 2852 redraw: |
2853 /* redraw the line */ | |
2854 msg_col = startcol; | |
2855 vcol = 0; | |
5966 | 2856 p = (char_u *)line_ga.ga_data; |
2857 p[line_ga.ga_len] = NUL; | |
2858 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2859 { |
168 | 2860 if (*p == TAB) |
7 | 2861 { |
168 | 2862 do |
7 | 2863 { |
168 | 2864 msg_putchar(' '); |
2865 } while (++vcol % 8); | |
5966 | 2866 ++p; |
7 | 2867 } |
168 | 2868 else |
164 | 2869 { |
5966 | 2870 len = MB_PTR2LEN(p); |
2871 msg_outtrans_len(p, len); | |
2872 vcol += ptr2cells(p); | |
2873 p += len; | |
7 | 2874 } |
2875 } | |
168 | 2876 msg_clr_eos(); |
1329 | 2877 windgoto(msg_row, msg_col); |
168 | 2878 continue; |
2879 } | |
2880 | |
2881 if (c1 == Ctrl_D) | |
2882 { | |
2883 /* Delete one shiftwidth. */ | |
2884 p = (char_u *)line_ga.ga_data; | |
2885 if (prev_char == '0' || prev_char == '^') | |
7 | 2886 { |
168 | 2887 if (prev_char == '^') |
2888 ex_keep_indent = TRUE; | |
2889 indent = 0; | |
2890 p[--line_ga.ga_len] = NUL; | |
7 | 2891 } |
2892 else | |
2893 { | |
168 | 2894 p[line_ga.ga_len] = NUL; |
5995 | 2895 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
|
2896 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
|
2897 { |
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
|
2898 --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
|
2899 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
|
2900 } |
168 | 2901 } |
5995 | 2902 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2903 { |
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
|
2904 s = skipwhite(p); |
168 | 2905 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2906 --line_ga.ga_len; | |
7 | 2907 } |
168 | 2908 goto add_indent; |
2909 } | |
2910 | |
2911 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2912 { | |
2913 escaped = TRUE; | |
2914 continue; | |
7 | 2915 } |
168 | 2916 |
2917 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2918 if (IS_SPECIAL(c1)) | |
2919 continue; | |
7 | 2920 } |
168 | 2921 |
2922 if (IS_SPECIAL(c1)) | |
2923 c1 = '?'; | |
5966 | 2924 #ifdef FEAT_MBYTE |
2925 if (has_mbyte) | |
2926 len = (*mb_char2bytes)(c1, | |
2927 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2928 else | |
2929 #endif | |
2930 { | |
2931 len = 1; | |
2932 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2933 } | |
168 | 2934 if (c1 == '\n') |
2935 msg_putchar('\n'); | |
2936 else if (c1 == TAB) | |
2937 { | |
2938 /* Don't use chartabsize(), 'ts' can be different */ | |
2939 do | |
2940 { | |
2941 msg_putchar(' '); | |
2942 } while (++vcol % 8); | |
2943 } | |
7 | 2944 else |
2945 { | |
168 | 2946 msg_outtrans_len( |
5966 | 2947 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2948 vcol += char2cells(c1); |
7 | 2949 } |
5966 | 2950 line_ga.ga_len += len; |
168 | 2951 escaped = FALSE; |
2952 | |
2953 windgoto(msg_row, msg_col); | |
164 | 2954 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2955 |
2590 | 2956 /* We are done when a NL is entered, but not when it comes after an |
2957 * odd number of backslashes, that results in a NUL. */ | |
2958 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2959 { |
2590 | 2960 int bcount = 0; |
2961 | |
2962 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2963 ++bcount; | |
2964 | |
2965 if (bcount > 0) | |
2966 { | |
2967 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2968 * "\NL", etc. */ | |
2969 line_ga.ga_len -= (bcount + 1) / 2; | |
2970 pend -= (bcount + 1) / 2; | |
2971 pend[-1] = '\n'; | |
2972 } | |
2973 | |
2974 if ((bcount & 1) == 0) | |
2975 { | |
2976 --line_ga.ga_len; | |
2977 --pend; | |
2978 *pend = NUL; | |
2979 break; | |
2980 } | |
7 | 2981 } |
2982 } | |
2983 | |
168 | 2984 --no_mapping; |
2985 --allow_keys; | |
2986 | |
7 | 2987 /* make following messages go to the next line */ |
2988 msg_didout = FALSE; | |
2989 msg_col = 0; | |
2990 if (msg_row < Rows - 1) | |
2991 ++msg_row; | |
2992 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2993 | |
2994 if (got_int) | |
2995 ga_clear(&line_ga); | |
2996 | |
2997 return (char_u *)line_ga.ga_data; | |
2998 } | |
2999 | |
502 | 3000 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
3001 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 3002 /* |
3003 * Return TRUE if ccline.overstrike is on. | |
3004 */ | |
3005 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3006 cmdline_overstrike(void) |
7 | 3007 { |
3008 return ccline.overstrike; | |
3009 } | |
3010 | |
3011 /* | |
3012 * Return TRUE if the cursor is at the end of the cmdline. | |
3013 */ | |
3014 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3015 cmdline_at_end(void) |
7 | 3016 { |
3017 return (ccline.cmdpos >= ccline.cmdlen); | |
3018 } | |
3019 #endif | |
3020 | |
574 | 3021 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 3022 /* |
3023 * Return the virtual column number at the current cursor position. | |
3024 * This is used by the IM code to obtain the start of the preedit string. | |
3025 */ | |
3026 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3027 cmdline_getvcol_cursor(void) |
7 | 3028 { |
3029 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3030 return MAXCOL; | |
3031 | |
3032 # ifdef FEAT_MBYTE | |
3033 if (has_mbyte) | |
3034 { | |
3035 colnr_T col; | |
3036 int i = 0; | |
3037 | |
3038 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3039 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3040 |
3041 return col; | |
3042 } | |
3043 else | |
3044 # endif | |
3045 return ccline.cmdpos; | |
3046 } | |
3047 #endif | |
3048 | |
3049 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3050 /* | |
3051 * If part of the command line is an IM preedit string, redraw it with | |
3052 * IM feedback attributes. The cursor position is restored after drawing. | |
3053 */ | |
3054 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3055 redrawcmd_preedit(void) |
7 | 3056 { |
3057 if ((State & CMDLINE) | |
3058 && xic != NULL | |
976 | 3059 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3060 && !p_imdisable |
3061 && im_is_preediting()) | |
3062 { | |
3063 int cmdpos = 0; | |
3064 int cmdspos; | |
3065 int old_row; | |
3066 int old_col; | |
3067 colnr_T col; | |
3068 | |
3069 old_row = msg_row; | |
3070 old_col = msg_col; | |
531 | 3071 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3072 |
3073 # ifdef FEAT_MBYTE | |
3074 if (has_mbyte) | |
3075 { | |
3076 for (col = 0; col < preedit_start_col | |
3077 && cmdpos < ccline.cmdlen; ++col) | |
3078 { | |
3079 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3080 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3081 } |
3082 } | |
3083 else | |
3084 # endif | |
3085 { | |
3086 cmdspos += preedit_start_col; | |
3087 cmdpos += preedit_start_col; | |
3088 } | |
3089 | |
3090 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3091 msg_col = cmdspos % (int)Columns; | |
3092 if (msg_row >= Rows) | |
3093 msg_row = Rows - 1; | |
3094 | |
3095 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3096 { | |
3097 int char_len; | |
3098 int char_attr; | |
3099 | |
3100 char_attr = im_get_feedback_attr(col); | |
3101 if (char_attr < 0) | |
3102 break; /* end of preedit string */ | |
3103 | |
3104 # ifdef FEAT_MBYTE | |
3105 if (has_mbyte) | |
474 | 3106 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3107 else |
3108 # endif | |
3109 char_len = 1; | |
3110 | |
3111 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3112 cmdpos += char_len; | |
3113 } | |
3114 | |
3115 msg_row = old_row; | |
3116 msg_col = old_col; | |
3117 } | |
3118 } | |
3119 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3120 | |
3121 /* | |
3122 * Allocate a new command line buffer. | |
3123 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3124 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3125 */ | |
3126 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3127 alloc_cmdbuff(int len) |
7 | 3128 { |
3129 /* | |
3130 * give some extra space to avoid having to allocate all the time | |
3131 */ | |
3132 if (len < 80) | |
3133 len = 100; | |
3134 else | |
3135 len += 20; | |
3136 | |
3137 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3138 ccline.cmdbufflen = len; | |
3139 } | |
3140 | |
3141 /* | |
3142 * Re-allocate the command line to length len + something extra. | |
3143 * return FAIL for failure, OK otherwise | |
3144 */ | |
3145 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3146 realloc_cmdbuff(int len) |
7 | 3147 { |
3148 char_u *p; | |
3149 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3150 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3151 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
|
3152 |
7 | 3153 p = ccline.cmdbuff; |
3154 alloc_cmdbuff(len); /* will get some more */ | |
3155 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3156 { | |
3157 ccline.cmdbuff = p; /* keep the old one */ | |
3158 return FAIL; | |
3159 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3160 /* 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
|
3161 * 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
|
3162 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
|
3163 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3164 vim_free(p); |
1718 | 3165 |
3166 if (ccline.xpc != NULL | |
3167 && ccline.xpc->xp_pattern != NULL | |
3168 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3169 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3170 { | |
1754 | 3171 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3172 |
3173 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3174 * to point into the newly allocated memory. */ | |
3175 if (i >= 0 && i <= ccline.cmdlen) | |
3176 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3177 } | |
3178 | |
7 | 3179 return OK; |
3180 } | |
3181 | |
359 | 3182 #if defined(FEAT_ARABIC) || defined(PROTO) |
3183 static char_u *arshape_buf = NULL; | |
3184 | |
3185 # if defined(EXITFREE) || defined(PROTO) | |
3186 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3187 free_cmdline_buf(void) |
359 | 3188 { |
3189 vim_free(arshape_buf); | |
3190 } | |
3191 # endif | |
3192 #endif | |
3193 | |
7 | 3194 /* |
3195 * Draw part of the cmdline at the current cursor position. But draw stars | |
3196 * when cmdline_star is TRUE. | |
3197 */ | |
3198 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3199 draw_cmdline(int start, int len) |
7 | 3200 { |
3201 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3202 int i; | |
3203 | |
3204 if (cmdline_star > 0) | |
3205 for (i = 0; i < len; ++i) | |
3206 { | |
3207 msg_putchar('*'); | |
3208 # ifdef FEAT_MBYTE | |
3209 if (has_mbyte) | |
474 | 3210 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3211 # endif |
3212 } | |
3213 else | |
3214 #endif | |
3215 #ifdef FEAT_ARABIC | |
3216 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3217 { | |
3218 static int buflen = 0; | |
3219 char_u *p; | |
3220 int j; | |
3221 int newlen = 0; | |
3222 int mb_l; | |
719 | 3223 int pc, pc1 = 0; |
7 | 3224 int prev_c = 0; |
3225 int prev_c1 = 0; | |
714 | 3226 int u8c; |
3227 int u8cc[MAX_MCO]; | |
7 | 3228 int nc = 0; |
3229 | |
3230 /* | |
3231 * Do arabic shaping into a temporary buffer. This is very | |
3232 * inefficient! | |
3233 */ | |
507 | 3234 if (len * 2 + 2 > buflen) |
7 | 3235 { |
3236 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3237 * alloc()/free() calls. */ | |
359 | 3238 vim_free(arshape_buf); |
507 | 3239 buflen = len * 2 + 2; |
359 | 3240 arshape_buf = alloc(buflen); |
3241 if (arshape_buf == NULL) | |
7 | 3242 return; /* out of memory */ |
3243 } | |
3244 | |
507 | 3245 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3246 { | |
3247 /* Prepend a space to draw the leading composing char on. */ | |
3248 arshape_buf[0] = ' '; | |
3249 newlen = 1; | |
3250 } | |
3251 | |
7 | 3252 for (j = start; j < start + len; j += mb_l) |
3253 { | |
3254 p = ccline.cmdbuff + j; | |
714 | 3255 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3256 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3257 if (ARABIC_CHAR(u8c)) |
3258 { | |
3259 /* Do Arabic shaping. */ | |
3260 if (cmdmsg_rl) | |
3261 { | |
3262 /* displaying from right to left */ | |
3263 pc = prev_c; | |
3264 pc1 = prev_c1; | |
714 | 3265 prev_c1 = u8cc[0]; |
7 | 3266 if (j + mb_l >= start + len) |
3267 nc = NUL; | |
3268 else | |
3269 nc = utf_ptr2char(p + mb_l); | |
3270 } | |
3271 else | |
3272 { | |
3273 /* displaying from left to right */ | |
3274 if (j + mb_l >= start + len) | |
3275 pc = NUL; | |
3276 else | |
714 | 3277 { |
3278 int pcc[MAX_MCO]; | |
3279 | |
3280 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3281 start + len - j - mb_l); |
714 | 3282 pc1 = pcc[0]; |
3283 } | |
7 | 3284 nc = prev_c; |
3285 } | |
3286 prev_c = u8c; | |
3287 | |
714 | 3288 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3289 |
359 | 3290 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3291 if (u8cc[0] != 0) |
7 | 3292 { |
714 | 3293 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3294 if (u8cc[1] != 0) | |
3295 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3296 arshape_buf + newlen); |
7 | 3297 } |
3298 } | |
3299 else | |
3300 { | |
3301 prev_c = u8c; | |
359 | 3302 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3303 newlen += mb_l; |
3304 } | |
3305 } | |
3306 | |
359 | 3307 msg_outtrans_len(arshape_buf, newlen); |
7 | 3308 } |
3309 else | |
3310 #endif | |
3311 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3312 } | |
3313 | |
3314 /* | |
3315 * Put a character on the command line. Shifts the following text to the | |
3316 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3317 * "c" must be printable (fit in one display cell)! | |
3318 */ | |
3319 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3320 putcmdline(int c, int shift) |
7 | 3321 { |
3322 if (cmd_silent) | |
3323 return; | |
3324 msg_no_more = TRUE; | |
3325 msg_putchar(c); | |
3326 if (shift) | |
3327 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3328 msg_no_more = FALSE; | |
3329 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3330 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3331 extra_char_shift = shift; |
7 | 3332 } |
3333 | |
3334 /* | |
3335 * Undo a putcmdline(c, FALSE). | |
3336 */ | |
3337 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3338 unputcmdline(void) |
7 | 3339 { |
3340 if (cmd_silent) | |
3341 return; | |
3342 msg_no_more = TRUE; | |
3343 if (ccline.cmdlen == ccline.cmdpos) | |
3344 msg_putchar(' '); | |
3558 | 3345 #ifdef FEAT_MBYTE |
3346 else if (has_mbyte) | |
3347 draw_cmdline(ccline.cmdpos, | |
3348 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3349 #endif | |
7 | 3350 else |
3351 draw_cmdline(ccline.cmdpos, 1); | |
3352 msg_no_more = FALSE; | |
3353 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3354 extra_char = NUL; |
7 | 3355 } |
3356 | |
3357 /* | |
3358 * Put the given string, of the given length, onto the command line. | |
3359 * If len is -1, then STRLEN() is used to calculate the length. | |
3360 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3361 * part will be redrawn, otherwise it will not. If this function is called | |
3362 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3363 * called afterwards. | |
3364 */ | |
3365 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3366 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3367 { |
3368 int retval; | |
3369 int i; | |
3370 int m; | |
3371 int c; | |
3372 | |
3373 if (len < 0) | |
3374 len = (int)STRLEN(str); | |
3375 | |
3376 /* Check if ccline.cmdbuff needs to be longer */ | |
3377 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
|
3378 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3379 else |
3380 retval = OK; | |
3381 if (retval == OK) | |
3382 { | |
3383 if (!ccline.overstrike) | |
3384 { | |
3385 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3386 ccline.cmdbuff + ccline.cmdpos, | |
3387 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3388 ccline.cmdlen += len; | |
3389 } | |
3390 else | |
3391 { | |
3392 #ifdef FEAT_MBYTE | |
3393 if (has_mbyte) | |
3394 { | |
3395 /* Count nr of characters in the new string. */ | |
3396 m = 0; | |
474 | 3397 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3398 ++m; |
3399 /* Count nr of bytes in cmdline that are overwritten by these | |
3400 * characters. */ | |
3401 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3402 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3403 --m; |
3404 if (i < ccline.cmdlen) | |
3405 { | |
3406 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3407 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3408 ccline.cmdlen += ccline.cmdpos + len - i; | |
3409 } | |
3410 else | |
3411 ccline.cmdlen = ccline.cmdpos + len; | |
3412 } | |
3413 else | |
3414 #endif | |
3415 if (ccline.cmdpos + len > ccline.cmdlen) | |
3416 ccline.cmdlen = ccline.cmdpos + len; | |
3417 } | |
3418 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3419 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3420 | |
3421 #ifdef FEAT_MBYTE | |
3422 if (enc_utf8) | |
3423 { | |
3424 /* When the inserted text starts with a composing character, | |
3425 * backup to the character before it. There could be two of them. | |
3426 */ | |
3427 i = 0; | |
3428 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3429 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3430 { | |
3431 i = (*mb_head_off)(ccline.cmdbuff, | |
3432 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3433 ccline.cmdpos -= i; | |
3434 len += i; | |
3435 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3436 } | |
3437 # ifdef FEAT_ARABIC | |
3438 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3439 { | |
3440 /* Check the previous character for Arabic combining pair. */ | |
3441 i = (*mb_head_off)(ccline.cmdbuff, | |
3442 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3443 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3444 + ccline.cmdpos - i), c)) | |
3445 { | |
3446 ccline.cmdpos -= i; | |
3447 len += i; | |
3448 } | |
3449 else | |
3450 i = 0; | |
3451 } | |
3452 # endif | |
3453 if (i != 0) | |
3454 { | |
3455 /* Also backup the cursor position. */ | |
3456 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3457 ccline.cmdspos -= i; | |
3458 msg_col -= i; | |
3459 if (msg_col < 0) | |
3460 { | |
3461 msg_col += Columns; | |
3462 --msg_row; | |
3463 } | |
3464 } | |
3465 } | |
3466 #endif | |
3467 | |
3468 if (redraw && !cmd_silent) | |
3469 { | |
3470 msg_no_more = TRUE; | |
3471 i = cmdline_row; | |
3114 | 3472 cursorcmd(); |
7 | 3473 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3474 /* Avoid clearing the rest of the line too often. */ | |
3475 if (cmdline_row != i || ccline.overstrike) | |
3476 msg_clr_eos(); | |
3477 msg_no_more = FALSE; | |
3478 } | |
3479 #ifdef FEAT_FKMAP | |
3480 /* | |
3481 * If we are in Farsi command mode, the character input must be in | |
3482 * Insert mode. So do not advance the cmdpos. | |
3483 */ | |
3484 if (!cmd_fkmap) | |
3485 #endif | |
3486 { | |
3487 if (KeyTyped) | |
534 | 3488 { |
7 | 3489 m = Columns * Rows; |
534 | 3490 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3491 m = MAXCOL; | |
3492 } | |
7 | 3493 else |
3494 m = MAXCOL; | |
3495 for (i = 0; i < len; ++i) | |
3496 { | |
3497 c = cmdline_charsize(ccline.cmdpos); | |
3498 #ifdef FEAT_MBYTE | |
3499 /* count ">" for a double-wide char that doesn't fit. */ | |
3500 if (has_mbyte) | |
3501 correct_cmdspos(ccline.cmdpos, c); | |
3502 #endif | |
1612 | 3503 /* Stop cursor at the end of the screen, but do increment the |
3504 * insert position, so that entering a very long command | |
3505 * works, even though you can't see it. */ | |
3506 if (ccline.cmdspos + c < m) | |
3507 ccline.cmdspos += c; | |
7 | 3508 #ifdef FEAT_MBYTE |
3509 if (has_mbyte) | |
3510 { | |
474 | 3511 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3512 if (c > len - i - 1) |
3513 c = len - i - 1; | |
3514 ccline.cmdpos += c; | |
3515 i += c; | |
3516 } | |
3517 #endif | |
3518 ++ccline.cmdpos; | |
3519 } | |
3520 } | |
3521 } | |
3522 if (redraw) | |
3523 msg_check(); | |
3524 return retval; | |
3525 } | |
3526 | |
95 | 3527 static struct cmdline_info prev_ccline; |
3528 static int prev_ccline_used = FALSE; | |
3529 | |
3530 /* | |
3531 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3532 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3533 * available globally in prev_ccline. | |
3534 */ | |
3535 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3536 save_cmdline(struct cmdline_info *ccp) |
95 | 3537 { |
3538 if (!prev_ccline_used) | |
3539 { | |
3540 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3541 prev_ccline_used = TRUE; | |
3542 } | |
3543 *ccp = prev_ccline; | |
3544 prev_ccline = ccline; | |
3545 ccline.cmdbuff = NULL; | |
3546 ccline.cmdprompt = NULL; | |
1718 | 3547 ccline.xpc = NULL; |
95 | 3548 } |
3549 | |
3550 /* | |
1214 | 3551 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3552 */ |
3553 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3554 restore_cmdline(struct cmdline_info *ccp) |
95 | 3555 { |
3556 ccline = prev_ccline; | |
3557 prev_ccline = *ccp; | |
3558 } | |
3559 | |
849 | 3560 #if defined(FEAT_EVAL) || defined(PROTO) |
3561 /* | |
3562 * Save the command line into allocated memory. Returns a pointer to be | |
3563 * passed to restore_cmdline_alloc() later. | |
3564 * Returns NULL when failed. | |
3565 */ | |
3566 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3567 save_cmdline_alloc(void) |
849 | 3568 { |
3569 struct cmdline_info *p; | |
3570 | |
3571 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3572 if (p != NULL) | |
3573 save_cmdline(p); | |
3574 return (char_u *)p; | |
3575 } | |
3576 | |
3577 /* | |
3578 * Restore the command line from the return value of save_cmdline_alloc(). | |
3579 */ | |
3580 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3581 restore_cmdline_alloc(char_u *p) |
849 | 3582 { |
3583 if (p != NULL) | |
3584 { | |
3585 restore_cmdline((struct cmdline_info *)p); | |
3586 vim_free(p); | |
3587 } | |
3588 } | |
3589 #endif | |
3590 | |
15 | 3591 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3592 * 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
|
3593 * Used by CTRL-R command in command-line mode. |
15 | 3594 * insert_reg() can't be used here, because special characters from the |
3595 * register contents will be interpreted as commands. | |
3596 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3597 * Return FAIL for failure, OK otherwise. |
15 | 3598 */ |
3599 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3600 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3601 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3602 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
|
3603 int remcr) /* remove trailing CR */ |
15 | 3604 { |
3605 long i; | |
3606 char_u *arg; | |
772 | 3607 char_u *p; |
15 | 3608 int allocated; |
3609 struct cmdline_info save_ccline; | |
3610 | |
3611 /* check for valid regname; also accept special characters for CTRL-R in | |
3612 * the command line */ | |
3613 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
|
3614 && 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
|
3615 && !valid_yank_reg(regname, FALSE)) |
15 | 3616 return FAIL; |
3617 | |
3618 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3619 * CTRL-C to break the loop. */ | |
3620 line_breakcheck(); | |
3621 if (got_int) | |
3622 return FAIL; | |
3623 | |
3624 #ifdef FEAT_CLIPBOARD | |
3625 regname = may_get_selection(regname); | |
3626 #endif | |
3627 | |
634 | 3628 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3629 * things like going to another buffer when evaluating an expression. */ |
95 | 3630 save_cmdline(&save_ccline); |
634 | 3631 ++textlock; |
15 | 3632 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3633 --textlock; |
95 | 3634 restore_cmdline(&save_ccline); |
15 | 3635 |
3636 if (i) | |
3637 { | |
3638 /* Got the value of a special register in "arg". */ | |
3639 if (arg == NULL) | |
3640 return FAIL; | |
772 | 3641 |
3642 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3643 * part of the word. */ | |
3644 p = arg; | |
3645 if (p_is && regname == Ctrl_W) | |
3646 { | |
3647 char_u *w; | |
3648 int len; | |
3649 | |
3650 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3651 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3652 { |
3653 #ifdef FEAT_MBYTE | |
3654 if (has_mbyte) | |
3655 { | |
3656 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3657 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3658 break; | |
3659 w -= len; | |
3660 } | |
3661 else | |
3662 #endif | |
3663 { | |
3664 if (!vim_iswordc(w[-1])) | |
3665 break; | |
3666 --w; | |
3667 } | |
3668 } | |
2937 | 3669 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3670 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3671 p += len; | |
3672 } | |
3673 | |
3674 cmdline_paste_str(p, literally); | |
15 | 3675 if (allocated) |
3676 vim_free(arg); | |
3677 return OK; | |
3678 } | |
3679 | |
1015 | 3680 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3681 } |
3682 | |
3683 /* | |
3684 * Put a string on the command line. | |
3685 * When "literally" is TRUE, insert literally. | |
3686 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3687 * line. | |
3688 */ | |
3689 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3690 cmdline_paste_str(char_u *s, int literally) |
15 | 3691 { |
3692 int c, cv; | |
3693 | |
3694 if (literally) | |
3695 put_on_cmdline(s, -1, TRUE); | |
3696 else | |
3697 while (*s != NUL) | |
3698 { | |
3699 cv = *s; | |
3700 if (cv == Ctrl_V && s[1]) | |
3701 ++s; | |
3702 #ifdef FEAT_MBYTE | |
3703 if (has_mbyte) | |
1606 | 3704 c = mb_cptr2char_adv(&s); |
15 | 3705 else |
3706 #endif | |
3707 c = *s++; | |
3628 | 3708 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3709 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3710 #ifdef UNIX |
3711 || c == intr_char | |
3712 #endif | |
3713 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3714 stuffcharReadbuff(Ctrl_V); | |
3715 stuffcharReadbuff(c); | |
3716 } | |
3717 } | |
3718 | |
7 | 3719 #ifdef FEAT_WILDMENU |
3720 /* | |
3721 * Delete characters on the command line, from "from" to the current | |
3722 * position. | |
3723 */ | |
3724 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3725 cmdline_del(int from) |
7 | 3726 { |
3727 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3728 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3729 ccline.cmdlen -= ccline.cmdpos - from; | |
3730 ccline.cmdpos = from; | |
3731 } | |
3732 #endif | |
3733 | |
3734 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3735 * 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
|
3736 * 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
|
3737 * overwritten. |
7 | 3738 */ |
3739 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3740 redrawcmdline(void) |
7 | 3741 { |
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
|
3742 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
|
3743 } |
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
|
3744 |
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
|
3745 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
|
3746 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
|
3747 { |
7 | 3748 if (cmd_silent) |
3749 return; | |
3750 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
|
3751 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
|
3752 compute_cmdrow(); |
7 | 3753 redrawcmd(); |
3754 cursorcmd(); | |
3755 } | |
3756 | |
3757 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3758 redrawcmdprompt(void) |
7 | 3759 { |
3760 int i; | |
3761 | |
3762 if (cmd_silent) | |
3763 return; | |
531 | 3764 if (ccline.cmdfirstc != NUL) |
7 | 3765 msg_putchar(ccline.cmdfirstc); |
3766 if (ccline.cmdprompt != NULL) | |
3767 { | |
3768 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3769 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3770 /* do the reverse of set_cmdspos() */ | |
531 | 3771 if (ccline.cmdfirstc != NUL) |
7 | 3772 --ccline.cmdindent; |
3773 } | |
3774 else | |
3775 for (i = ccline.cmdindent; i > 0; --i) | |
3776 msg_putchar(' '); | |
3777 } | |
3778 | |
3779 /* | |
3780 * Redraw what is currently on the command line. | |
3781 */ | |
3782 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3783 redrawcmd(void) |
7 | 3784 { |
3785 if (cmd_silent) | |
3786 return; | |
3787 | |
683 | 3788 /* when 'incsearch' is set there may be no command line while redrawing */ |
3789 if (ccline.cmdbuff == NULL) | |
3790 { | |
3791 windgoto(cmdline_row, 0); | |
3792 msg_clr_eos(); | |
3793 return; | |
3794 } | |
3795 | |
7 | 3796 msg_start(); |
3797 redrawcmdprompt(); | |
3798 | |
3799 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3800 msg_no_more = TRUE; | |
3801 draw_cmdline(0, ccline.cmdlen); | |
3802 msg_clr_eos(); | |
3803 msg_no_more = FALSE; | |
3804 | |
3805 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
|
3806 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
|
3807 putcmdline(extra_char, extra_char_shift); |
7 | 3808 |
3809 /* | |
3810 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3811 * in cmdline mode we can reset them now. | |
3812 */ | |
3813 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3814 | |
3815 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3816 * in cmdline mode */ | |
3817 skip_redraw = FALSE; | |
3818 } | |
3819 | |
3820 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3821 compute_cmdrow(void) |
7 | 3822 { |
540 | 3823 if (exmode_active || msg_scrolled != 0) |
7 | 3824 cmdline_row = Rows - 1; |
3825 else | |
3826 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
|
3827 + lastwin->w_status_height; |
7 | 3828 } |
3829 | |
3830 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3831 cursorcmd(void) |
7 | 3832 { |
3833 if (cmd_silent) | |
3834 return; | |
3835 | |
3836 #ifdef FEAT_RIGHTLEFT | |
3837 if (cmdmsg_rl) | |
3838 { | |
3839 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3840 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3841 if (msg_row <= 0) | |
3842 msg_row = Rows - 1; | |
3843 } | |
3844 else | |
3845 #endif | |
3846 { | |
3847 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3848 msg_col = ccline.cmdspos % (int)Columns; | |
3849 if (msg_row >= Rows) | |
3850 msg_row = Rows - 1; | |
3851 } | |
3852 | |
3853 windgoto(msg_row, msg_col); | |
3854 #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
|
3855 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
|
3856 redrawcmd_preedit(); |
7 | 3857 #endif |
3858 #ifdef MCH_CURSOR_SHAPE | |
3859 mch_update_cursor(); | |
3860 #endif | |
3861 } | |
3862 | |
3863 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3864 gotocmdline(int clr) |
7 | 3865 { |
3866 msg_start(); | |
3867 #ifdef FEAT_RIGHTLEFT | |
3868 if (cmdmsg_rl) | |
3869 msg_col = Columns - 1; | |
3870 else | |
3871 #endif | |
3872 msg_col = 0; /* always start in column 0 */ | |
3873 if (clr) /* clear the bottom line(s) */ | |
3874 msg_clr_eos(); /* will reset clear_cmdline */ | |
3875 windgoto(cmdline_row, 0); | |
3876 } | |
3877 | |
3878 /* | |
3879 * Check the word in front of the cursor for an abbreviation. | |
3880 * Called when the non-id character "c" has been entered. | |
3881 * When an abbreviation is recognized it is removed from the text with | |
3882 * backspaces and the replacement string is inserted, followed by "c". | |
3883 */ | |
3884 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3885 ccheck_abbr(int c) |
7 | 3886 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3887 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3888 |
7 | 3889 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3890 return FALSE; | |
3891 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3892 /* 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
|
3893 * 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
|
3894 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
|
3895 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3896 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
|
3897 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3898 && 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
|
3899 && 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
|
3900 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3901 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3902 /* 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
|
3903 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3904 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3905 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3906 } |
3907 | |
3164 | 3908 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3909 static int | |
3910 #ifdef __BORLANDC__ | |
3911 _RTLENTRYF | |
3912 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3913 sort_func_compare(const void *s1, const void *s2) |
3164 | 3914 { |
3915 char_u *p1 = *(char_u **)s1; | |
3916 char_u *p2 = *(char_u **)s2; | |
3917 | |
3918 if (*p1 != '<' && *p2 == '<') return -1; | |
3919 if (*p1 == '<' && *p2 != '<') return 1; | |
3920 return STRCMP(p1, p2); | |
3921 } | |
3922 #endif | |
3923 | |
7 | 3924 /* |
3925 * Return FAIL if this is not an appropriate context in which to do | |
3926 * completion of anything, return OK if it is (even if there are no matches). | |
3927 * For the caller, this means that the character is just passed through like a | |
3928 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3929 */ | |
3930 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3931 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3932 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3933 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3934 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3935 int escape) /* if TRUE, escape the returned matches */ |
7 | 3936 { |
3937 int i, j; | |
3938 char_u *p1; | |
3939 char_u *p2; | |
3940 int difflen; | |
3941 int v; | |
3942 | |
3943 if (xp->xp_numfiles == -1) | |
3944 { | |
3945 set_expand_context(xp); | |
3946 cmd_showtail = expand_showtail(xp); | |
3947 } | |
3948 | |
3949 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3950 { | |
3951 beep_flush(); | |
3952 return OK; /* Something illegal on command line */ | |
3953 } | |
3954 if (xp->xp_context == EXPAND_NOTHING) | |
3955 { | |
3956 /* Caller can use the character as a normal char instead */ | |
3957 return FAIL; | |
3958 } | |
3959 | |
3960 MSG_PUTS("..."); /* show that we are busy */ | |
3961 out_flush(); | |
3962 | |
3963 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3964 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3965 |
3966 if (type == WILD_NEXT || type == WILD_PREV) | |
3967 { | |
3968 /* | |
3969 * Get next/previous match for a previous expanded pattern. | |
3970 */ | |
3971 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3972 } | |
3973 else | |
3974 { | |
3975 /* | |
3976 * Translate string into pattern and expand it. | |
3977 */ | |
1965 | 3978 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3979 xp->xp_context)) == NULL) | |
7 | 3980 p2 = NULL; |
3981 else | |
3982 { | |
2652 | 3983 int use_options = options | |
3961 | 3984 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3985 if (escape) | |
3986 use_options |= WILD_ESCAPE; | |
2652 | 3987 |
3988 if (p_wic) | |
3989 use_options += WILD_ICASE; | |
1965 | 3990 p2 = ExpandOne(xp, p1, |
3991 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3992 use_options, type); |
7 | 3993 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3994 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3995 if (p2 != NULL && type == WILD_LONGEST) |
3996 { | |
1965 | 3997 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3998 if (ccline.cmdbuff[i + j] == '*' |
3999 || ccline.cmdbuff[i + j] == '?') | |
4000 break; | |
4001 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
|
4002 VIM_CLEAR(p2); |
7 | 4003 } |
4004 } | |
4005 } | |
4006 | |
4007 if (p2 != NULL && !got_int) | |
4008 { | |
1965 | 4009 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
|
4010 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 4011 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
4012 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 4013 xp->xp_pattern = ccline.cmdbuff + i; |
4014 } | |
4015 else | |
4016 v = OK; | |
4017 if (v == OK) | |
4018 { | |
323 | 4019 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
4020 &ccline.cmdbuff[ccline.cmdpos], | |
4021 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
4022 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 4023 ccline.cmdlen += difflen; |
4024 ccline.cmdpos += difflen; | |
4025 } | |
4026 } | |
4027 vim_free(p2); | |
4028 | |
4029 redrawcmd(); | |
33 | 4030 cursorcmd(); |
7 | 4031 |
4032 /* When expanding a ":map" command and no matches are found, assume that | |
4033 * the key is supposed to be inserted literally */ | |
4034 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
4035 return FAIL; | |
4036 | |
4037 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4038 beep_flush(); | |
4039 else if (xp->xp_numfiles == 1) | |
4040 /* free expanded pattern */ | |
4041 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4042 | |
4043 return OK; | |
4044 } | |
4045 | |
4046 /* | |
4047 * Do wildcard expansion on the string 'str'. | |
4048 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4049 * Return a pointer to allocated memory containing the new string. |
7 | 4050 * Return NULL for failure. |
4051 * | |
1412 | 4052 * "orig" is the originally expanded string, copied to allocated memory. It |
4053 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4054 * WILD_PREV "orig" should be NULL. | |
4055 * | |
838 | 4056 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4057 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4058 * |
4059 * mode = WILD_FREE: just free previously expanded matches | |
4060 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4061 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4062 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4063 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4064 * mode = WILD_ALL: return all matches concatenated | |
4065 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4066 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4067 * |
4068 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4069 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4070 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4071 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4072 * options = WILD_ADD_SLASH: add a slash after directory names | |
4073 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4074 * options = WILD_SILENT: don't print warning messages | |
4075 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4076 * options = WILD_ICASE: ignore case for files |
7 | 4077 * |
4078 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4079 */ | |
4080 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4081 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4082 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4083 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4084 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
|
4085 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4086 int mode) |
7 | 4087 { |
4088 char_u *ss = NULL; | |
4089 static int findex; | |
4090 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4091 int orig_saved = FALSE; |
7 | 4092 int i; |
4093 long_u len; | |
4094 int non_suf_match; /* number without matching suffix */ | |
4095 | |
4096 /* | |
4097 * first handle the case of using an old match | |
4098 */ | |
4099 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4100 { | |
4101 if (xp->xp_numfiles > 0) | |
4102 { | |
4103 if (mode == WILD_PREV) | |
4104 { | |
4105 if (findex == -1) | |
4106 findex = xp->xp_numfiles; | |
4107 --findex; | |
4108 } | |
4109 else /* mode == WILD_NEXT */ | |
4110 ++findex; | |
4111 | |
4112 /* | |
4113 * When wrapping around, return the original string, set findex to | |
4114 * -1. | |
4115 */ | |
4116 if (findex < 0) | |
4117 { | |
4118 if (orig_save == NULL) | |
4119 findex = xp->xp_numfiles - 1; | |
4120 else | |
4121 findex = -1; | |
4122 } | |
4123 if (findex >= xp->xp_numfiles) | |
4124 { | |
4125 if (orig_save == NULL) | |
4126 findex = 0; | |
4127 else | |
4128 findex = -1; | |
4129 } | |
4130 #ifdef FEAT_WILDMENU | |
4131 if (p_wmnu) | |
4132 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4133 findex, cmd_showtail); | |
4134 #endif | |
4135 if (findex == -1) | |
4136 return vim_strsave(orig_save); | |
4137 return vim_strsave(xp->xp_files[findex]); | |
4138 } | |
4139 else | |
4140 return NULL; | |
4141 } | |
4142 | |
1412 | 4143 /* free old names */ |
7 | 4144 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4145 { | |
4146 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4147 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
|
4148 VIM_CLEAR(orig_save); |
7 | 4149 } |
4150 findex = 0; | |
4151 | |
4152 if (mode == WILD_FREE) /* only release file name */ | |
4153 return NULL; | |
4154 | |
4155 if (xp->xp_numfiles == -1) | |
4156 { | |
4157 vim_free(orig_save); | |
4158 orig_save = orig; | |
1432 | 4159 orig_saved = TRUE; |
7 | 4160 |
4161 /* | |
4162 * Do the expansion. | |
4163 */ | |
4164 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4165 options) == FAIL) | |
4166 { | |
4167 #ifdef FNAME_ILLEGAL | |
4168 /* Illegal file name has been silently skipped. But when there | |
4169 * are wildcards, the real problem is that there was no match, | |
4170 * causing the pattern to be added, which has illegal characters. | |
4171 */ | |
4172 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4173 EMSG2(_(e_nomatch2), str); | |
4174 #endif | |
4175 } | |
4176 else if (xp->xp_numfiles == 0) | |
4177 { | |
4178 if (!(options & WILD_SILENT)) | |
4179 EMSG2(_(e_nomatch2), str); | |
4180 } | |
4181 else | |
4182 { | |
4183 /* Escape the matches for use on the command line. */ | |
4184 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4185 | |
4186 /* | |
4187 * Check for matching suffixes in file names. | |
4188 */ | |
3398 | 4189 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4190 && mode != WILD_LONGEST) | |
7 | 4191 { |
4192 if (xp->xp_numfiles) | |
4193 non_suf_match = xp->xp_numfiles; | |
4194 else | |
4195 non_suf_match = 1; | |
4196 if ((xp->xp_context == EXPAND_FILES | |
4197 || xp->xp_context == EXPAND_DIRECTORIES) | |
4198 && xp->xp_numfiles > 1) | |
4199 { | |
4200 /* | |
4201 * More than one match; check suffix. | |
4202 * The files will have been sorted on matching suffix in | |
4203 * expand_wildcards, only need to check the first two. | |
4204 */ | |
4205 non_suf_match = 0; | |
4206 for (i = 0; i < 2; ++i) | |
4207 if (match_suffix(xp->xp_files[i])) | |
4208 ++non_suf_match; | |
4209 } | |
4210 if (non_suf_match != 1) | |
4211 { | |
4212 /* Can we ever get here unless it's while expanding | |
4213 * interactively? If not, we can get rid of this all | |
4214 * together. Don't really want to wait for this message | |
4215 * (and possibly have to hit return to continue!). | |
4216 */ | |
4217 if (!(options & WILD_SILENT)) | |
4218 EMSG(_(e_toomany)); | |
4219 else if (!(options & WILD_NO_BEEP)) | |
4220 beep_flush(); | |
4221 } | |
4222 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4223 ss = vim_strsave(xp->xp_files[0]); | |
4224 } | |
4225 } | |
4226 } | |
4227 | |
4228 /* Find longest common part */ | |
4229 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4230 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4231 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4232 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4233 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4234 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4235 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4236 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4237 if (has_mbyte) |
7 | 4238 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4239 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
|
4240 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
|
4241 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4242 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4243 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4244 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
|
4245 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
|
4246 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4247 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4248 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4249 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
|
4250 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4251 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4252 ci = xp->xp_files[i][len]; |
4242 | 4253 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4254 || xp->xp_context == EXPAND_FILES |
714 | 4255 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4256 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4257 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4258 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4259 break; |
4260 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4261 else if (c0 != ci) |
7 | 4262 break; |
4263 } | |
4264 if (i < xp->xp_numfiles) | |
4265 { | |
4266 if (!(options & WILD_NO_BEEP)) | |
6949 | 4267 vim_beep(BO_WILD); |
7 | 4268 break; |
4269 } | |
4270 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4271 |
7 | 4272 ss = alloc((unsigned)len + 1); |
4273 if (ss) | |
419 | 4274 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4275 findex = -1; /* next p_wc gets first one */ |
4276 } | |
4277 | |
4278 /* Concatenate all matching names */ | |
4279 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4280 { | |
4281 len = 0; | |
4282 for (i = 0; i < xp->xp_numfiles; ++i) | |
4283 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4284 ss = lalloc(len, TRUE); | |
4285 if (ss != NULL) | |
4286 { | |
4287 *ss = NUL; | |
4288 for (i = 0; i < xp->xp_numfiles; ++i) | |
4289 { | |
4290 STRCAT(ss, xp->xp_files[i]); | |
4291 if (i != xp->xp_numfiles - 1) | |
4292 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4293 } | |
4294 } | |
4295 } | |
4296 | |
4297 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4298 ExpandCleanup(xp); | |
4299 | |
1412 | 4300 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4301 if (!orig_saved) |
1412 | 4302 vim_free(orig); |
4303 | |
7 | 4304 return ss; |
4305 } | |
4306 | |
4307 /* | |
4308 * Prepare an expand structure for use. | |
4309 */ | |
4310 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4311 ExpandInit(expand_T *xp) |
7 | 4312 { |
1718 | 4313 xp->xp_pattern = NULL; |
1965 | 4314 xp->xp_pattern_len = 0; |
7 | 4315 xp->xp_backslash = XP_BS_NONE; |
632 | 4316 #ifndef BACKSLASH_IN_FILENAME |
4317 xp->xp_shell = FALSE; | |
4318 #endif | |
7 | 4319 xp->xp_numfiles = -1; |
4320 xp->xp_files = NULL; | |
632 | 4321 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4322 xp->xp_arg = NULL; | |
4323 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4324 xp->xp_line = NULL; |
7 | 4325 } |
4326 | |
4327 /* | |
4328 * Cleanup an expand structure after use. | |
4329 */ | |
4330 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4331 ExpandCleanup(expand_T *xp) |
7 | 4332 { |
4333 if (xp->xp_numfiles >= 0) | |
4334 { | |
4335 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4336 xp->xp_numfiles = -1; | |
4337 } | |
4338 } | |
4339 | |
4340 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4341 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4342 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4343 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4344 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4345 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4346 int options) |
7 | 4347 { |
4348 int i; | |
4349 char_u *p; | |
4350 | |
4351 /* | |
4352 * May change home directory back to "~" | |
4353 */ | |
4354 if (options & WILD_HOME_REPLACE) | |
4355 tilde_replace(str, numfiles, files); | |
4356 | |
4357 if (options & WILD_ESCAPE) | |
4358 { | |
4359 if (xp->xp_context == EXPAND_FILES | |
2778 | 4360 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4361 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4362 || xp->xp_context == EXPAND_BUFFERS |
4363 || xp->xp_context == EXPAND_DIRECTORIES) | |
4364 { | |
4365 /* | |
4366 * Insert a backslash into a file name before a space, \, %, # | |
4367 * and wildmatch characters, except '~'. | |
4368 */ | |
4369 for (i = 0; i < numfiles; ++i) | |
4370 { | |
4371 /* for ":set path=" we need to escape spaces twice */ | |
4372 if (xp->xp_backslash == XP_BS_THREE) | |
4373 { | |
4374 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4375 if (p != NULL) | |
4376 { | |
4377 vim_free(files[i]); | |
4378 files[i] = p; | |
719 | 4379 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4380 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4381 if (p != NULL) | |
4382 { | |
4383 vim_free(files[i]); | |
4384 files[i] = p; | |
4385 } | |
4386 #endif | |
4387 } | |
4388 } | |
1589 | 4389 #ifdef BACKSLASH_IN_FILENAME |
4390 p = vim_strsave_fnameescape(files[i], FALSE); | |
4391 #else | |
1586 | 4392 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4393 #endif |
7 | 4394 if (p != NULL) |
4395 { | |
4396 vim_free(files[i]); | |
4397 files[i] = p; | |
4398 } | |
4399 | |
4400 /* If 'str' starts with "\~", replace "~" at start of | |
4401 * files[i] with "\~". */ | |
4402 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4403 escape_fname(&files[i]); |
7 | 4404 } |
4405 xp->xp_backslash = XP_BS_NONE; | |
435 | 4406 |
4407 /* If the first file starts with a '+' escape it. Otherwise it | |
4408 * could be seen as "+cmd". */ | |
4409 if (*files[0] == '+') | |
4410 escape_fname(&files[0]); | |
7 | 4411 } |
4412 else if (xp->xp_context == EXPAND_TAGS) | |
4413 { | |
4414 /* | |
4415 * Insert a backslash before characters in a tag name that | |
4416 * would terminate the ":tag" command. | |
4417 */ | |
4418 for (i = 0; i < numfiles; ++i) | |
4419 { | |
4420 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4421 if (p != NULL) | |
4422 { | |
4423 vim_free(files[i]); | |
4424 files[i] = p; | |
4425 } | |
4426 } | |
4427 } | |
4428 } | |
4429 } | |
4430 | |
4431 /* | |
1586 | 4432 * Escape special characters in "fname" for when used as a file name argument |
4433 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4434 * Returns the result in allocated memory. | |
4435 */ | |
4436 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4437 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4438 { |
1685 | 4439 char_u *p; |
1586 | 4440 #ifdef BACKSLASH_IN_FILENAME |
4441 char_u buf[20]; | |
4442 int j = 0; | |
4443 | |
5481 | 4444 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4445 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4446 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4447 buf[j++] = *p; |
4448 buf[j] = NUL; | |
1700 | 4449 p = vim_strsave_escaped(fname, buf); |
1586 | 4450 #else |
1685 | 4451 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4452 if (shell && csh_like_shell() && p != NULL) | |
4453 { | |
4454 char_u *s; | |
4455 | |
4456 /* For csh and similar shells need to put two backslashes before '!'. | |
4457 * One is taken by Vim, one by the shell. */ | |
4458 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4459 vim_free(p); | |
4460 p = s; | |
4461 } | |
1700 | 4462 #endif |
4463 | |
4464 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4465 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4466 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4467 escape_fname(&p); |
4468 | |
1685 | 4469 return p; |
1586 | 4470 } |
4471 | |
4472 /* | |
435 | 4473 * Put a backslash before the file name in "pp", which is in allocated memory. |
4474 */ | |
4475 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4476 escape_fname(char_u **pp) |
435 | 4477 { |
4478 char_u *p; | |
4479 | |
4480 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4481 if (p != NULL) | |
4482 { | |
4483 p[0] = '\\'; | |
4484 STRCPY(p + 1, *pp); | |
4485 vim_free(*pp); | |
4486 *pp = p; | |
4487 } | |
4488 } | |
4489 | |
4490 /* | |
7 | 4491 * For each file name in files[num_files]: |
4492 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4493 */ | |
4494 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4495 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4496 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4497 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4498 char_u **files) |
7 | 4499 { |
4500 int i; | |
4501 char_u *p; | |
4502 | |
4503 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4504 { | |
4505 for (i = 0; i < num_files; ++i) | |
4506 { | |
4507 p = home_replace_save(NULL, files[i]); | |
4508 if (p != NULL) | |
4509 { | |
4510 vim_free(files[i]); | |
4511 files[i] = p; | |
4512 } | |
4513 } | |
4514 } | |
4515 } | |
4516 | |
4517 /* | |
4518 * Show all matches for completion on the command line. | |
4519 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4520 * be inserted like a normal character. | |
4521 */ | |
4522 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4523 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4524 { |
4525 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4526 int num_files; | |
4527 char_u **files_found; | |
4528 int i, j, k; | |
4529 int maxlen; | |
4530 int lines; | |
4531 int columns; | |
4532 char_u *p; | |
4533 int lastlen; | |
4534 int attr; | |
4535 int showtail; | |
4536 | |
4537 if (xp->xp_numfiles == -1) | |
4538 { | |
4539 set_expand_context(xp); | |
4540 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4541 &num_files, &files_found); | |
4542 showtail = expand_showtail(xp); | |
4543 if (i != EXPAND_OK) | |
4544 return i; | |
4545 | |
4546 } | |
4547 else | |
4548 { | |
4549 num_files = xp->xp_numfiles; | |
4550 files_found = xp->xp_files; | |
4551 showtail = cmd_showtail; | |
4552 } | |
4553 | |
4554 #ifdef FEAT_WILDMENU | |
4555 if (!wildmenu) | |
4556 { | |
4557 #endif | |
4558 msg_didany = FALSE; /* lines_left will be set */ | |
4559 msg_start(); /* prepare for paging */ | |
4560 msg_putchar('\n'); | |
4561 out_flush(); | |
4562 cmdline_row = msg_row; | |
4563 msg_didany = FALSE; /* lines_left will be set again */ | |
4564 msg_start(); /* prepare for paging */ | |
4565 #ifdef FEAT_WILDMENU | |
4566 } | |
4567 #endif | |
4568 | |
4569 if (got_int) | |
4570 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4571 #ifdef FEAT_WILDMENU | |
4572 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
|
4573 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4574 #endif |
4575 else | |
4576 { | |
4577 /* find the length of the longest file name */ | |
4578 maxlen = 0; | |
4579 for (i = 0; i < num_files; ++i) | |
4580 { | |
4581 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4582 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4583 || xp->xp_context == EXPAND_BUFFERS)) |
4584 { | |
4585 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4586 j = vim_strsize(NameBuff); | |
4587 } | |
4588 else | |
4589 j = vim_strsize(L_SHOWFILE(i)); | |
4590 if (j > maxlen) | |
4591 maxlen = j; | |
4592 } | |
4593 | |
4594 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4595 lines = num_files; | |
4596 else | |
4597 { | |
4598 /* compute the number of columns and lines for the listing */ | |
4599 maxlen += 2; /* two spaces between file names */ | |
4600 columns = ((int)Columns + 2) / maxlen; | |
4601 if (columns < 1) | |
4602 columns = 1; | |
4603 lines = (num_files + columns - 1) / columns; | |
4604 } | |
4605 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4606 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4607 |
4608 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4609 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4610 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4611 msg_clr_eos(); |
4612 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
|
4613 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4614 } |
4615 | |
4616 /* list the files line by line */ | |
4617 for (i = 0; i < lines; ++i) | |
4618 { | |
4619 lastlen = 999; | |
4620 for (k = i; k < num_files; k += lines) | |
4621 { | |
4622 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4623 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4624 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4625 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4626 msg_advance(maxlen + 1); | |
4627 msg_puts(p); | |
4628 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
|
4629 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4630 break; |
4631 } | |
4632 for (j = maxlen - lastlen; --j >= 0; ) | |
4633 msg_putchar(' '); | |
4634 if (xp->xp_context == EXPAND_FILES | |
714 | 4635 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4636 || xp->xp_context == EXPAND_BUFFERS) |
4637 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4638 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4639 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4640 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4641 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4642 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4643 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4644 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4645 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4646 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4647 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
|
4648 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4649 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4650 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4651 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4652 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4653 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4654 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4655 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4656 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4657 j = mch_isdir(files_found[k]); |
7 | 4658 if (showtail) |
4659 p = L_SHOWFILE(k); | |
4660 else | |
4661 { | |
4662 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4663 TRUE); | |
4664 p = NameBuff; | |
4665 } | |
4666 } | |
4667 else | |
4668 { | |
4669 j = FALSE; | |
4670 p = L_SHOWFILE(k); | |
4671 } | |
4672 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4673 } | |
4674 if (msg_col > 0) /* when not wrapped around */ | |
4675 { | |
4676 msg_clr_eos(); | |
4677 msg_putchar('\n'); | |
4678 } | |
4679 out_flush(); /* show one line at a time */ | |
4680 if (got_int) | |
4681 { | |
4682 got_int = FALSE; | |
4683 break; | |
4684 } | |
4685 } | |
4686 | |
4687 /* | |
4688 * we redraw the command below the lines that we have just listed | |
4689 * This is a bit tricky, but it saves a lot of screen updating. | |
4690 */ | |
4691 cmdline_row = msg_row; /* will put it back later */ | |
4692 } | |
4693 | |
4694 if (xp->xp_numfiles == -1) | |
4695 FreeWild(num_files, files_found); | |
4696 | |
4697 return EXPAND_OK; | |
4698 } | |
4699 | |
4700 /* | |
4701 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4702 * Find tail of file name path, but ignore trailing "/". | |
4703 */ | |
4704 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4705 sm_gettail(char_u *s) |
7 | 4706 { |
4707 char_u *p; | |
4708 char_u *t = s; | |
4709 int had_sep = FALSE; | |
4710 | |
4711 for (p = s; *p != NUL; ) | |
4712 { | |
4713 if (vim_ispathsep(*p) | |
4714 #ifdef BACKSLASH_IN_FILENAME | |
4715 && !rem_backslash(p) | |
4716 #endif | |
4717 ) | |
4718 had_sep = TRUE; | |
4719 else if (had_sep) | |
4720 { | |
4721 t = p; | |
4722 had_sep = FALSE; | |
4723 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4724 MB_PTR_ADV(p); |
7 | 4725 } |
4726 return t; | |
4727 } | |
4728 | |
4729 /* | |
4730 * Return TRUE if we only need to show the tail of completion matches. | |
4731 * When not completing file names or there is a wildcard in the path FALSE is | |
4732 * returned. | |
4733 */ | |
4734 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4735 expand_showtail(expand_T *xp) |
7 | 4736 { |
4737 char_u *s; | |
4738 char_u *end; | |
4739 | |
4740 /* When not completing file names a "/" may mean something different. */ | |
714 | 4741 if (xp->xp_context != EXPAND_FILES |
4742 && xp->xp_context != EXPAND_SHELLCMD | |
4743 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4744 return FALSE; |
4745 | |
4746 end = gettail(xp->xp_pattern); | |
4747 if (end == xp->xp_pattern) /* there is no path separator */ | |
4748 return FALSE; | |
4749 | |
4750 for (s = xp->xp_pattern; s < end; s++) | |
4751 { | |
4752 /* Skip escaped wildcards. Only when the backslash is not a path | |
4753 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4754 if (rem_backslash(s)) | |
4755 ++s; | |
4756 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4757 return FALSE; | |
4758 } | |
4759 return TRUE; | |
4760 } | |
4761 | |
4762 /* | |
4763 * Prepare a string for expansion. | |
4764 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4765 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4766 * When expanding other names: The string will be used with regcomp(). Copy |
4767 * the name into allocated memory and prepend "^". | |
4768 */ | |
4769 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4770 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4771 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4772 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4773 int context) /* EXPAND_FILES etc. */ |
7 | 4774 { |
4775 char_u *retval; | |
4776 int i, j; | |
4777 int new_len; | |
4778 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4779 int ends_in_star; |
7 | 4780 |
714 | 4781 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4782 && context != EXPAND_FILES_IN_PATH |
714 | 4783 && context != EXPAND_SHELLCMD |
4784 && context != EXPAND_DIRECTORIES) | |
7 | 4785 { |
4786 /* | |
4787 * Matching will be done internally (on something other than files). | |
4788 * So we convert the file-matching-type wildcards into our kind for | |
4789 * use with vim_regcomp(). First work out how long it will be: | |
4790 */ | |
4791 | |
4792 /* For help tags the translation is done in find_help_tags(). | |
4793 * For a tag pattern starting with "/" no translation is needed. */ | |
4794 if (context == EXPAND_HELP | |
4795 || context == EXPAND_COLORS | |
4796 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4797 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4798 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4799 || 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
|
4800 || ((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
|
4801 || 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
|
4802 && fname[0] == '/')) |
7 | 4803 retval = vim_strnsave(fname, len); |
4804 else | |
4805 { | |
4806 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4807 for (i = 0; i < len; i++) | |
4808 { | |
4809 if (fname[i] == '*' || fname[i] == '~') | |
4810 new_len++; /* '*' needs to be replaced by ".*" | |
4811 '~' needs to be replaced by "\~" */ | |
4812 | |
4813 /* Buffer names are like file names. "." should be literal */ | |
4814 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4815 new_len++; /* "." becomes "\." */ | |
4816 | |
4817 /* Custom expansion takes care of special things, match | |
4818 * backslashes literally (perhaps also for other types?) */ | |
634 | 4819 if ((context == EXPAND_USER_DEFINED |
4820 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4821 new_len++; /* '\' becomes "\\" */ |
4822 } | |
4823 retval = alloc(new_len); | |
4824 if (retval != NULL) | |
4825 { | |
4826 retval[0] = '^'; | |
4827 j = 1; | |
4828 for (i = 0; i < len; i++, j++) | |
4829 { | |
4830 /* Skip backslash. But why? At least keep it for custom | |
4831 * expansion. */ | |
4832 if (context != EXPAND_USER_DEFINED | |
407 | 4833 && context != EXPAND_USER_LIST |
4834 && fname[i] == '\\' | |
4835 && ++i == len) | |
7 | 4836 break; |
4837 | |
4838 switch (fname[i]) | |
4839 { | |
4840 case '*': retval[j++] = '.'; | |
4841 break; | |
4842 case '~': retval[j++] = '\\'; | |
4843 break; | |
4844 case '?': retval[j] = '.'; | |
4845 continue; | |
4846 case '.': if (context == EXPAND_BUFFERS) | |
4847 retval[j++] = '\\'; | |
4848 break; | |
407 | 4849 case '\\': if (context == EXPAND_USER_DEFINED |
4850 || context == EXPAND_USER_LIST) | |
7 | 4851 retval[j++] = '\\'; |
4852 break; | |
4853 } | |
4854 retval[j] = fname[i]; | |
4855 } | |
4856 retval[j] = NUL; | |
4857 } | |
4858 } | |
4859 } | |
4860 else | |
4861 { | |
4862 retval = alloc(len + 4); | |
4863 if (retval != NULL) | |
4864 { | |
419 | 4865 vim_strncpy(retval, fname, len); |
7 | 4866 |
4867 /* | |
831 | 4868 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4869 * * would become **, which walks the whole tree. | |
7 | 4870 * ~ would be at the start of the file name, but not the tail. |
4871 * $ could be anywhere in the tail. | |
4872 * ` could be anywhere in the file name. | |
1484 | 4873 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4874 */ |
4875 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4876 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
|
4877 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4878 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4879 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4880 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4881 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4882 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4883 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4884 #endif |
7 | 4885 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4886 && !ends_in_star |
7 | 4887 && vim_strchr(tail, '$') == NULL |
4888 && vim_strchr(retval, '`') == NULL) | |
4889 retval[len++] = '*'; | |
1484 | 4890 else if (len > 0 && retval[len - 1] == '$') |
4891 --len; | |
7 | 4892 retval[len] = NUL; |
4893 } | |
4894 } | |
4895 return retval; | |
4896 } | |
4897 | |
4898 /* | |
4899 * Must parse the command line so far to work out what context we are in. | |
4900 * Completion can then be done based on that context. | |
4901 * This routine sets the variables: | |
4902 * xp->xp_pattern The start of the pattern to be expanded within | |
4903 * the command line (ends at the cursor). | |
4904 * xp->xp_context The type of thing to expand. Will be one of: | |
4905 * | |
4906 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4907 * the command line, like an unknown command. Caller | |
4908 * should beep. | |
4909 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4910 * a normal char, rather than for completion. eg | |
4911 * :s/^I/ | |
4912 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4913 * it. | |
4914 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4915 * EXPAND_FILES After command with XFILE set, or after setting | |
4916 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4917 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4918 * when we know only directories are of interest. eg | |
4919 * :set dir=^I | |
714 | 4920 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4921 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4922 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4923 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4924 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4925 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4926 * EXPAND_EVENTS Complete event names | |
4927 * EXPAND_SYNTAX Complete :syntax command arguments | |
4928 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4929 * EXPAND_AUGROUP Complete autocommand group names | |
4930 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4931 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4932 * eg :unmap a^I , :cunab x^I | |
4933 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4934 * eg :call sub^I | |
4935 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4936 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4937 * names in expressions, eg :while s^I | |
4938 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4939 * EXPAND_USER Complete user names |
7 | 4940 */ |
4941 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4942 set_expand_context(expand_T *xp) |
7 | 4943 { |
168 | 4944 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4945 if (ccline.cmdfirstc != ':' |
4946 #ifdef FEAT_EVAL | |
168 | 4947 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4948 && !ccline.input_fn |
7 | 4949 #endif |
4950 ) | |
4951 { | |
4952 xp->xp_context = EXPAND_NOTHING; | |
4953 return; | |
4954 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4955 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4956 } |
4957 | |
4958 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4959 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4960 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4961 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
|
4962 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
|
4963 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4964 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4965 { |
4966 int old_char = NUL; | |
4967 char_u *nextcomm; | |
4968 | |
4969 /* | |
4970 * Avoid a UMR warning from Purify, only save the character if it has been | |
4971 * written before. | |
4972 */ | |
4973 if (col < len) | |
4974 old_char = str[col]; | |
4975 str[col] = NUL; | |
4976 nextcomm = str; | |
168 | 4977 |
4978 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4979 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4980 { |
4981 # ifdef FEAT_CMDL_COMPL | |
168 | 4982 /* pass CMD_SIZE because there is no real command */ |
4983 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4984 # endif |
4985 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4986 else if (use_ccline && ccline.input_fn) |
531 | 4987 { |
4988 xp->xp_context = ccline.xp_context; | |
4989 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4990 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4991 xp->xp_arg = ccline.xp_arg; |
1322 | 4992 # endif |
531 | 4993 } |
168 | 4994 else |
4995 #endif | |
4996 while (nextcomm != NULL) | |
4997 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4998 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4999 /* 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
|
5000 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
5001 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
5002 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
5003 |
7 | 5004 str[col] = old_char; |
5005 } | |
5006 | |
5007 /* | |
5008 * Expand the command line "str" from context "xp". | |
5009 * "xp" must have been set by set_cmd_context(). | |
5010 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
5011 * starts. | |
5012 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
5013 * cursor. | |
5014 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
5015 * key that triggered expansion literally. | |
5016 * Returns EXPAND_OK otherwise. | |
5017 */ | |
5018 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5019 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5020 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5021 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
|
5022 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5023 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5024 char_u ***matches) /* return: array of pointers to matches */ |
7 | 5025 { |
5026 char_u *file_str = NULL; | |
2652 | 5027 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 5028 |
5029 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
5030 { | |
5031 beep_flush(); | |
5032 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
5033 } | |
5034 if (xp->xp_context == EXPAND_NOTHING) | |
5035 { | |
5036 /* Caller can use the character as a normal char instead */ | |
5037 return EXPAND_NOTHING; | |
5038 } | |
5039 | |
5040 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5041 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5042 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5043 if (file_str == NULL) |
5044 return EXPAND_UNSUCCESSFUL; | |
5045 | |
2652 | 5046 if (p_wic) |
5047 options += WILD_ICASE; | |
5048 | |
7 | 5049 /* find all files that match the description */ |
2652 | 5050 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5051 { |
5052 *matchcount = 0; | |
5053 *matches = NULL; | |
5054 } | |
5055 vim_free(file_str); | |
5056 | |
5057 return EXPAND_OK; | |
5058 } | |
5059 | |
5060 #ifdef FEAT_MULTI_LANG | |
5061 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5062 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5063 * 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
|
5064 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5065 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5066 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5067 |
5068 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5069 cleanup_help_tags(int num_file, char_u **file) |
7 | 5070 { |
5071 int i, j; | |
5072 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5073 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5074 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5075 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5076 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
|
5077 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5078 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5079 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5080 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5081 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5082 *p = NUL; |
7 | 5083 |
5084 for (i = 0; i < num_file; ++i) | |
5085 { | |
5086 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
|
5087 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5088 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5089 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5090 { |
5091 /* Sorting on priority means the same item in another language may | |
5092 * be anywhere. Search all items for a match up to the "@en". */ | |
5093 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
|
5094 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
|
5095 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5096 break; |
5097 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5098 /* item only exists with @en, remove it */ |
7 | 5099 file[i][len] = NUL; |
5100 } | |
5101 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5102 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5103 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5104 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
|
5105 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5106 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5107 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5108 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5109 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
|
5110 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5111 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5112 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5113 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5114 } |
7 | 5115 } |
5116 #endif | |
5117 | |
5118 /* | |
5119 * Do the expansion based on xp->xp_context and "pat". | |
5120 */ | |
5121 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5122 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5123 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5124 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5125 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5126 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5127 int options) /* EW_ flags */ |
7 | 5128 { |
5129 #ifdef FEAT_CMDL_COMPL | |
5130 regmatch_T regmatch; | |
5131 #endif | |
5132 int ret; | |
5133 int flags; | |
5134 | |
5135 flags = EW_DIR; /* include directories */ | |
5136 if (options & WILD_LIST_NOTFOUND) | |
5137 flags |= EW_NOTFOUND; | |
5138 if (options & WILD_ADD_SLASH) | |
5139 flags |= EW_ADDSLASH; | |
5140 if (options & WILD_KEEP_ALL) | |
5141 flags |= EW_KEEPALL; | |
5142 if (options & WILD_SILENT) | |
5143 flags |= EW_SILENT; | |
6659 | 5144 if (options & WILD_ALLLINKS) |
5145 flags |= EW_ALLLINKS; | |
7 | 5146 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5147 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5148 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5149 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5150 { |
5151 /* | |
5152 * Expand file or directory names. | |
5153 */ | |
5154 int free_pat = FALSE; | |
5155 int i; | |
5156 | |
5157 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5158 * space */ | |
5159 if (xp->xp_backslash != XP_BS_NONE) | |
5160 { | |
5161 free_pat = TRUE; | |
5162 pat = vim_strsave(pat); | |
5163 for (i = 0; pat[i]; ++i) | |
5164 if (pat[i] == '\\') | |
5165 { | |
5166 if (xp->xp_backslash == XP_BS_THREE | |
5167 && pat[i + 1] == '\\' | |
5168 && pat[i + 2] == '\\' | |
5169 && pat[i + 3] == ' ') | |
1621 | 5170 STRMOVE(pat + i, pat + i + 3); |
7 | 5171 if (xp->xp_backslash == XP_BS_ONE |
5172 && pat[i + 1] == ' ') | |
1621 | 5173 STRMOVE(pat + i, pat + i + 1); |
7 | 5174 } |
5175 } | |
5176 | |
5177 if (xp->xp_context == EXPAND_FILES) | |
5178 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5179 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
|
5180 flags |= (EW_FILE | EW_PATH); |
7 | 5181 else |
5182 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5183 if (options & WILD_ICASE) |
5184 flags |= EW_ICASE; | |
5185 | |
2016 | 5186 /* Expand wildcards, supporting %:h and the like. */ |
5187 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5188 if (free_pat) |
5189 vim_free(pat); | |
5190 return ret; | |
5191 } | |
5192 | |
5193 *file = (char_u **)""; | |
5194 *num_file = 0; | |
5195 if (xp->xp_context == EXPAND_HELP) | |
5196 { | |
1696 | 5197 /* With an empty argument we would get all the help tags, which is |
5198 * very slow. Get matches for "help" instead. */ | |
5199 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5200 num_file, file, FALSE) == OK) | |
7 | 5201 { |
5202 #ifdef FEAT_MULTI_LANG | |
5203 cleanup_help_tags(*num_file, *file); | |
5204 #endif | |
5205 return OK; | |
5206 } | |
5207 return FAIL; | |
5208 } | |
5209 | |
5210 #ifndef FEAT_CMDL_COMPL | |
5211 return FAIL; | |
5212 #else | |
716 | 5213 if (xp->xp_context == EXPAND_SHELLCMD) |
5214 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5215 if (xp->xp_context == EXPAND_OLD_SETTING) |
5216 return ExpandOldSetting(num_file, file); | |
5217 if (xp->xp_context == EXPAND_BUFFERS) | |
5218 return ExpandBufnames(pat, num_file, file, options); | |
5219 if (xp->xp_context == EXPAND_TAGS | |
5220 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5221 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5222 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5223 { |
5224 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5225 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
|
5226 directories); |
2929 | 5227 } |
7 | 5228 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5229 { |
3106 | 5230 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5231 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5232 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5233 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5234 { |
5235 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5236 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5237 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5238 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5239 { |
5240 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
|
5241 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5242 } |
407 | 5243 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5244 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5245 return ExpandUserList(xp, num_file, file); |
407 | 5246 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5247 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5248 return ExpandPackAddDir(pat, num_file, file); |
7 | 5249 |
5250 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5251 if (regmatch.regprog == NULL) | |
5252 return FAIL; | |
5253 | |
5254 /* set ignore-case according to p_ic, p_scs and pat */ | |
5255 regmatch.rm_ic = ignorecase(pat); | |
5256 | |
5257 if (xp->xp_context == EXPAND_SETTINGS | |
5258 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5259 ret = ExpandSettings(xp, ®match, num_file, file); | |
5260 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5261 ret = ExpandMappings(®match, num_file, file); | |
5262 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5263 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5264 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5265 # endif | |
5266 else | |
5267 { | |
5268 static struct expgen | |
5269 { | |
5270 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5271 char_u *((*func)(expand_T *, int)); |
7 | 5272 int ic; |
2849 | 5273 int escaped; |
7 | 5274 } tab[] = |
5275 { | |
2849 | 5276 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5277 {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
|
5278 {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
|
5279 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5280 #ifdef FEAT_CMDHIST |
5281 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5282 #endif | |
7 | 5283 #ifdef FEAT_USR_CMDS |
2849 | 5284 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5285 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5286 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5287 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5288 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5289 #endif |
5290 #ifdef FEAT_EVAL | |
2849 | 5291 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5292 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5293 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5294 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5295 #endif |
5296 #ifdef FEAT_MENU | |
2849 | 5297 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5298 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5299 #endif |
5300 #ifdef FEAT_SYN_HL | |
2849 | 5301 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5302 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5303 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5304 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5305 #endif |
2849 | 5306 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5307 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5308 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5309 #ifdef FEAT_CSCOPE |
2849 | 5310 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5311 #endif |
1868 | 5312 #ifdef FEAT_SIGNS |
2849 | 5313 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5314 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5315 #ifdef FEAT_PROFILE |
2849 | 5316 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5317 #endif |
7 | 5318 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5319 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5320 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5321 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5322 #endif | |
5323 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5324 {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
|
5325 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5326 }; |
5327 int i; | |
5328 | |
5329 /* | |
5330 * Find a context in the table and call the ExpandGeneric() with the | |
5331 * right function to do the expansion. | |
5332 */ | |
5333 ret = FAIL; | |
1880 | 5334 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5335 if (xp->xp_context == tab[i].context) |
5336 { | |
5337 if (tab[i].ic) | |
5338 regmatch.rm_ic = TRUE; | |
2849 | 5339 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5340 tab[i].func, tab[i].escaped); |
7 | 5341 break; |
5342 } | |
5343 } | |
5344 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5345 vim_regfree(regmatch.regprog); |
7 | 5346 |
5347 return ret; | |
5348 #endif /* FEAT_CMDL_COMPL */ | |
5349 } | |
5350 | |
5351 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5352 /* | |
5353 * Expand a list of names. | |
5354 * | |
5355 * Generic function for command line completion. It calls a function to | |
5356 * obtain strings, one by one. The strings are matched against a regexp | |
5357 * program. Matching strings are copied into an array, which is returned. | |
5358 * | |
5359 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5360 */ | |
5361 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5362 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5363 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5364 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5365 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5366 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5367 char_u *((*func)(expand_T *, int)), |
7 | 5368 /* 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
|
5369 int escaped) |
7 | 5370 { |
5371 int i; | |
5372 int count = 0; | |
480 | 5373 int round; |
7 | 5374 char_u *str; |
5375 | |
5376 /* do this loop twice: | |
480 | 5377 * round == 0: count the number of matching names |
5378 * round == 1: copy the matching names into allocated memory | |
7 | 5379 */ |
480 | 5380 for (round = 0; round <= 1; ++round) |
7 | 5381 { |
5382 for (i = 0; ; ++i) | |
5383 { | |
5384 str = (*func)(xp, i); | |
5385 if (str == NULL) /* end of list */ | |
5386 break; | |
5387 if (*str == NUL) /* skip empty strings */ | |
5388 continue; | |
5389 | |
5390 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5391 { | |
480 | 5392 if (round) |
7 | 5393 { |
2849 | 5394 if (escaped) |
5395 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5396 else | |
5397 str = vim_strsave(str); | |
7 | 5398 (*file)[count] = str; |
5399 #ifdef FEAT_MENU | |
5400 if (func == get_menu_names && str != NULL) | |
5401 { | |
5402 /* test for separator added by get_menu_names() */ | |
5403 str += STRLEN(str) - 1; | |
5404 if (*str == '\001') | |
5405 *str = '.'; | |
5406 } | |
5407 #endif | |
5408 } | |
5409 ++count; | |
5410 } | |
5411 } | |
480 | 5412 if (round == 0) |
7 | 5413 { |
5414 if (count == 0) | |
5415 return OK; | |
5416 *num_file = count; | |
5417 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5418 if (*file == NULL) | |
5419 { | |
5420 *file = (char_u **)""; | |
5421 return FAIL; | |
5422 } | |
5423 count = 0; | |
5424 } | |
5425 } | |
480 | 5426 |
828 | 5427 /* Sort the results. Keep menu's in the specified order. */ |
5428 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5429 { |
5430 if (xp->xp_context == EXPAND_EXPRESSION | |
5431 || xp->xp_context == EXPAND_FUNCTIONS | |
5432 || xp->xp_context == EXPAND_USER_FUNC) | |
5433 /* <SNR> functions should be sorted to the end. */ | |
5434 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5435 sort_func_compare); | |
5436 else | |
5437 sort_strings(*file, *num_file); | |
5438 } | |
480 | 5439 |
1322 | 5440 #ifdef FEAT_CMDL_COMPL |
5441 /* Reset the variables used for special highlight names expansion, so that | |
5442 * they don't show up when getting normal highlight names by ID. */ | |
5443 reset_expand_highlight(); | |
5444 #endif | |
5445 | |
7 | 5446 return OK; |
5447 } | |
5448 | |
716 | 5449 /* |
5450 * Complete a shell command. | |
5451 * Returns FAIL or OK; | |
5452 */ | |
5453 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5454 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5455 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
|
5456 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
|
5457 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
|
5458 int flagsarg) /* EW_ flags */ |
716 | 5459 { |
5460 char_u *pat; | |
5461 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5462 char_u *path = NULL; |
716 | 5463 int mustfree = FALSE; |
5464 garray_T ga; | |
5465 char_u *buf = alloc(MAXPATHL); | |
5466 size_t l; | |
5467 char_u *s, *e; | |
5468 int flags = flagsarg; | |
5469 int ret; | |
6695 | 5470 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5471 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5472 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5473 hash_T hash; |
716 | 5474 |
5475 if (buf == NULL) | |
5476 return FAIL; | |
5477 | |
5478 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5479 * space */ | |
5480 pat = vim_strsave(filepat); | |
5481 for (i = 0; pat[i]; ++i) | |
5482 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5483 STRMOVE(pat + i, pat + i + 1); |
716 | 5484 |
6695 | 5485 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5486 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5487 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
|
5488 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5489 path = (char_u *)"."; |
5490 else | |
2630 | 5491 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5492 /* 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
|
5493 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5494 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5495 if (path == NULL) |
5496 path = (char_u *)""; | |
5497 } | |
716 | 5498 |
5499 /* | |
5500 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5501 * collect them in "ga". When "." is not in $PATH also expand for the |
5502 * current directory, to find "subdir/cmd". | |
716 | 5503 */ |
5504 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
|
5505 hash_init(&found_ht); |
6695 | 5506 for (s = path; ; s = e) |
716 | 5507 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5508 #if defined(MSWIN) |
716 | 5509 e = vim_strchr(s, ';'); |
5510 #else | |
5511 e = vim_strchr(s, ':'); | |
5512 #endif | |
5513 if (e == NULL) | |
5514 e = s + STRLEN(s); | |
5515 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5516 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
|
5517 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5518 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
|
5519 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5520 // 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
|
5521 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
|
5522 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
|
5523 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5524 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
|
5525 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5526 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
|
5527 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
|
5528 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5529 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5530 // 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
|
5531 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
|
5532 |
716 | 5533 l = e - s; |
5534 if (l > MAXPATHL - 5) | |
5535 break; | |
5536 vim_strncpy(buf, s, l); | |
5537 add_pathsep(buf); | |
5538 l = STRLEN(buf); | |
5539 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5540 | |
5541 /* Expand matches in one directory of $PATH. */ | |
5542 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5543 if (ret == OK) | |
5544 { | |
5545 if (ga_grow(&ga, *num_file) == FAIL) | |
5546 FreeWild(*num_file, *file); | |
5547 else | |
5548 { | |
5549 for (i = 0; i < *num_file; ++i) | |
5550 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5551 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5552 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5553 if (STRLEN(name) > l) |
716 | 5554 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5555 // 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
|
5556 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5557 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
|
5558 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5559 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5560 // 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
|
5561 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5562 ((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
|
5563 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
|
5564 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5565 } |
716 | 5566 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5567 vim_free(name); |
716 | 5568 } |
5569 vim_free(*file); | |
5570 } | |
5571 } | |
5572 if (*e != NUL) | |
5573 ++e; | |
5574 } | |
5575 *file = ga.ga_data; | |
5576 *num_file = ga.ga_len; | |
5577 | |
5578 vim_free(buf); | |
5579 vim_free(pat); | |
5580 if (mustfree) | |
5581 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5582 hash_clear(&found_ht); |
716 | 5583 return OK; |
5584 } | |
5585 | |
5586 | |
7 | 5587 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5588 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5589 * 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
|
5590 * return the result (either a string or a List). |
7 | 5591 */ |
407 | 5592 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5593 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
|
5594 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
|
5595 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5596 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5597 char_u ***file) |
7 | 5598 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5599 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
|
5600 typval_T args[4]; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5601 sctx_T save_current_sctx = current_sctx; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5602 char_u *pat = NULL; |
407 | 5603 void *ret; |
13 | 5604 struct cmdline_info save_ccline; |
7 | 5605 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5606 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5607 return NULL; |
7 | 5608 *num_file = 0; |
5609 *file = NULL; | |
5610 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5611 if (ccline.cmdbuff != NULL) |
1518 | 5612 { |
5613 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5614 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5615 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5616 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5617 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
|
5618 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5619 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
|
5620 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
|
5621 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
|
5622 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
|
5623 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
|
5624 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
|
5625 args[3].v_type = VAR_UNKNOWN; |
7 | 5626 |
13 | 5627 /* Save the cmdline, we don't know what the function may do. */ |
5628 save_ccline = ccline; | |
5629 ccline.cmdbuff = NULL; | |
5630 ccline.cmdprompt = NULL; | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5631 current_sctx = xp->xp_script_ctx; |
13 | 5632 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5633 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5634 |
5635 ccline = save_ccline; | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5636 current_sctx = save_current_sctx; |
1518 | 5637 if (ccline.cmdbuff != NULL) |
5638 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5639 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5640 vim_free(pat); |
407 | 5641 return ret; |
5642 } | |
5643 | |
5644 /* | |
5645 * Expand names with a function defined by the user. | |
5646 */ | |
5647 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5648 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5649 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5650 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5651 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5652 char_u ***file) |
407 | 5653 { |
5654 char_u *retstr; | |
5655 char_u *s; | |
5656 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
|
5657 int keep; |
407 | 5658 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
|
5659 int skip; |
407 | 5660 |
5661 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5662 if (retstr == NULL) | |
7 | 5663 return FAIL; |
5664 | |
5665 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5666 for (s = retstr; *s != NUL; s = e) |
7 | 5667 { |
5668 e = vim_strchr(s, '\n'); | |
5669 if (e == NULL) | |
5670 e = s + STRLEN(s); | |
5671 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
|
5672 *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
|
5673 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5674 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
|
5675 *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
|
5676 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5677 if (!skip) |
7 | 5678 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5679 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
|
5680 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5681 ((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
|
5682 ++ga.ga_len; |
7 | 5683 } |
5684 | |
5685 if (*e != NUL) | |
5686 ++e; | |
5687 } | |
407 | 5688 vim_free(retstr); |
5689 *file = ga.ga_data; | |
5690 *num_file = ga.ga_len; | |
5691 return OK; | |
5692 } | |
5693 | |
5694 /* | |
5695 * Expand names with a list returned by a function defined by the user. | |
5696 */ | |
5697 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5698 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5699 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5700 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5701 char_u ***file) |
407 | 5702 { |
5703 list_T *retlist; | |
5704 listitem_T *li; | |
5705 garray_T ga; | |
5706 | |
5707 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5708 if (retlist == NULL) | |
5709 return FAIL; | |
5710 | |
5711 ga_init2(&ga, (int)sizeof(char *), 3); | |
5712 /* Loop over the items in the list. */ | |
5713 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5714 { | |
1917 | 5715 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5716 continue; /* Skip non-string items and empty strings */ | |
407 | 5717 |
5718 if (ga_grow(&ga, 1) == FAIL) | |
5719 break; | |
5720 | |
5721 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5722 vim_strsave(li->li_tv.vval.v_string); |
407 | 5723 ++ga.ga_len; |
5724 } | |
5725 list_unref(retlist); | |
5726 | |
7 | 5727 *file = ga.ga_data; |
5728 *num_file = ga.ga_len; | |
5729 return OK; | |
5730 } | |
5731 #endif | |
5732 | |
5733 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5734 * 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
|
5735 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5736 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5737 * 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
|
5738 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5739 * 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
|
5740 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5741 * "dirnames" is an array with one or more directory names. |
7 | 5742 */ |
5743 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5744 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5745 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5746 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5747 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5748 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5749 char *dirnames[]) |
7 | 5750 { |
5751 char_u *s; | |
5752 char_u *e; | |
5873 | 5753 char_u *match; |
7 | 5754 garray_T ga; |
2929 | 5755 int i; |
5756 int pat_len; | |
7 | 5757 |
5758 *num_file = 0; | |
5759 *file = NULL; | |
2931 | 5760 pat_len = (int)STRLEN(pat); |
2929 | 5761 ga_init2(&ga, (int)sizeof(char *), 10); |
5762 | |
5763 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5764 { |
2929 | 5765 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5766 if (s == NULL) | |
5767 { | |
5768 ga_clear_strings(&ga); | |
5769 return FAIL; | |
5770 } | |
5771 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5772 globpath(p_rtp, s, &ga, 0); |
2929 | 5773 vim_free(s); |
5873 | 5774 } |
5775 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5776 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5777 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
|
5778 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5779 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
|
5780 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5781 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5782 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5783 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5784 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5785 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
|
5786 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5787 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5788 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5789 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5790 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5791 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5792 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
|
5793 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5794 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
|
5795 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5796 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5797 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5798 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5799 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5800 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
|
5801 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5802 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5803 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5804 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5805 |
5873 | 5806 for (i = 0; i < ga.ga_len; ++i) |
5807 { | |
5808 match = ((char_u **)ga.ga_data)[i]; | |
5809 s = match; | |
5810 e = s + STRLEN(s); | |
5811 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5812 { |
5873 | 5813 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5814 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5815 if (s < match || vim_ispathsep(*s)) |
5816 break; | |
5817 ++s; | |
5818 *e = NUL; | |
5819 mch_memmove(match, s, e - s + 1); | |
7 | 5820 } |
5821 } | |
5873 | 5822 |
2929 | 5823 if (ga.ga_len == 0) |
3628 | 5824 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5825 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5826 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5827 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5828 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5829 |
7 | 5830 *file = ga.ga_data; |
5831 *num_file = ga.ga_len; | |
5832 return OK; | |
5833 } | |
5834 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5835 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5841 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5842 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5843 char_u ***file) |
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 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5846 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5847 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5849 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5850 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5851 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5852 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5853 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5854 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5855 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
|
5856 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5857 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5858 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5859 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5860 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5861 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5862 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5863 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
|
5864 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5865 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5866 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5867 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
|
5868 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5869 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
|
5870 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5871 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5872 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
|
5873 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5874 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5875 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5876 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5877 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5878 /* 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
|
5879 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5880 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5881 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5882 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5883 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5884 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5885 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5886 |
7 | 5887 #endif |
5888 | |
5889 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5890 /* | |
5891 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5892 * Adds the matches to "ga". Caller must init "ga". |
7 | 5893 */ |
5873 | 5894 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5895 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5896 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5897 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5898 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5899 int expand_options) |
7 | 5900 { |
5901 expand_T xpc; | |
5902 char_u *buf; | |
5903 int i; | |
5904 int num_p; | |
5905 char_u **p; | |
5906 | |
5907 buf = alloc(MAXPATHL); | |
5908 if (buf == NULL) | |
5873 | 5909 return; |
7 | 5910 |
632 | 5911 ExpandInit(&xpc); |
7 | 5912 xpc.xp_context = EXPAND_FILES; |
632 | 5913 |
7 | 5914 /* Loop over all entries in {path}. */ |
5915 while (*path != NUL) | |
5916 { | |
5917 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5918 copy_option_part(&path, buf, MAXPATHL, ","); | |
5919 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5920 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5921 # 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
|
5922 /* 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
|
5923 * 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
|
5924 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
|
5925 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5926 # else |
7 | 5927 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
|
5928 # endif |
7 | 5929 STRCAT(buf, file); |
1754 | 5930 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5931 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5932 { |
1754 | 5933 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5934 |
5935 if (ga_grow(ga, num_p) == OK) | |
7 | 5936 { |
5937 for (i = 0; i < num_p; ++i) | |
5938 { | |
5873 | 5939 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5940 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5941 ++ga->ga_len; |
7 | 5942 } |
5943 } | |
5873 | 5944 |
7 | 5945 FreeWild(num_p, p); |
5946 } | |
5947 } | |
5948 } | |
5949 | |
5950 vim_free(buf); | |
5951 } | |
5952 | |
5953 #endif | |
5954 | |
5955 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5956 | |
5957 /********************************* | |
5958 * Command line history stuff * | |
5959 *********************************/ | |
5960 | |
5961 /* | |
5962 * Translate a history character to the associated type number. | |
5963 */ | |
5964 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5965 hist_char2type(int c) |
7 | 5966 { |
5967 if (c == ':') | |
5968 return HIST_CMD; | |
5969 if (c == '=') | |
5970 return HIST_EXPR; | |
5971 if (c == '@') | |
5972 return HIST_INPUT; | |
5973 if (c == '>') | |
5974 return HIST_DEBUG; | |
5975 return HIST_SEARCH; /* must be '?' or '/' */ | |
5976 } | |
5977 | |
5978 /* | |
5979 * Table of history names. | |
5980 * These names are used in :history and various hist...() functions. | |
5981 * It is sufficient to give the significant prefix of a history name. | |
5982 */ | |
5983 | |
5984 static char *(history_names[]) = | |
5985 { | |
5986 "cmd", | |
5987 "search", | |
5988 "expr", | |
5989 "input", | |
5990 "debug", | |
5991 NULL | |
5992 }; | |
5993 | |
3503 | 5994 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5995 /* | |
5996 * Function given to ExpandGeneric() to obtain the possible first | |
5997 * arguments of the ":history command. | |
5998 */ | |
5999 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6000 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 6001 { |
6002 static char_u compl[2] = { NUL, NUL }; | |
6003 char *short_names = ":=@>?/"; | |
3529 | 6004 int short_names_count = (int)STRLEN(short_names); |
3503 | 6005 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
6006 | |
6007 if (idx < short_names_count) | |
6008 { | |
6009 compl[0] = (char_u)short_names[idx]; | |
6010 return compl; | |
6011 } | |
6012 if (idx < short_names_count + history_name_count) | |
6013 return (char_u *)history_names[idx - short_names_count]; | |
6014 if (idx == short_names_count + history_name_count) | |
6015 return (char_u *)"all"; | |
6016 return NULL; | |
6017 } | |
6018 #endif | |
6019 | |
7 | 6020 /* |
6021 * init_history() - Initialize the command line history. | |
6022 * Also used to re-allocate the history when the size changes. | |
6023 */ | |
356 | 6024 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6025 init_history(void) |
7 | 6026 { |
6027 int newlen; /* new length of history table */ | |
6028 histentry_T *temp; | |
6029 int i; | |
6030 int j; | |
6031 int type; | |
6032 | |
6033 /* | |
6034 * If size of history table changed, reallocate it | |
6035 */ | |
6036 newlen = (int)p_hi; | |
6037 if (newlen != hislen) /* history length changed */ | |
6038 { | |
6039 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6040 { | |
6041 if (newlen) | |
6042 { | |
6043 temp = (histentry_T *)lalloc( | |
6044 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6045 if (temp == NULL) /* out of memory! */ | |
6046 { | |
6047 if (type == 0) /* first one: just keep the old length */ | |
6048 { | |
6049 newlen = hislen; | |
6050 break; | |
6051 } | |
6052 /* Already changed one table, now we can only have zero | |
6053 * length for all tables. */ | |
6054 newlen = 0; | |
6055 type = -1; | |
6056 continue; | |
6057 } | |
6058 } | |
6059 else | |
6060 temp = NULL; | |
6061 if (newlen == 0 || temp != NULL) | |
6062 { | |
6063 if (hisidx[type] < 0) /* there are no entries yet */ | |
6064 { | |
6065 for (i = 0; i < newlen; ++i) | |
4258 | 6066 clear_hist_entry(&temp[i]); |
7 | 6067 } |
6068 else if (newlen > hislen) /* array becomes bigger */ | |
6069 { | |
6070 for (i = 0; i <= hisidx[type]; ++i) | |
6071 temp[i] = history[type][i]; | |
6072 j = i; | |
6073 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6074 clear_hist_entry(&temp[i]); |
7 | 6075 for ( ; j < hislen; ++i, ++j) |
6076 temp[i] = history[type][j]; | |
6077 } | |
6078 else /* array becomes smaller or 0 */ | |
6079 { | |
6080 j = hisidx[type]; | |
6081 for (i = newlen - 1; ; --i) | |
6082 { | |
6083 if (i >= 0) /* copy newest entries */ | |
6084 temp[i] = history[type][j]; | |
6085 else /* remove older entries */ | |
6086 vim_free(history[type][j].hisstr); | |
6087 if (--j < 0) | |
6088 j = hislen - 1; | |
6089 if (j == hisidx[type]) | |
6090 break; | |
6091 } | |
6092 hisidx[type] = newlen - 1; | |
6093 } | |
6094 vim_free(history[type]); | |
6095 history[type] = temp; | |
6096 } | |
6097 } | |
6098 hislen = newlen; | |
6099 } | |
6100 } | |
6101 | |
4258 | 6102 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6103 clear_hist_entry(histentry_T *hisptr) |
4258 | 6104 { |
6105 hisptr->hisnum = 0; | |
6106 hisptr->viminfo = FALSE; | |
6107 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6108 hisptr->time_set = 0; |
4258 | 6109 } |
6110 | |
7 | 6111 /* |
6112 * Check if command line 'str' is already in history. | |
6113 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6114 */ | |
6115 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6116 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6117 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6118 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6119 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
|
6120 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6121 int writing) /* ignore entries read from viminfo */ |
7 | 6122 { |
6123 int i; | |
6124 int last_i = -1; | |
2986 | 6125 char_u *p; |
7 | 6126 |
6127 if (hisidx[type] < 0) | |
6128 return FALSE; | |
6129 i = hisidx[type]; | |
6130 do | |
6131 { | |
6132 if (history[type][i].hisstr == NULL) | |
6133 return FALSE; | |
2986 | 6134 |
6135 /* For search history, check that the separator character matches as | |
6136 * well. */ | |
6137 p = history[type][i].hisstr; | |
6138 if (STRCMP(str, p) == 0 | |
4285 | 6139 && !(writing && history[type][i].viminfo) |
2986 | 6140 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6141 { |
6142 if (!move_to_front) | |
6143 return TRUE; | |
6144 last_i = i; | |
6145 break; | |
6146 } | |
6147 if (--i < 0) | |
6148 i = hislen - 1; | |
6149 } while (i != hisidx[type]); | |
6150 | |
6151 if (last_i >= 0) | |
6152 { | |
6153 str = history[type][i].hisstr; | |
6154 while (i != hisidx[type]) | |
6155 { | |
6156 if (++i >= hislen) | |
6157 i = 0; | |
6158 history[type][last_i] = history[type][i]; | |
6159 last_i = i; | |
6160 } | |
4258 | 6161 history[type][i].hisnum = ++hisnum[type]; |
6162 history[type][i].viminfo = FALSE; | |
7 | 6163 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6164 history[type][i].time_set = vim_time(); |
7 | 6165 return TRUE; |
6166 } | |
6167 return FALSE; | |
6168 } | |
6169 | |
6170 /* | |
6171 * Convert history name (from table above) to its HIST_ equivalent. | |
6172 * When "name" is empty, return "cmd" history. | |
6173 * Returns -1 for unknown history name. | |
6174 */ | |
6175 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6176 get_histtype(char_u *name) |
7 | 6177 { |
6178 int i; | |
6179 int len = (int)STRLEN(name); | |
6180 | |
6181 /* No argument: use current history. */ | |
6182 if (len == 0) | |
6183 return hist_char2type(ccline.cmdfirstc); | |
6184 | |
6185 for (i = 0; history_names[i] != NULL; ++i) | |
6186 if (STRNICMP(name, history_names[i], len) == 0) | |
6187 return i; | |
6188 | |
6189 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6190 return hist_char2type(name[0]); | |
6191 | |
6192 return -1; | |
6193 } | |
6194 | |
6195 static int last_maptick = -1; /* last seen maptick */ | |
6196 | |
6197 /* | |
6198 * Add the given string to the given history. If the string is already in the | |
6199 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6200 * values. | |
6201 */ | |
6202 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6203 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6204 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6205 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6206 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
|
6207 int sep) /* separator character used (search hist) */ |
7 | 6208 { |
6209 histentry_T *hisptr; | |
6210 int len; | |
6211 | |
6212 if (hislen == 0) /* no history */ | |
6213 return; | |
6214 | |
5467 | 6215 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6216 return; | |
6217 | |
7 | 6218 /* |
6219 * Searches inside the same mapping overwrite each other, so that only | |
6220 * the last line is kept. Be careful not to remove a line that was moved | |
6221 * down, only lines that were added. | |
6222 */ | |
6223 if (histype == HIST_SEARCH && in_map) | |
6224 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6225 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6226 { |
6227 /* Current line is from the same mapping, remove it */ | |
6228 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6229 vim_free(hisptr->hisstr); | |
4258 | 6230 clear_hist_entry(hisptr); |
7 | 6231 --hisnum[histype]; |
6232 if (--hisidx[HIST_SEARCH] < 0) | |
6233 hisidx[HIST_SEARCH] = hislen - 1; | |
6234 } | |
6235 last_maptick = -1; | |
6236 } | |
4285 | 6237 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6238 { |
6239 if (++hisidx[histype] == hislen) | |
6240 hisidx[histype] = 0; | |
6241 hisptr = &history[histype][hisidx[histype]]; | |
6242 vim_free(hisptr->hisstr); | |
6243 | |
6244 /* Store the separator after the NUL of the string. */ | |
835 | 6245 len = (int)STRLEN(new_entry); |
7 | 6246 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6247 if (hisptr->hisstr != NULL) | |
6248 hisptr->hisstr[len + 1] = sep; | |
6249 | |
6250 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6251 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6252 hisptr->time_set = vim_time(); |
7 | 6253 if (histype == HIST_SEARCH && in_map) |
6254 last_maptick = maptick; | |
6255 } | |
6256 } | |
6257 | |
6258 #if defined(FEAT_EVAL) || defined(PROTO) | |
6259 | |
6260 /* | |
6261 * Get identifier of newest history entry. | |
6262 * "histype" may be one of the HIST_ values. | |
6263 */ | |
6264 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6265 get_history_idx(int histype) |
7 | 6266 { |
6267 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6268 || hisidx[histype] < 0) | |
6269 return -1; | |
6270 | |
6271 return history[histype][hisidx[histype]].hisnum; | |
6272 } | |
6273 | |
531 | 6274 /* |
7 | 6275 * Calculate history index from a number: |
6276 * num > 0: seen as identifying number of a history entry | |
6277 * num < 0: relative position in history wrt newest entry | |
6278 * "histype" may be one of the HIST_ values. | |
6279 */ | |
6280 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6281 calc_hist_idx(int histype, int num) |
7 | 6282 { |
6283 int i; | |
6284 histentry_T *hist; | |
6285 int wrapped = FALSE; | |
6286 | |
6287 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6288 || (i = hisidx[histype]) < 0 || num == 0) | |
6289 return -1; | |
6290 | |
6291 hist = history[histype]; | |
6292 if (num > 0) | |
6293 { | |
6294 while (hist[i].hisnum > num) | |
6295 if (--i < 0) | |
6296 { | |
6297 if (wrapped) | |
6298 break; | |
6299 i += hislen; | |
6300 wrapped = TRUE; | |
6301 } | |
6302 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6303 return i; | |
6304 } | |
6305 else if (-num <= hislen) | |
6306 { | |
6307 i += num + 1; | |
6308 if (i < 0) | |
6309 i += hislen; | |
6310 if (hist[i].hisstr != NULL) | |
6311 return i; | |
6312 } | |
6313 return -1; | |
6314 } | |
6315 | |
6316 /* | |
6317 * Get a history entry by its index. | |
6318 * "histype" may be one of the HIST_ values. | |
6319 */ | |
6320 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6321 get_history_entry(int histype, int idx) |
7 | 6322 { |
6323 idx = calc_hist_idx(histype, idx); | |
6324 if (idx >= 0) | |
6325 return history[histype][idx].hisstr; | |
6326 else | |
6327 return (char_u *)""; | |
6328 } | |
6329 | |
6330 /* | |
6331 * Clear all entries of a history. | |
6332 * "histype" may be one of the HIST_ values. | |
6333 */ | |
6334 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6335 clr_history(int histype) |
7 | 6336 { |
6337 int i; | |
6338 histentry_T *hisptr; | |
6339 | |
6340 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6341 { | |
6342 hisptr = history[histype]; | |
6343 for (i = hislen; i--;) | |
6344 { | |
6345 vim_free(hisptr->hisstr); | |
4258 | 6346 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6347 hisptr++; |
7 | 6348 } |
6349 hisidx[histype] = -1; /* mark history as cleared */ | |
6350 hisnum[histype] = 0; /* reset identifier counter */ | |
6351 return OK; | |
6352 } | |
6353 return FAIL; | |
6354 } | |
6355 | |
6356 /* | |
6357 * Remove all entries matching {str} from a history. | |
6358 * "histype" may be one of the HIST_ values. | |
6359 */ | |
6360 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6361 del_history_entry(int histype, char_u *str) |
7 | 6362 { |
6363 regmatch_T regmatch; | |
6364 histentry_T *hisptr; | |
6365 int idx; | |
6366 int i; | |
6367 int last; | |
6368 int found = FALSE; | |
6369 | |
6370 regmatch.regprog = NULL; | |
6371 regmatch.rm_ic = FALSE; /* always match case */ | |
6372 if (hislen != 0 | |
6373 && histype >= 0 | |
6374 && histype < HIST_COUNT | |
6375 && *str != NUL | |
6376 && (idx = hisidx[histype]) >= 0 | |
6377 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6378 != NULL) | |
6379 { | |
6380 i = last = idx; | |
6381 do | |
6382 { | |
6383 hisptr = &history[histype][i]; | |
6384 if (hisptr->hisstr == NULL) | |
6385 break; | |
6386 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6387 { | |
6388 found = TRUE; | |
6389 vim_free(hisptr->hisstr); | |
4258 | 6390 clear_hist_entry(hisptr); |
7 | 6391 } |
6392 else | |
6393 { | |
6394 if (i != last) | |
6395 { | |
6396 history[histype][last] = *hisptr; | |
4258 | 6397 clear_hist_entry(hisptr); |
7 | 6398 } |
6399 if (--last < 0) | |
6400 last += hislen; | |
6401 } | |
6402 if (--i < 0) | |
6403 i += hislen; | |
6404 } while (i != idx); | |
6405 if (history[histype][idx].hisstr == NULL) | |
6406 hisidx[histype] = -1; | |
6407 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6408 vim_regfree(regmatch.regprog); |
7 | 6409 return found; |
6410 } | |
6411 | |
6412 /* | |
6413 * Remove an indexed entry from a history. | |
6414 * "histype" may be one of the HIST_ values. | |
6415 */ | |
6416 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6417 del_history_idx(int histype, int idx) |
7 | 6418 { |
6419 int i, j; | |
6420 | |
6421 i = calc_hist_idx(histype, idx); | |
6422 if (i < 0) | |
6423 return FALSE; | |
6424 idx = hisidx[histype]; | |
6425 vim_free(history[histype][i].hisstr); | |
6426 | |
6427 /* When deleting the last added search string in a mapping, reset | |
6428 * last_maptick, so that the last added search string isn't deleted again. | |
6429 */ | |
6430 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6431 last_maptick = -1; | |
6432 | |
6433 while (i != idx) | |
6434 { | |
6435 j = (i + 1) % hislen; | |
6436 history[histype][i] = history[histype][j]; | |
6437 i = j; | |
6438 } | |
4258 | 6439 clear_hist_entry(&history[histype][i]); |
7 | 6440 if (--i < 0) |
6441 i += hislen; | |
6442 hisidx[histype] = i; | |
6443 return TRUE; | |
6444 } | |
6445 | |
6446 #endif /* FEAT_EVAL */ | |
6447 | |
6448 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6449 /* | |
6450 * Very specific function to remove the value in ":set key=val" from the | |
6451 * history. | |
6452 */ | |
6453 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6454 remove_key_from_history(void) |
7 | 6455 { |
6456 char_u *p; | |
6457 int i; | |
6458 | |
6459 i = hisidx[HIST_CMD]; | |
6460 if (i < 0) | |
6461 return; | |
6462 p = history[HIST_CMD][i].hisstr; | |
6463 if (p != NULL) | |
6464 for ( ; *p; ++p) | |
6465 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6466 { | |
6467 p = vim_strchr(p + 3, '='); | |
6468 if (p == NULL) | |
6469 break; | |
6470 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6471 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6472 if (p[i] == '\\' && p[i + 1]) |
6473 ++i; | |
1621 | 6474 STRMOVE(p, p + i); |
7 | 6475 --p; |
6476 } | |
6477 } | |
6478 #endif | |
6479 | |
6480 #endif /* FEAT_CMDHIST */ | |
6481 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6482 #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
|
6483 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 * 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
|
6485 * 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
|
6486 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6487 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6488 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6489 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6490 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 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
|
6495 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6496 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6498 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6499 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6500 #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
|
6501 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 * 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
|
6503 * 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
|
6504 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6506 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6507 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 { |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6509 struct cmdline_info *p; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6510 |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6511 if (cmdline_star > 0) |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6512 return NULL; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6513 p = get_ccline_ptr(); |
8645
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 NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6516 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
|
6517 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6519 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 * 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
|
6521 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6522 * 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
|
6523 * Returns -1 when something is wrong. |
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 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6526 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6527 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6528 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
|
6529 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6532 return p->cmdpos; |
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 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6535 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6536 * 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
|
6537 * 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
|
6538 * 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
|
6539 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6541 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6542 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6543 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6544 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
|
6545 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6546 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6547 return 1; |
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 /* 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
|
6550 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6551 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6552 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6553 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6554 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6555 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6556 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6557 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6558 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6559 #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
|
6560 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6561 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6562 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6563 * 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
|
6564 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6565 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6566 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6567 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6568 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6569 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
|
6570 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6571 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6572 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6573 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6574 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6575 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6576 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6577 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6578 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6579 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6580 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6581 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6582 |
7 | 6583 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6584 /* | |
6585 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6586 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6587 * Returns OK if parsed successfully, otherwise FAIL. | |
6588 */ | |
6589 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6590 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6591 { |
6592 int len; | |
6593 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6594 varnumber_T num; |
7 | 6595 |
6596 *str = skipwhite(*str); | |
6597 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6598 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6599 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6600 *str += len; |
6601 *num1 = (int)num; | |
6602 first = TRUE; | |
6603 } | |
6604 *str = skipwhite(*str); | |
6605 if (**str == ',') /* parse "to" part of range */ | |
6606 { | |
6607 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6608 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6609 if (len > 0) |
6610 { | |
6611 *num2 = (int)num; | |
6612 *str = skipwhite(*str + len); | |
6613 } | |
6614 else if (!first) /* no number given at all */ | |
6615 return FAIL; | |
6616 } | |
6617 else if (first) /* only one number given */ | |
6618 *num2 = *num1; | |
6619 return OK; | |
6620 } | |
6621 #endif | |
6622 | |
6623 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6624 /* | |
6625 * :history command - print a history | |
6626 */ | |
6627 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6628 ex_history(exarg_T *eap) |
7 | 6629 { |
6630 histentry_T *hist; | |
6631 int histype1 = HIST_CMD; | |
6632 int histype2 = HIST_CMD; | |
6633 int hisidx1 = 1; | |
6634 int hisidx2 = -1; | |
6635 int idx; | |
6636 int i, j, k; | |
6637 char_u *end; | |
6638 char_u *arg = eap->arg; | |
6639 | |
6640 if (hislen == 0) | |
6641 { | |
6642 MSG(_("'history' option is zero")); | |
6643 return; | |
6644 } | |
6645 | |
6646 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6647 { | |
6648 end = arg; | |
6649 while (ASCII_ISALPHA(*end) | |
6650 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6651 end++; | |
6652 i = *end; | |
6653 *end = NUL; | |
6654 histype1 = get_histtype(arg); | |
6655 if (histype1 == -1) | |
6656 { | |
1853 | 6657 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6658 { |
6659 histype1 = 0; | |
6660 histype2 = HIST_COUNT-1; | |
6661 } | |
6662 else | |
6663 { | |
6664 *end = i; | |
6665 EMSG(_(e_trailing)); | |
6666 return; | |
6667 } | |
6668 } | |
6669 else | |
6670 histype2 = histype1; | |
6671 *end = i; | |
6672 } | |
6673 else | |
6674 end = arg; | |
6675 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6676 { | |
6677 EMSG(_(e_trailing)); | |
6678 return; | |
6679 } | |
6680 | |
6681 for (; !got_int && histype1 <= histype2; ++histype1) | |
6682 { | |
6683 STRCPY(IObuff, "\n # "); | |
6684 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6685 MSG_PUTS_TITLE(IObuff); | |
6686 idx = hisidx[histype1]; | |
6687 hist = history[histype1]; | |
6688 j = hisidx1; | |
6689 k = hisidx2; | |
6690 if (j < 0) | |
6691 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6692 if (k < 0) | |
6693 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6694 if (idx >= 0 && j <= k) | |
6695 for (i = idx + 1; !got_int; ++i) | |
6696 { | |
6697 if (i == hislen) | |
6698 i = 0; | |
6699 if (hist[i].hisstr != NULL | |
6700 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6701 { | |
6702 msg_putchar('\n'); | |
6703 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6704 hist[i].hisnum); | |
6705 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6706 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6707 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6708 else |
6709 STRCAT(IObuff, hist[i].hisstr); | |
6710 msg_outtrans(IObuff); | |
6711 out_flush(); | |
6712 } | |
6713 if (i == idx) | |
6714 break; | |
6715 } | |
6716 } | |
6717 } | |
6718 #endif | |
6719 | |
6720 #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
|
6721 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6722 * 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
|
6723 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6724 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
|
6725 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6726 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
|
6727 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6728 static int viminfo_add_at_front = FALSE; |
6729 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6730 static int hist_type2char(int type, int use_question); |
7 | 6731 |
6732 /* | |
6733 * Translate a history type number to the associated character. | |
6734 */ | |
6735 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6736 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6737 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6738 int use_question) /* use '?' instead of '/' */ |
7 | 6739 { |
6740 if (type == HIST_CMD) | |
6741 return ':'; | |
6742 if (type == HIST_SEARCH) | |
6743 { | |
6744 if (use_question) | |
6745 return '?'; | |
6746 else | |
6747 return '/'; | |
6748 } | |
6749 if (type == HIST_EXPR) | |
6750 return '='; | |
6751 return '@'; | |
6752 } | |
6753 | |
6754 /* | |
6755 * Prepare for reading the history from the viminfo file. | |
6756 * This allocates history arrays to store the read history lines. | |
6757 */ | |
6758 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6759 prepare_viminfo_history(int asklen, int writing) |
7 | 6760 { |
6761 int i; | |
6762 int num; | |
6763 int type; | |
6764 int len; | |
6765 | |
6766 init_history(); | |
4285 | 6767 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6768 if (asklen > hislen) |
6769 asklen = hislen; | |
6770 | |
6771 for (type = 0; type < HIST_COUNT; ++type) | |
6772 { | |
4258 | 6773 /* Count the number of empty spaces in the history list. Entries read |
6774 * from viminfo previously are also considered empty. If there are | |
6775 * more spaces available than we request, then fill them up. */ | |
7 | 6776 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6777 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6778 num++; |
6779 len = asklen; | |
6780 if (num > len) | |
6781 len = num; | |
6782 if (len <= 0) | |
6783 viminfo_history[type] = NULL; | |
6784 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6785 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6787 if (viminfo_history[type] == NULL) |
6788 len = 0; | |
6789 viminfo_hislen[type] = len; | |
6790 viminfo_hisidx[type] = 0; | |
6791 } | |
6792 } | |
6793 | |
6794 /* | |
6795 * Accept a line from the viminfo, store it in the history array when it's | |
6796 * new. | |
6797 */ | |
6798 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6799 read_viminfo_history(vir_T *virp, int writing) |
7 | 6800 { |
6801 int type; | |
6802 long_u len; | |
6803 char_u *val; | |
6804 char_u *p; | |
6805 | |
6806 type = hist_char2type(virp->vir_line[0]); | |
6807 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6808 { | |
6809 val = viminfo_readstring(virp, 1, TRUE); | |
6810 if (val != NULL && *val != NUL) | |
6811 { | |
3316 | 6812 int sep = (*val == ' ' ? NUL : *val); |
6813 | |
7 | 6814 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6815 viminfo_add_at_front, sep, writing)) |
7 | 6816 { |
6817 /* Need to re-allocate to append the separator byte. */ | |
6818 len = STRLEN(val); | |
6819 p = lalloc(len + 2, TRUE); | |
6820 if (p != NULL) | |
6821 { | |
6822 if (type == HIST_SEARCH) | |
6823 { | |
6824 /* Search entry: Move the separator from the first | |
6825 * column to after the NUL. */ | |
6826 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6827 p[len] = sep; |
7 | 6828 } |
6829 else | |
6830 { | |
6831 /* Not a search entry: No separator in the viminfo | |
6832 * file, add a NUL separator. */ | |
6833 mch_memmove(p, val, (size_t)len + 1); | |
6834 p[len + 1] = NUL; | |
6835 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 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
|
6837 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
|
6838 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
|
6839 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
|
6840 viminfo_hisidx[type]++; |
7 | 6841 } |
6842 } | |
6843 } | |
6844 vim_free(val); | |
6845 } | |
6846 return viminfo_readline(virp); | |
6847 } | |
6848 | |
4285 | 6849 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6850 * 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
|
6851 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6855 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6856 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6857 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6858 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6859 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6862 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
|
6863 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6864 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6865 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6866 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6867 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6868 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6869 || (vp[2].bv_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
|
6870 || 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
|
6871 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6872 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6873 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6874 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6875 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6876 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
|
6877 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6878 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6879 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6880 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6881 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
|
6882 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6883 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6885 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6886 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
|
6887 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6888 /* 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
|
6889 * 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
|
6890 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
|
6891 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6892 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6893 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6894 && (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
|
6895 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6896 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6897 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6898 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6899 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6900 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6901 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6902 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6903 /* 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
|
6904 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6905 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6906 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6907 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6908 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6909 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6910 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6911 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
|
6912 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6913 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6914 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
|
6915 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6916 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6917 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
|
6918 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 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
|
6920 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6921 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6922 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6923 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6924 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6925 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6926 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6927 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6928 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 * 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
|
6930 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 idx = hislen - 1; |
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 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
|
6960 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6962 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
|
6963 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 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
|
6965 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 idx = hislen - 1; |
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 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 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
|
6971 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 #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
|
6978 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6979 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6982 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
|
6983 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6984 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6985 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6986 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 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
|
6988 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
|
6989 return 0; |
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 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6993 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 * 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
|
6995 * timestamp; |
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 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6999 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7000 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7003 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7004 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7005 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 /* 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
|
7007 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7008 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
|
7009 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
|
7010 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
|
7011 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7012 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7013 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7014 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7015 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 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
|
7017 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
|
7018 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7020 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7021 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7022 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7023 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7024 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
|
7025 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7026 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7027 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7028 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7029 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7030 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7031 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7032 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7033 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7034 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7035 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7036 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7037 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7038 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7039 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
|
7040 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7041 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7042 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
|
7043 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
|
7044 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7045 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7046 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7047 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7048 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7049 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7050 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7051 /* |
4285 | 7052 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7053 */ | |
7 | 7054 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7055 finish_viminfo_history(vir_T *virp) |
7 | 7056 { |
7057 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7058 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7059 |
7060 for (type = 0; type < HIST_COUNT; ++type) | |
7061 { | |
7062 if (history[type] == NULL) | |
4283 | 7063 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7064 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7065 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7066 merge_history(type); |
7 | 7067 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7068 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7069 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7070 VIM_CLEAR(viminfo_history[type]); |
4327 | 7071 viminfo_hisidx[type] = 0; |
7 | 7072 } |
7073 } | |
7074 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7075 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7076 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7077 * 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
|
7078 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7079 * 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
|
7080 */ |
7 | 7081 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7082 write_viminfo_history(FILE *fp, int merge) |
7 | 7083 { |
7084 int i; | |
7085 int type; | |
7086 int num_saved; | |
4283 | 7087 int round; |
7 | 7088 |
7089 init_history(); | |
7090 if (hislen == 0) | |
7091 return; | |
7092 for (type = 0; type < HIST_COUNT; ++type) | |
7093 { | |
7094 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7095 if (num_saved == 0) | |
7096 continue; | |
7097 if (num_saved < 0) /* Use default */ | |
7098 num_saved = hislen; | |
7099 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7100 type == HIST_CMD ? _("Command Line") : | |
7101 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7102 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7103 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7104 _("Debug Line")); |
7 | 7105 if (num_saved > hislen) |
7106 num_saved = hislen; | |
4283 | 7107 |
7108 /* | |
7109 * Merge typed and viminfo history: | |
7110 * round 1: history of typed commands. | |
7111 * round 2: history from recently read viminfo. | |
7112 */ | |
7113 for (round = 1; round <= 2; ++round) | |
7114 { | |
4307 | 7115 if (round == 1) |
7116 /* start at newest entry, somewhere in the list */ | |
7117 i = hisidx[type]; | |
7118 else if (viminfo_hisidx[type] > 0) | |
7119 /* start at newest entry, first in the list */ | |
7120 i = 0; | |
7121 else | |
7122 /* empty list */ | |
7123 i = -1; | |
4283 | 7124 if (i >= 0) |
7125 while (num_saved > 0 | |
7126 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7127 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7128 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7129 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7130 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7131 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7132 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7133 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7134 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7135 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7136 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7137 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7138 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7139 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7140 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7141 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7142 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7143 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7144 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7145 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7146 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7147 || !history[type][i].viminfo)) |
7 | 7148 { |
4283 | 7149 --num_saved; |
7150 fputc(hist_type2char(type, TRUE), fp); | |
7151 /* For the search history: put the separator in the | |
7152 * second column; use a space if there isn't one. */ | |
7153 if (type == HIST_SEARCH) | |
7154 { | |
7155 c = p[STRLEN(p) + 1]; | |
7156 putc(c == NUL ? ' ' : c, fp); | |
7157 } | |
7158 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7159 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7160 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7161 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7162 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7163 /* 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
|
7164 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7165 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7166 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7167 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7168 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7169 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
|
7170 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7171 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7172 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7173 } |
7 | 7174 } |
4283 | 7175 if (round == 1) |
7176 { | |
7177 /* Decrement index, loop around and stop when back at | |
7178 * the start. */ | |
7179 if (--i < 0) | |
7180 i = hislen - 1; | |
7181 if (i == hisidx[type]) | |
7182 break; | |
7183 } | |
7184 else | |
7185 { | |
7186 /* Increment index. Stop at the end in the while. */ | |
7187 ++i; | |
7188 } | |
7 | 7189 } |
4283 | 7190 } |
4285 | 7191 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7192 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7193 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
|
7194 VIM_CLEAR(viminfo_history[type]); |
4311 | 7195 viminfo_hisidx[type] = 0; |
7 | 7196 } |
7197 } | |
7198 #endif /* FEAT_VIMINFO */ | |
7199 | |
7200 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7201 /* | |
7202 * Write a character at the current cursor+offset position. | |
7203 * It is directly written into the command buffer block. | |
7204 */ | |
7205 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7206 cmd_pchar(int c, int offset) |
7 | 7207 { |
7208 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7209 { | |
7210 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7211 return; | |
7212 } | |
7213 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7214 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7215 } | |
7216 | |
7217 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7218 cmd_gchar(int offset) |
7 | 7219 { |
7220 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7221 { | |
7222 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7223 return NUL; | |
7224 } | |
7225 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7226 } | |
7227 #endif | |
7228 | |
7229 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7230 /* | |
7231 * Open a window on the current command line and history. Allow editing in | |
7232 * the window. Returns when the window is closed. | |
7233 * Returns: | |
7234 * CR if the command is to be executed | |
7235 * Ctrl_C if it is to be abandoned | |
7236 * K_IGNORE if editing continues | |
7237 */ | |
7238 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
|
7239 open_cmdwin(void) |
7 | 7240 { |
7241 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7242 bufref_T old_curbuf; |
7 | 7243 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7244 bufref_T bufref; |
7 | 7245 win_T *wp; |
7246 int i; | |
7247 linenr_T lnum; | |
7248 int histtype; | |
7249 garray_T winsizes; | |
7250 int save_restart_edit = restart_edit; | |
7251 int save_State = State; | |
7252 int save_exmode = exmode_active; | |
510 | 7253 #ifdef FEAT_RIGHTLEFT |
7254 int save_cmdmsg_rl = cmdmsg_rl; | |
7255 #endif | |
6145 | 7256 #ifdef FEAT_FOLDING |
7257 int save_KeyTyped; | |
7258 #endif | |
7 | 7259 |
7260 /* Can't do this recursively. Can't do it when typing a password. */ | |
7261 if (cmdwin_type != 0 | |
7262 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7263 || cmdline_star > 0 | |
7264 # endif | |
7265 ) | |
7266 { | |
7267 beep_flush(); | |
7268 return K_IGNORE; | |
7269 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7270 set_bufref(&old_curbuf, curbuf); |
7 | 7271 |
7272 /* Save current window sizes. */ | |
7273 win_size_save(&winsizes); | |
7274 | |
7275 /* Don't execute autocommands while creating the window. */ | |
1410 | 7276 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7277 |
683 | 7278 /* don't use a new tab page */ |
7279 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
|
7280 cmdmod.noswapfile = 1; |
683 | 7281 |
7 | 7282 /* Create a window for the command-line buffer. */ |
7283 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7284 { | |
7285 beep_flush(); | |
1410 | 7286 unblock_autocmds(); |
7 | 7287 return K_IGNORE; |
7288 } | |
1831 | 7289 cmdwin_type = get_cmdline_type(); |
7 | 7290 |
7291 /* Create the command-line buffer empty. */ | |
1743 | 7292 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7293 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7294 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7295 curbuf->b_p_ma = TRUE; | |
1865 | 7296 #ifdef FEAT_FOLDING |
7297 curwin->w_p_fen = FALSE; | |
7298 #endif | |
7 | 7299 # ifdef FEAT_RIGHTLEFT |
510 | 7300 curwin->w_p_rl = cmdmsg_rl; |
7301 cmdmsg_rl = FALSE; | |
7 | 7302 # endif |
2583 | 7303 RESET_BINDING(curwin); |
7 | 7304 |
7305 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7306 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7307 /* 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
|
7308 ++curbuf_lock; |
7 | 7309 |
510 | 7310 /* Showing the prompt may have set need_wait_return, reset it. */ |
7311 need_wait_return = FALSE; | |
7312 | |
1831 | 7313 histtype = hist_char2type(cmdwin_type); |
7 | 7314 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7315 { | |
7316 if (p_wc == TAB) | |
7317 { | |
7318 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7319 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7320 } | |
7321 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7322 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7323 --curbuf_lock; |
7 | 7324 |
10 | 7325 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7326 * sets 'textwidth' to 78). */ | |
7327 curbuf->b_p_tw = 0; | |
7328 | |
7 | 7329 /* Fill the buffer with the history. */ |
7330 init_history(); | |
7331 if (hislen > 0) | |
7332 { | |
7333 i = hisidx[histtype]; | |
7334 if (i >= 0) | |
7335 { | |
7336 lnum = 0; | |
7337 do | |
7338 { | |
7339 if (++i == hislen) | |
7340 i = 0; | |
7341 if (history[histtype][i].hisstr != NULL) | |
7342 ml_append(lnum++, history[histtype][i].hisstr, | |
7343 (colnr_T)0, FALSE); | |
7344 } | |
7345 while (i != hisidx[histtype]); | |
7346 } | |
7347 } | |
7348 | |
7349 /* Replace the empty last line with the current command-line and put the | |
7350 * cursor there. */ | |
7351 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7352 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7353 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7354 changed_line_abv_curs(); |
7355 invalidate_botline(); | |
743 | 7356 redraw_later(SOME_VALID); |
7 | 7357 |
7358 /* 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
|
7359 save_cmdline(&save_ccline); |
7 | 7360 |
7361 /* No Ex mode here! */ | |
7362 exmode_active = 0; | |
7363 | |
7364 State = NORMAL; | |
7365 # ifdef FEAT_MOUSE | |
7366 setmouse(); | |
7367 # endif | |
7368 | |
7369 /* 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
|
7370 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7371 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7372 stuffcharReadbuff(K_NOP); | |
7 | 7373 |
7374 i = RedrawingDisabled; | |
7375 RedrawingDisabled = 0; | |
7376 | |
7377 /* | |
7378 * Call the main loop until <CR> or CTRL-C is typed. | |
7379 */ | |
7380 cmdwin_result = 0; | |
168 | 7381 main_loop(TRUE, FALSE); |
7 | 7382 |
7383 RedrawingDisabled = i; | |
7384 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7385 # ifdef FEAT_FOLDING |
6145 | 7386 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7387 # endif |
6145 | 7388 |
7 | 7389 /* 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
|
7390 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7391 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7392 # ifdef FEAT_FOLDING |
6145 | 7393 /* Restore KeyTyped in case it is modified by autocommands */ |
7394 KeyTyped = save_KeyTyped; | |
7 | 7395 # endif |
7396 | |
1214 | 7397 /* 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
|
7398 restore_cmdline(&save_ccline); |
7 | 7399 cmdwin_type = 0; |
7400 | |
7401 exmode_active = save_exmode; | |
7402 | |
1612 | 7403 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7404 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7405 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7406 { |
7407 cmdwin_result = Ctrl_C; | |
7408 EMSG(_("E199: Active window or buffer deleted")); | |
7409 } | |
7410 else | |
7411 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7412 # if defined(FEAT_EVAL) |
7 | 7413 /* autocmds may abort script processing */ |
7414 if (aborting() && cmdwin_result != K_IGNORE) | |
7415 cmdwin_result = Ctrl_C; | |
7416 # endif | |
7417 /* Set the new command line from the cmdline buffer. */ | |
7418 vim_free(ccline.cmdbuff); | |
510 | 7419 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7420 { |
510 | 7421 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7422 | |
7423 if (histtype == HIST_CMD) | |
7424 { | |
7425 /* Execute the command directly. */ | |
7426 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7427 cmdwin_result = CAR; | |
7428 } | |
7429 else | |
7430 { | |
7431 /* First need to cancel what we were doing. */ | |
7432 ccline.cmdbuff = NULL; | |
7433 stuffcharReadbuff(':'); | |
7434 stuffReadbuff((char_u *)p); | |
7435 stuffcharReadbuff(CAR); | |
7436 } | |
7 | 7437 } |
7438 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7439 { | |
7440 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7441 cmdwin_result = CAR; | |
7442 } | |
2839 | 7443 else if (cmdwin_result == Ctrl_C) |
7444 { | |
7445 /* :q or :close, don't execute any command | |
7446 * and don't modify the cmd window. */ | |
7447 ccline.cmdbuff = NULL; | |
7448 } | |
7 | 7449 else |
7450 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7451 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
|
7452 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7453 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
|
7454 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
|
7455 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
|
7456 ccline.cmdpos = 0; |
7 | 7457 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
|
7458 } |
7 | 7459 else |
7460 { | |
7461 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7462 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7463 ccline.cmdpos = curwin->w_cursor.col; | |
7464 if (ccline.cmdpos > ccline.cmdlen) | |
7465 ccline.cmdpos = ccline.cmdlen; | |
7466 if (cmdwin_result == K_IGNORE) | |
7467 { | |
7468 set_cmdspos_cursor(); | |
7469 redrawcmd(); | |
7470 } | |
7471 } | |
7472 | |
7473 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7474 block_autocmds(); |
6876 | 7475 # ifdef FEAT_CONCEAL |
7476 /* Avoid command-line window first character being concealed. */ | |
7477 curwin->w_p_cole = 0; | |
7478 # endif | |
7 | 7479 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7480 set_bufref(&bufref, curbuf); |
7 | 7481 win_goto(old_curwin); |
7482 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7483 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7484 /* 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
|
7485 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7486 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7487 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7488 |
7489 /* Restore window sizes. */ | |
7490 win_size_restore(&winsizes); | |
7491 | |
1410 | 7492 unblock_autocmds(); |
7 | 7493 } |
7494 | |
7495 ga_clear(&winsizes); | |
7496 restart_edit = save_restart_edit; | |
510 | 7497 # ifdef FEAT_RIGHTLEFT |
7498 cmdmsg_rl = save_cmdmsg_rl; | |
7499 # endif | |
7 | 7500 |
7501 State = save_State; | |
7502 # ifdef FEAT_MOUSE | |
7503 setmouse(); | |
7504 # endif | |
7505 | |
7506 return cmdwin_result; | |
7507 } | |
7508 #endif /* FEAT_CMDWIN */ | |
7509 | |
7510 /* | |
7511 * Used for commands that either take a simple command string argument, or: | |
7512 * cmd << endmarker | |
7513 * {script} | |
7514 * endmarker | |
7515 * Returns a pointer to allocated memory with {script} or NULL. | |
7516 */ | |
7517 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7518 script_get(exarg_T *eap, char_u *cmd) |
7 | 7519 { |
7520 char_u *theline; | |
7521 char *end_pattern = NULL; | |
7522 char dot[] = "."; | |
7523 garray_T ga; | |
7524 | |
7525 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7526 return NULL; | |
7527 | |
7528 ga_init2(&ga, 1, 0x400); | |
7529 | |
7530 if (cmd[2] != NUL) | |
7531 end_pattern = (char *)skipwhite(cmd + 2); | |
7532 else | |
7533 end_pattern = dot; | |
7534 | |
7535 for (;;) | |
7536 { | |
7537 theline = eap->getline( | |
7538 #ifdef FEAT_EVAL | |
75 | 7539 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7540 #endif |
7541 NUL, eap->cookie, 0); | |
7542 | |
7543 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7544 { |
7545 vim_free(theline); | |
7 | 7546 break; |
1694 | 7547 } |
7 | 7548 |
7549 ga_concat(&ga, theline); | |
7550 ga_append(&ga, '\n'); | |
7551 vim_free(theline); | |
7552 } | |
21 | 7553 ga_append(&ga, NUL); |
7 | 7554 |
7555 return (char_u *)ga.ga_data; | |
7556 } |