Mercurial > vim
annotate src/ex_getln.c @ 14613:3f9b73cc8adb v8.1.0320
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
commit https://github.com/vim/vim/commit/8b0d5ce881ac16a36ea00018ba13a58b0fdb7534
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 22 23:05:44 2018 +0200
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Problem: Too much 'incsearch' highlight for pattern matching everything.
Solution: Add the skiplen to the command and remove the line range.
(Christian Brabandt) Check for empty pattern earlier.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 22 Aug 2018 23:15:06 +0200 |
parents | 5e038972cafa |
children | c6b41d47bac1 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
1718 | 47 /* The current cmdline_info. It is initialized in getcmdline() and after that |
48 * used by other functions. When invoking getcmdline() recursively it needs | |
49 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
50 * TODO: make it local to getcmdline() and pass it around. */ | |
51 static struct cmdline_info ccline; | |
7 | 52 |
53 static int cmd_showtail; /* Only show path tail in lists ? */ | |
54 | |
55 #ifdef FEAT_EVAL | |
56 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
57 #endif | |
58 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
60 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
62 |
7 | 63 #ifdef FEAT_CMDHIST |
64 typedef struct hist_entry | |
65 { | |
66 int hisnum; /* identifying number */ | |
4258 | 67 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 68 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
69 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 70 } histentry_T; |
71 | |
72 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
73 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
74 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
75 /* identifying (unique) number of newest history entry */ | |
76 static int hislen = 0; /* actual length of history tables */ | |
77 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
80 static int in_history(int, char_u *, int, int, int); |
7 | 81 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
82 static int calc_hist_idx(int histype, int num); |
7 | 83 # endif |
84 #endif | |
85 | |
86 #ifdef FEAT_RIGHTLEFT | |
87 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
88 #endif | |
89 | |
90 #ifdef FEAT_FKMAP | |
91 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
92 #endif | |
93 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
117 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
119 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
123 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
129 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
156 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
157 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
159 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
274 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
278 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
279 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
281 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
283 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 char_u *end; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
285 char_u *dummy; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
288 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
289 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
293 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
333 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
337 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
343 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
347 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
350 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
351 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
353 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
354 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
355 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
356 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
357 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
358 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
359 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
360 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
362 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
363 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
364 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
365 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
366 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
368 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
369 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
371 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
372 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
374 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
376 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
377 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
378 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
379 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
380 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
381 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
382 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
383 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 curwin->w_cursor = is_state->search_start; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 parse_cmd_address(&ea, &dummy); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
391 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
397 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
398 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
401 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
402 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
403 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
404 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
405 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
406 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
407 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
408 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
409 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
410 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
411 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
412 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
413 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
414 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
416 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
430 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
436 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
440 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
|
441 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
|
442 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
443 redraw_all_later(SOME_VALID); |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
444 p_magic = is_state->magic_save; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
445 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
446 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 * 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
|
450 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 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
|
453 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 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
|
456 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
457 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
|
458 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 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
|
460 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
|
461 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
463 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
464 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
465 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
|
466 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
467 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
468 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
469 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
|
470 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
471 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
472 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 // 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
|
474 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 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
|
477 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 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
|
480 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
481 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
|
482 // 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
|
483 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
|
484 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
485 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
486 // 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
|
487 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
|
488 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
|
489 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
492 // 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
|
493 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
|
494 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
|
495 && 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
|
496 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
497 // 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
|
498 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
|
499 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 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
|
502 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
|
503 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
504 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 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
|
507 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 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
|
509 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 ++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
|
511 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 // 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
|
513 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
|
514 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 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
|
517 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
|
518 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
|
519 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
520 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
521 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
|
522 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
528 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
|
529 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 |
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 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
|
532 || 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
|
533 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
534 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
535 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
536 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
|
537 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
538 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 // 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
|
540 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 (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
|
543 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
545 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 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
|
547 // 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
|
548 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
|
549 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 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
|
552 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 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
|
554 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 // 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
|
556 // 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
|
557 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
|
558 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
|
559 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
563 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
|
564 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 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
|
566 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
|
567 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
573 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
|
574 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
576 // 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
|
577 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
|
578 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
|
579 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 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
|
584 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 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
|
588 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 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
|
592 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
595 * 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
|
596 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 * 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
|
598 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 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
|
601 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
|
602 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 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
|
604 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
606 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
|
607 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 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
|
610 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
|
611 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
|
612 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
613 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
615 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
618 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
|
619 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 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
|
621 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
622 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
|
623 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 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
|
625 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
|
626 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 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
|
631 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 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
|
633 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
|
634 // 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
|
635 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 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
|
638 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 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
|
641 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 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
|
643 ++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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 --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
|
651 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
|
652 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 // 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
|
660 // 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
|
661 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
|
662 (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
|
663 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 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
|
665 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 // 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
|
667 // 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
|
668 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
|
669 (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
|
670 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 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
|
672 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 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
|
675 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 (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
|
677 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 (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
|
679 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
687 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
|
688 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
|
689 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 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
|
693 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
|
694 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
695 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
696 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
697 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 * 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
|
699 * 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
|
700 * 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
|
701 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 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
|
704 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
705 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
|
706 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
707 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
709 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
710 // 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
|
711 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
|
712 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 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
|
714 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
|
715 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
716 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
717 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
718 // 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
|
719 // 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
|
720 // 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
|
721 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
|
722 *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
|
723 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
724 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 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
|
726 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
|
727 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
728 // 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
|
729 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 *c = '\\'; |
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 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
733 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
734 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
735 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
736 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
737 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
738 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
739 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
740 /* |
7 | 741 * getcmdline() - accept a command line starting with firstc. |
742 * | |
743 * firstc == ':' get ":" command line. | |
744 * firstc == '/' or '?' get search pattern | |
745 * firstc == '=' get expression | |
746 * firstc == '@' get text for input() function | |
747 * firstc == '>' get text for debug mode | |
748 * firstc == NUL get text for :insert command | |
749 * firstc == -1 like NUL, and break on CTRL-C | |
750 * | |
751 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
752 * command line. | |
753 * | |
754 * Careful: getcmdline() can be called recursively! | |
755 * | |
756 * Return pointer to allocated string if there is a commandline, NULL | |
757 * otherwise. | |
758 */ | |
759 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
760 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
761 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
762 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
|
763 int indent) /* indent for inside conditionals */ |
7 | 764 { |
765 int c; | |
766 int i; | |
767 int j; | |
768 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
769 int do_abbr; /* when TRUE check for abbr. */ | |
770 #ifdef FEAT_CMDHIST | |
771 char_u *lookfor = NULL; /* string to match */ | |
772 int hiscnt; /* current history line in use */ | |
773 int histype; /* history type to be used */ | |
774 #endif | |
775 #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
|
776 incsearch_state_T is_state; |
7 | 777 #endif |
778 int did_wild_list = FALSE; /* did wild_list() recently */ | |
779 int wim_index = 0; /* index in wim_flags[] */ | |
780 int res; | |
781 int save_msg_scroll = msg_scroll; | |
782 int save_State = State; /* remember State when called */ | |
783 int some_key_typed = FALSE; /* one of the keys was typed */ | |
784 #ifdef FEAT_MOUSE | |
785 /* mouse drag and release events are ignored, unless they are | |
786 * preceded with a mouse down event */ | |
787 int ignore_drag_release = TRUE; | |
788 #endif | |
789 #ifdef FEAT_EVAL | |
790 int break_ctrl_c = FALSE; | |
791 #endif | |
792 expand_T xpc; | |
793 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
|
794 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 795 /* Everything that may work recursively should save and restore the |
796 * current command line in save_ccline. That includes update_screen(), a | |
797 * custom status line may invoke ":normal". */ | |
798 struct cmdline_info save_ccline; | |
799 #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
|
800 int cmdline_type; |
7 | 801 |
802 #ifdef FEAT_EVAL | |
803 if (firstc == -1) | |
804 { | |
805 firstc = NUL; | |
806 break_ctrl_c = TRUE; | |
807 } | |
808 #endif | |
809 #ifdef FEAT_RIGHTLEFT | |
810 /* start without Hebrew mapping for a command line */ | |
811 if (firstc == ':' || firstc == '=' || firstc == '>') | |
812 cmd_hkmap = 0; | |
813 #endif | |
814 | |
815 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
|
816 |
7 | 817 #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
|
818 init_incsearch_state(&is_state); |
7 | 819 #endif |
820 | |
821 /* | |
822 * set some variables for redrawcmd() | |
823 */ | |
824 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 825 ccline.cmdindent = (firstc > 0 ? indent : 0); |
826 | |
827 /* alloc initial ccline.cmdbuff */ | |
828 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 829 if (ccline.cmdbuff == NULL) |
830 return NULL; /* out of memory */ | |
831 ccline.cmdlen = ccline.cmdpos = 0; | |
832 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
|
833 sb_text_start_cmdline(); |
7 | 834 |
164 | 835 /* autoindent for :insert and :append */ |
836 if (firstc <= 0) | |
837 { | |
6929 | 838 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 839 ccline.cmdbuff[indent] = NUL; |
840 ccline.cmdpos = indent; | |
841 ccline.cmdspos = indent; | |
842 ccline.cmdlen = indent; | |
843 } | |
844 | |
7 | 845 ExpandInit(&xpc); |
1718 | 846 ccline.xpc = &xpc; |
7 | 847 |
848 #ifdef FEAT_RIGHTLEFT | |
849 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
850 && (firstc == '/' || firstc == '?')) | |
851 cmdmsg_rl = TRUE; | |
852 else | |
853 cmdmsg_rl = FALSE; | |
854 #endif | |
855 | |
856 redir_off = TRUE; /* don't redirect the typed command */ | |
857 if (!cmd_silent) | |
858 { | |
859 i = msg_scrolled; | |
860 msg_scrolled = 0; /* avoid wait_return message */ | |
861 gotocmdline(TRUE); | |
862 msg_scrolled += i; | |
863 redrawcmdprompt(); /* draw prompt or indent */ | |
864 set_cmdspos(); | |
865 } | |
866 xpc.xp_context = EXPAND_NOTHING; | |
867 xpc.xp_backslash = XP_BS_NONE; | |
632 | 868 #ifndef BACKSLASH_IN_FILENAME |
869 xpc.xp_shell = FALSE; | |
870 #endif | |
7 | 871 |
531 | 872 #if defined(FEAT_EVAL) |
873 if (ccline.input_fn) | |
874 { | |
875 xpc.xp_context = ccline.xp_context; | |
876 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 877 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 878 xpc.xp_arg = ccline.xp_arg; |
1322 | 879 # endif |
531 | 880 } |
881 #endif | |
882 | |
7 | 883 /* |
884 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
885 * doing ":@0" when register 0 doesn't contain a CR. | |
886 */ | |
887 msg_scroll = FALSE; | |
888 | |
889 State = CMDLINE; | |
890 | |
891 if (firstc == '/' || firstc == '?' || firstc == '@') | |
892 { | |
893 /* Use ":lmap" mappings for search pattern and input(). */ | |
894 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
895 b_im_ptr = &curbuf->b_p_iminsert; | |
896 else | |
897 b_im_ptr = &curbuf->b_p_imsearch; | |
898 if (*b_im_ptr == B_IMODE_LMAP) | |
899 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
900 #ifdef HAVE_INPUT_METHOD |
7 | 901 im_set_active(*b_im_ptr == B_IMODE_IM); |
902 #endif | |
903 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
904 #ifdef HAVE_INPUT_METHOD |
7 | 905 else if (p_imcmdline) |
906 im_set_active(TRUE); | |
907 #endif | |
908 | |
909 #ifdef FEAT_MOUSE | |
910 setmouse(); | |
911 #endif | |
912 #ifdef CURSOR_SHAPE | |
913 ui_cursor_shape(); /* may show different cursor shape */ | |
914 #endif | |
915 | |
571 | 916 /* When inside an autocommand for writing "exiting" may be set and |
917 * terminal mode set to cooked. Need to set raw mode here then. */ | |
918 settmode(TMODE_RAW); | |
919 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
920 /* 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
|
921 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
|
922 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
|
923 |
7 | 924 #ifdef FEAT_CMDHIST |
925 init_history(); | |
926 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
927 histype = hist_char2type(firstc); | |
928 #endif | |
929 | |
930 #ifdef FEAT_DIGRAPHS | |
1868 | 931 do_digraph(-1); /* init digraph typeahead */ |
7 | 932 #endif |
933 | |
5993 | 934 /* If something above caused an error, reset the flags, we do want to type |
935 * and execute commands. Display may be messed up a bit. */ | |
936 if (did_emsg) | |
937 redrawcmd(); | |
938 did_emsg = FALSE; | |
939 got_int = FALSE; | |
940 | |
7 | 941 /* |
942 * Collect the command string, handling editing keys. | |
943 */ | |
944 for (;;) | |
945 { | |
972 | 946 redir_off = TRUE; /* Don't redirect the typed command. |
947 Repeated, because a ":redir" inside | |
948 completion may switch it on. */ | |
7 | 949 #ifdef USE_ON_FLY_SCROLL |
950 dont_scroll = FALSE; /* allow scrolling here */ | |
951 #endif | |
952 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
953 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 |
7 | 958 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 959 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
960 /* 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
|
961 * anything, such as stop completion. */ |
1472 | 962 do |
963 { | |
964 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
|
965 } while (c == K_IGNORE || c == K_NOP); |
1472 | 966 |
7 | 967 if (KeyTyped) |
968 { | |
969 some_key_typed = TRUE; | |
970 #ifdef FEAT_RIGHTLEFT | |
971 if (cmd_hkmap) | |
972 c = hkmap(c); | |
973 # ifdef FEAT_FKMAP | |
974 if (cmd_fkmap) | |
975 c = cmdl_fkmap(c); | |
976 # endif | |
977 if (cmdmsg_rl && !KeyStuffed) | |
978 { | |
979 /* Invert horizontal movements and operations. Only when | |
980 * typed by the user directly, not when the result of a | |
981 * mapping. */ | |
982 switch (c) | |
983 { | |
984 case K_RIGHT: c = K_LEFT; break; | |
985 case K_S_RIGHT: c = K_S_LEFT; break; | |
986 case K_C_RIGHT: c = K_C_LEFT; break; | |
987 case K_LEFT: c = K_RIGHT; break; | |
988 case K_S_LEFT: c = K_S_RIGHT; break; | |
989 case K_C_LEFT: c = K_C_RIGHT; break; | |
990 } | |
991 } | |
992 #endif | |
993 } | |
994 | |
995 /* | |
996 * Ignore got_int when CTRL-C was typed here. | |
997 * Don't ignore it in :global, we really need to break then, e.g., for | |
998 * ":g/pat/normal /pat" (without the <CR>). | |
999 * Don't ignore it for the input() function. | |
1000 */ | |
1001 if ((c == Ctrl_C | |
1002 #ifdef UNIX | |
1003 || c == intr_char | |
1004 #endif | |
1005 ) | |
1006 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1007 && firstc != '@' | |
1008 #endif | |
1009 #ifdef FEAT_EVAL | |
1010 && !break_ctrl_c | |
1011 #endif | |
1012 && !global_busy) | |
1013 got_int = FALSE; | |
1014 | |
1015 #ifdef FEAT_CMDHIST | |
1016 /* free old command line when finished moving around in the history | |
1017 * list */ | |
1018 if (lookfor != NULL | |
180 | 1019 && c != K_S_DOWN && c != K_S_UP |
230 | 1020 && c != K_DOWN && c != K_UP |
7 | 1021 && c != K_PAGEDOWN && c != K_PAGEUP |
1022 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1023 && c != K_LEFT && c != K_RIGHT |
7 | 1024 && (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
|
1025 VIM_CLEAR(lookfor); |
7 | 1026 #endif |
1027 | |
1028 /* | |
1718 | 1029 * When there are matching completions to select <S-Tab> works like |
1030 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1031 */ |
1718 | 1032 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1033 c = Ctrl_P; |
1034 | |
1035 #ifdef FEAT_WILDMENU | |
1036 /* Special translations for 'wildmenu' */ | |
1037 if (did_wild_list && p_wmnu) | |
1038 { | |
230 | 1039 if (c == K_LEFT) |
7 | 1040 c = Ctrl_P; |
230 | 1041 else if (c == K_RIGHT) |
7 | 1042 c = Ctrl_N; |
1043 } | |
1044 /* Hitting CR after "emenu Name.": complete submenu */ | |
1045 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1046 && ccline.cmdpos > 1 | |
1047 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1048 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1049 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1050 c = K_DOWN; | |
1051 #endif | |
1052 | |
1053 /* free expanded names when finished walking through matches */ | |
1054 if (xpc.xp_numfiles != -1 | |
1055 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1056 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1057 && c != Ctrl_L) | |
1058 { | |
1059 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1060 did_wild_list = FALSE; | |
1061 #ifdef FEAT_WILDMENU | |
230 | 1062 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1063 #endif |
1064 xpc.xp_context = EXPAND_NOTHING; | |
1065 wim_index = 0; | |
1066 #ifdef FEAT_WILDMENU | |
1067 if (p_wmnu && wild_menu_showing != 0) | |
1068 { | |
1069 int skt = KeyTyped; | |
532 | 1070 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1071 |
1072 if (ccline.input_fn) | |
1073 RedrawingDisabled = 0; | |
7 | 1074 |
1075 if (wild_menu_showing == WM_SCROLLED) | |
1076 { | |
1077 /* Entered command line, move it up */ | |
1078 cmdline_row--; | |
1079 redrawcmd(); | |
1080 } | |
1081 else if (save_p_ls != -1) | |
1082 { | |
1083 /* restore 'laststatus' and 'winminheight' */ | |
1084 p_ls = save_p_ls; | |
1085 p_wmh = save_p_wmh; | |
1086 last_status(FALSE); | |
195 | 1087 save_cmdline(&save_ccline); |
7 | 1088 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1089 restore_cmdline(&save_ccline); |
7 | 1090 redrawcmd(); |
1091 save_p_ls = -1; | |
1092 } | |
1093 else | |
1094 { | |
1095 win_redraw_last_status(topframe); | |
1096 redraw_statuslines(); | |
1097 } | |
532 | 1098 KeyTyped = skt; |
1099 wild_menu_showing = 0; | |
531 | 1100 if (ccline.input_fn) |
1101 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1102 } |
1103 #endif | |
1104 } | |
1105 | |
1106 #ifdef FEAT_WILDMENU | |
1107 /* Special translations for 'wildmenu' */ | |
1108 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1109 { | |
1110 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1111 if (c == K_DOWN && ccline.cmdpos > 0 |
1112 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1113 c = p_wc; |
230 | 1114 else if (c == K_UP) |
7 | 1115 { |
1116 /* Hitting <Up>: Remove one submenu name in front of the | |
1117 * cursor */ | |
1118 int found = FALSE; | |
1119 | |
1120 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1121 i = 0; | |
1122 while (--j > 0) | |
1123 { | |
1124 /* check for start of menu name */ | |
1125 if (ccline.cmdbuff[j] == ' ' | |
1126 && ccline.cmdbuff[j - 1] != '\\') | |
1127 { | |
1128 i = j + 1; | |
1129 break; | |
1130 } | |
1131 /* check for start of submenu name */ | |
1132 if (ccline.cmdbuff[j] == '.' | |
1133 && ccline.cmdbuff[j - 1] != '\\') | |
1134 { | |
1135 if (found) | |
1136 { | |
1137 i = j + 1; | |
1138 break; | |
1139 } | |
1140 else | |
1141 found = TRUE; | |
1142 } | |
1143 } | |
1144 if (i > 0) | |
1145 cmdline_del(i); | |
1146 c = p_wc; | |
1147 xpc.xp_context = EXPAND_NOTHING; | |
1148 } | |
1149 } | |
714 | 1150 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1151 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1152 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1153 { |
1154 char_u upseg[5]; | |
1155 | |
1156 upseg[0] = PATHSEP; | |
1157 upseg[1] = '.'; | |
1158 upseg[2] = '.'; | |
1159 upseg[3] = PATHSEP; | |
1160 upseg[4] = NUL; | |
1161 | |
1318 | 1162 if (c == K_DOWN |
1163 && ccline.cmdpos > 0 | |
1164 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1165 && (ccline.cmdpos < 3 | |
1166 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1167 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1168 { | |
1169 /* go down a directory */ | |
1170 c = p_wc; | |
1171 } | |
230 | 1172 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1173 { |
1174 /* If in a direct ancestor, strip off one ../ to go down */ | |
1175 int found = FALSE; | |
1176 | |
1177 j = ccline.cmdpos; | |
1178 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1179 while (--j > i) | |
1180 { | |
39 | 1181 #ifdef FEAT_MBYTE |
1182 if (has_mbyte) | |
1183 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1184 #endif | |
7 | 1185 if (vim_ispathsep(ccline.cmdbuff[j])) |
1186 { | |
1187 found = TRUE; | |
1188 break; | |
1189 } | |
1190 } | |
1191 if (found | |
1192 && ccline.cmdbuff[j - 1] == '.' | |
1193 && ccline.cmdbuff[j - 2] == '.' | |
1194 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1195 { | |
1196 cmdline_del(j - 2); | |
1197 c = p_wc; | |
1198 } | |
1199 } | |
230 | 1200 else if (c == K_UP) |
7 | 1201 { |
1202 /* go up a directory */ | |
1203 int found = FALSE; | |
1204 | |
1205 j = ccline.cmdpos - 1; | |
1206 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1207 while (--j > i) | |
1208 { | |
1209 #ifdef FEAT_MBYTE | |
1210 if (has_mbyte) | |
1211 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1212 #endif | |
1213 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1214 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1215 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1216 ccline.cmdbuff[j + 1]) == NULL |
7 | 1217 #endif |
1218 ) | |
1219 { | |
1220 if (found) | |
1221 { | |
1222 i = j + 1; | |
1223 break; | |
1224 } | |
1225 else | |
1226 found = TRUE; | |
1227 } | |
1228 } | |
1229 | |
1230 if (!found) | |
1231 j = i; | |
1232 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1233 j += 4; | |
1234 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1235 && j == i) | |
1236 j += 3; | |
1237 else | |
1238 j = 0; | |
1239 if (j > 0) | |
1240 { | |
1241 /* TODO this is only for DOS/UNIX systems - need to put in | |
1242 * machine-specific stuff here and in upseg init */ | |
1243 cmdline_del(j); | |
1244 put_on_cmdline(upseg + 1, 3, FALSE); | |
1245 } | |
1246 else if (ccline.cmdpos > i) | |
1247 cmdline_del(i); | |
3204 | 1248 |
1249 /* Now complete in the new directory. Set KeyTyped in case the | |
1250 * Up key came from a mapping. */ | |
7 | 1251 c = p_wc; |
3204 | 1252 KeyTyped = TRUE; |
7 | 1253 } |
1254 } | |
1255 | |
1256 #endif /* FEAT_WILDMENU */ | |
1257 | |
1258 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1259 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1260 if (c == Ctrl_BSL) | |
1261 { | |
1262 ++no_mapping; | |
1263 ++allow_keys; | |
1389 | 1264 c = plain_vgetc(); |
7 | 1265 --no_mapping; |
1266 --allow_keys; | |
3859 | 1267 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1268 * is in a mapping. */ | |
1269 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1270 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1271 { |
1272 vungetc(c); | |
1273 c = Ctrl_BSL; | |
1274 } | |
1275 #ifdef FEAT_EVAL | |
1276 else if (c == 'e') | |
1277 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1278 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1279 int len; |
7 | 1280 |
1281 /* | |
1282 * Replace the command line with the result of an expression. | |
625 | 1283 * Need to save and restore the current command line, to be |
1284 * able to enter a new one... | |
7 | 1285 */ |
1286 if (ccline.cmdpos == ccline.cmdlen) | |
1287 new_cmdpos = 99999; /* keep it at the end */ | |
1288 else | |
1289 new_cmdpos = ccline.cmdpos; | |
95 | 1290 |
1291 save_cmdline(&save_ccline); | |
7 | 1292 c = get_expr_register(); |
95 | 1293 restore_cmdline(&save_ccline); |
7 | 1294 if (c == '=') |
1295 { | |
634 | 1296 /* Need to save and restore ccline. And set "textlock" |
632 | 1297 * to avoid nasty things like going to another buffer when |
1298 * evaluating an expression. */ | |
95 | 1299 save_cmdline(&save_ccline); |
634 | 1300 ++textlock; |
7 | 1301 p = get_expr_line(); |
634 | 1302 --textlock; |
95 | 1303 restore_cmdline(&save_ccline); |
2617 | 1304 |
1305 if (p != NULL) | |
7 | 1306 { |
2617 | 1307 len = (int)STRLEN(p); |
1308 if (realloc_cmdbuff(len + 1) == OK) | |
1309 { | |
1310 ccline.cmdlen = len; | |
1311 STRCPY(ccline.cmdbuff, p); | |
1312 vim_free(p); | |
1313 | |
1314 /* Restore the cursor or use the position set with | |
1315 * set_cmdline_pos(). */ | |
1316 if (new_cmdpos > ccline.cmdlen) | |
1317 ccline.cmdpos = ccline.cmdlen; | |
1318 else | |
1319 ccline.cmdpos = new_cmdpos; | |
1320 | |
1321 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1322 redrawcmd(); | |
1323 goto cmdline_changed; | |
1324 } | |
7 | 1325 } |
1326 } | |
1327 beep_flush(); | |
2636 | 1328 got_int = FALSE; /* don't abandon the command line */ |
1329 did_emsg = FALSE; | |
1330 emsg_on_display = FALSE; | |
1331 redrawcmd(); | |
1332 goto cmdline_not_changed; | |
7 | 1333 } |
1334 #endif | |
1335 else | |
1336 { | |
1337 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1338 restart_edit = 'a'; | |
1339 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1340 in history */ | |
1341 goto returncmd; /* back to Normal mode */ | |
1342 } | |
1343 } | |
1344 | |
1345 #ifdef FEAT_CMDWIN | |
1346 if (c == cedit_key || c == K_CMDWIN) | |
1347 { | |
6211 | 1348 if (ex_normal_busy == 0 && got_int == FALSE) |
1349 { | |
1350 /* | |
1351 * Open a window to edit the command line (and history). | |
1352 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1353 c = open_cmdwin(); |
6211 | 1354 some_key_typed = TRUE; |
1355 } | |
7 | 1356 } |
1357 # ifdef FEAT_DIGRAPHS | |
1358 else | |
1359 # endif | |
1360 #endif | |
1361 #ifdef FEAT_DIGRAPHS | |
1362 c = do_digraph(c); | |
1363 #endif | |
1364 | |
1365 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1366 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1367 { | |
168 | 1368 /* In Ex mode a backslash escapes a newline. */ |
1369 if (exmode_active | |
1370 && c != ESC | |
1318 | 1371 && ccline.cmdpos == ccline.cmdlen |
168 | 1372 && ccline.cmdpos > 0 |
1373 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1374 { | |
1375 if (c == K_KENTER) | |
1376 c = '\n'; | |
1377 } | |
1378 else | |
7 | 1379 { |
168 | 1380 gotesc = FALSE; /* Might have typed ESC previously, don't |
1381 truncate the cmdline now. */ | |
1382 if (ccheck_abbr(c + ABBR_OFF)) | |
1383 goto cmdline_changed; | |
1384 if (!cmd_silent) | |
1385 { | |
1386 windgoto(msg_row, 0); | |
1387 out_flush(); | |
1388 } | |
1389 break; | |
7 | 1390 } |
1391 } | |
1392 | |
1393 /* | |
1394 * Completion for 'wildchar' or 'wildcharm' key. | |
1395 * - hitting <ESC> twice means: abandon command line. | |
1396 * - wildcard expansion is only done when the 'wildchar' key is really | |
1397 * typed, not when it comes from a macro | |
1398 */ | |
1399 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1400 { | |
1401 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1402 { | |
1403 /* if 'wildmode' contains "list" may still need to list */ | |
1404 if (xpc.xp_numfiles > 1 | |
1405 && !did_wild_list | |
1406 && (wim_flags[wim_index] & WIM_LIST)) | |
1407 { | |
1408 (void)showmatches(&xpc, FALSE); | |
1409 redrawcmd(); | |
1410 did_wild_list = TRUE; | |
1411 } | |
1412 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1413 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1414 firstc != '@'); | |
7 | 1415 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1416 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1417 firstc != '@'); | |
7 | 1418 else |
1419 res = OK; /* don't insert 'wildchar' now */ | |
1420 } | |
1421 else /* typed p_wc first time */ | |
1422 { | |
1423 wim_index = 0; | |
1424 j = ccline.cmdpos; | |
1425 /* if 'wildmode' first contains "longest", get longest | |
1426 * common part */ | |
1427 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1428 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1429 firstc != '@'); | |
7 | 1430 else |
3961 | 1431 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1432 firstc != '@'); | |
7 | 1433 |
1434 /* if interrupted while completing, behave like it failed */ | |
1435 if (got_int) | |
1436 { | |
1437 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1438 got_int = FALSE; /* don't abandon the command line */ | |
1439 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1440 #ifdef FEAT_WILDMENU | |
1441 xpc.xp_context = EXPAND_NOTHING; | |
1442 #endif | |
1443 goto cmdline_changed; | |
1444 } | |
1445 | |
1446 /* when more than one match, and 'wildmode' first contains | |
1447 * "list", or no change and 'wildmode' contains "longest,list", | |
1448 * list all matches */ | |
1449 if (res == OK && xpc.xp_numfiles > 1) | |
1450 { | |
1451 /* a "longest" that didn't do anything is skipped (but not | |
1452 * "list:longest") */ | |
1453 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1454 wim_index = 1; | |
1455 if ((wim_flags[wim_index] & WIM_LIST) | |
1456 #ifdef FEAT_WILDMENU | |
1457 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1458 #endif | |
1459 ) | |
1460 { | |
1461 if (!(wim_flags[0] & WIM_LONGEST)) | |
1462 { | |
1463 #ifdef FEAT_WILDMENU | |
1464 int p_wmnu_save = p_wmnu; | |
1465 p_wmnu = 0; | |
1466 #endif | |
3961 | 1467 /* remove match */ |
1468 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1469 #ifdef FEAT_WILDMENU |
1470 p_wmnu = p_wmnu_save; | |
1471 #endif | |
1472 } | |
1473 #ifdef FEAT_WILDMENU | |
1474 (void)showmatches(&xpc, p_wmnu | |
1475 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1476 #else | |
1477 (void)showmatches(&xpc, FALSE); | |
1478 #endif | |
1479 redrawcmd(); | |
1480 did_wild_list = TRUE; | |
1481 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1482 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1483 firstc != '@'); | |
7 | 1484 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1485 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1486 firstc != '@'); | |
7 | 1487 } |
1488 else | |
6949 | 1489 vim_beep(BO_WILD); |
7 | 1490 } |
1491 #ifdef FEAT_WILDMENU | |
1492 else if (xpc.xp_numfiles == -1) | |
1493 xpc.xp_context = EXPAND_NOTHING; | |
1494 #endif | |
1495 } | |
1496 if (wim_index < 3) | |
1497 ++wim_index; | |
1498 if (c == ESC) | |
1499 gotesc = TRUE; | |
1500 if (res == OK) | |
1501 goto cmdline_changed; | |
1502 } | |
1503 | |
1504 gotesc = FALSE; | |
1505 | |
1506 /* <S-Tab> goes to last match, in a clumsy way */ | |
1507 if (c == K_S_TAB && KeyTyped) | |
1508 { | |
3961 | 1509 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1510 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1511 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1512 goto cmdline_changed; |
1513 } | |
1514 | |
1515 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1516 c = NL; | |
1517 | |
1518 do_abbr = TRUE; /* default: check for abbreviation */ | |
1519 | |
1520 /* | |
1521 * Big switch for a typed command line character. | |
1522 */ | |
1523 switch (c) | |
1524 { | |
1525 case K_BS: | |
1526 case Ctrl_H: | |
1527 case K_DEL: | |
1528 case K_KDEL: | |
1529 case Ctrl_W: | |
1530 #ifdef FEAT_FKMAP | |
1531 if (cmd_fkmap && c == K_BS) | |
1532 c = K_DEL; | |
1533 #endif | |
1534 if (c == K_KDEL) | |
1535 c = K_DEL; | |
1536 | |
1537 /* | |
1538 * delete current character is the same as backspace on next | |
1539 * character, except at end of line | |
1540 */ | |
1541 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1542 ++ccline.cmdpos; | |
1543 #ifdef FEAT_MBYTE | |
1544 if (has_mbyte && c == K_DEL) | |
1545 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1546 ccline.cmdbuff + ccline.cmdpos); | |
1547 #endif | |
1548 if (ccline.cmdpos > 0) | |
1549 { | |
1550 char_u *p; | |
1551 | |
1552 j = ccline.cmdpos; | |
1553 p = ccline.cmdbuff + j; | |
1554 #ifdef FEAT_MBYTE | |
1555 if (has_mbyte) | |
1556 { | |
1557 p = mb_prevptr(ccline.cmdbuff, p); | |
1558 if (c == Ctrl_W) | |
1559 { | |
1560 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1561 p = mb_prevptr(ccline.cmdbuff, p); | |
1562 i = mb_get_class(p); | |
1563 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1564 p = mb_prevptr(ccline.cmdbuff, p); | |
1565 if (mb_get_class(p) != i) | |
474 | 1566 p += (*mb_ptr2len)(p); |
7 | 1567 } |
1568 } | |
1569 else | |
1570 #endif | |
1571 if (c == Ctrl_W) | |
1572 { | |
1573 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1574 --p; | |
1575 i = vim_iswordc(p[-1]); | |
1576 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1577 && vim_iswordc(p[-1]) == i) | |
1578 --p; | |
1579 } | |
1580 else | |
1581 --p; | |
1582 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1583 ccline.cmdlen -= j - ccline.cmdpos; | |
1584 i = ccline.cmdpos; | |
1585 while (i < ccline.cmdlen) | |
1586 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1587 | |
1588 /* Truncate at the end, required for multi-byte chars. */ | |
1589 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1590 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1591 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1592 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1593 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
|
1594 /* 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
|
1595 * 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
|
1596 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
|
1597 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1598 #endif |
7 | 1599 redrawcmd(); |
1600 } | |
1601 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1602 && ccline.cmdprompt == NULL && indent == 0) | |
1603 { | |
1604 /* In ex and debug mode it doesn't make sense to return. */ | |
1605 if (exmode_active | |
1606 #ifdef FEAT_EVAL | |
1607 || ccline.cmdfirstc == '>' | |
1608 #endif | |
1609 ) | |
1610 goto cmdline_not_changed; | |
1611 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1612 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1613 if (!cmd_silent) |
1614 { | |
1615 #ifdef FEAT_RIGHTLEFT | |
1616 if (cmdmsg_rl) | |
1617 msg_col = Columns; | |
1618 else | |
1619 #endif | |
1620 msg_col = 0; | |
1621 msg_putchar(' '); /* delete ':' */ | |
1622 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1623 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1624 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
|
1625 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
|
1626 #endif |
7 | 1627 redraw_cmdline = TRUE; |
1628 goto returncmd; /* back to cmd mode */ | |
1629 } | |
1630 goto cmdline_changed; | |
1631 | |
1632 case K_INS: | |
1633 case K_KINS: | |
1634 #ifdef FEAT_FKMAP | |
1635 /* if Farsi mode set, we are in reverse insert mode - | |
1636 Do not change the mode */ | |
1637 if (cmd_fkmap) | |
1638 beep_flush(); | |
1639 else | |
1640 #endif | |
1641 ccline.overstrike = !ccline.overstrike; | |
1642 #ifdef CURSOR_SHAPE | |
1643 ui_cursor_shape(); /* may show different cursor shape */ | |
1644 #endif | |
1645 goto cmdline_not_changed; | |
1646 | |
1647 case Ctrl_HAT: | |
782 | 1648 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1649 { |
1650 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1651 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1652 #ifdef HAVE_INPUT_METHOD |
7 | 1653 im_set_active(FALSE); /* Disable input method */ |
1654 #endif | |
1655 if (b_im_ptr != NULL) | |
1656 { | |
1657 if (State & LANGMAP) | |
1658 *b_im_ptr = B_IMODE_LMAP; | |
1659 else | |
1660 *b_im_ptr = B_IMODE_NONE; | |
1661 } | |
1662 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1663 #ifdef HAVE_INPUT_METHOD |
7 | 1664 else |
1665 { | |
1666 /* There are no ":lmap" mappings, toggle IM. When | |
1667 * 'imdisable' is set don't try getting the status, it's | |
1668 * always off. */ | |
1669 if ((p_imdisable && b_im_ptr != NULL) | |
1670 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1671 { | |
1672 im_set_active(FALSE); /* Disable input method */ | |
1673 if (b_im_ptr != NULL) | |
1674 *b_im_ptr = B_IMODE_NONE; | |
1675 } | |
1676 else | |
1677 { | |
1678 im_set_active(TRUE); /* Enable input method */ | |
1679 if (b_im_ptr != NULL) | |
1680 *b_im_ptr = B_IMODE_IM; | |
1681 } | |
1682 } | |
1683 #endif | |
1684 if (b_im_ptr != NULL) | |
1685 { | |
1686 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1687 set_iminsert_global(); | |
1688 else | |
1689 set_imsearch_global(); | |
1690 } | |
1691 #ifdef CURSOR_SHAPE | |
1692 ui_cursor_shape(); /* may show different cursor shape */ | |
1693 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1694 #if defined(FEAT_KEYMAP) |
7 | 1695 /* Show/unshow value of 'keymap' in status lines later. */ |
1696 status_redraw_curbuf(); | |
1697 #endif | |
1698 goto cmdline_not_changed; | |
1699 | |
1700 /* case '@': only in very old vi */ | |
1701 case Ctrl_U: | |
1702 /* delete all characters left of the cursor */ | |
1703 j = ccline.cmdpos; | |
1704 ccline.cmdlen -= j; | |
1705 i = ccline.cmdpos = 0; | |
1706 while (i < ccline.cmdlen) | |
1707 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1708 /* Truncate at the end, required for multi-byte chars. */ | |
1709 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1710 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1711 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
|
1712 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
|
1713 #endif |
7 | 1714 redrawcmd(); |
1715 goto cmdline_changed; | |
1716 | |
1717 #ifdef FEAT_CLIPBOARD | |
1718 case Ctrl_Y: | |
1719 /* Copy the modeless selection, if there is one. */ | |
1720 if (clip_star.state != SELECT_CLEARED) | |
1721 { | |
1722 if (clip_star.state == SELECT_DONE) | |
1723 clip_copy_modeless_selection(TRUE); | |
1724 goto cmdline_not_changed; | |
1725 } | |
1726 break; | |
1727 #endif | |
1728 | |
1729 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1730 case Ctrl_C: | |
571 | 1731 /* In exmode it doesn't make sense to return. Except when |
161 | 1732 * ":normal" runs out of characters. */ |
1733 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1734 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1735 goto cmdline_not_changed; |
1736 | |
1737 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1738 putting it in history */ | |
1739 goto returncmd; /* back to cmd mode */ | |
1740 | |
1741 case Ctrl_R: /* insert register */ | |
1742 #ifdef USE_ON_FLY_SCROLL | |
1743 dont_scroll = TRUE; /* disallow scrolling here */ | |
1744 #endif | |
1745 putcmdline('"', TRUE); | |
1746 ++no_mapping; | |
1389 | 1747 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1748 if (i == Ctrl_O) |
1749 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1750 if (i == Ctrl_R) | |
1389 | 1751 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
|
1752 extra_char = NUL; |
7 | 1753 --no_mapping; |
1754 #ifdef FEAT_EVAL | |
1755 /* | |
1756 * Insert the result of an expression. | |
1757 * Need to save the current command line, to be able to enter | |
1758 * a new one... | |
1759 */ | |
1760 new_cmdpos = -1; | |
1761 if (c == '=') | |
1762 { | |
1763 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1764 { | |
1765 beep_flush(); | |
1766 c = ESC; | |
1767 } | |
1768 else | |
1769 { | |
95 | 1770 save_cmdline(&save_ccline); |
7 | 1771 c = get_expr_register(); |
95 | 1772 restore_cmdline(&save_ccline); |
7 | 1773 } |
1774 } | |
1775 #endif | |
1776 if (c != ESC) /* use ESC to cancel inserting register */ | |
1777 { | |
1015 | 1778 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1779 |
613 | 1780 #ifdef FEAT_EVAL |
606 | 1781 /* When there was a serious error abort getting the |
1782 * command line. */ | |
1783 if (aborting()) | |
1784 { | |
1785 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1786 putting it in history */ | |
1787 goto returncmd; /* back to cmd mode */ | |
1788 } | |
613 | 1789 #endif |
7 | 1790 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1791 #ifdef FEAT_EVAL | |
1792 if (new_cmdpos >= 0) | |
1793 { | |
1794 /* set_cmdline_pos() was used */ | |
1795 if (new_cmdpos > ccline.cmdlen) | |
1796 ccline.cmdpos = ccline.cmdlen; | |
1797 else | |
1798 ccline.cmdpos = new_cmdpos; | |
1799 } | |
1800 #endif | |
1801 } | |
1802 redrawcmd(); | |
1803 goto cmdline_changed; | |
1804 | |
1805 case Ctrl_D: | |
1806 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1807 break; /* Use ^D as normal char instead */ | |
1808 | |
1809 redrawcmd(); | |
1810 continue; /* don't do incremental search now */ | |
1811 | |
1812 case K_RIGHT: | |
1813 case K_S_RIGHT: | |
1814 case K_C_RIGHT: | |
1815 do | |
1816 { | |
1817 if (ccline.cmdpos >= ccline.cmdlen) | |
1818 break; | |
1819 i = cmdline_charsize(ccline.cmdpos); | |
1820 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1821 break; | |
1822 ccline.cmdspos += i; | |
1823 #ifdef FEAT_MBYTE | |
1824 if (has_mbyte) | |
474 | 1825 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1826 + ccline.cmdpos); |
1827 else | |
1828 #endif | |
1829 ++ccline.cmdpos; | |
1830 } | |
180 | 1831 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1832 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1833 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1834 #ifdef FEAT_MBYTE | |
1835 if (has_mbyte) | |
1836 set_cmdspos_cursor(); | |
1837 #endif | |
1838 goto cmdline_not_changed; | |
1839 | |
1840 case K_LEFT: | |
1841 case K_S_LEFT: | |
1842 case K_C_LEFT: | |
1456 | 1843 if (ccline.cmdpos == 0) |
1844 goto cmdline_not_changed; | |
7 | 1845 do |
1846 { | |
1847 --ccline.cmdpos; | |
1848 #ifdef FEAT_MBYTE | |
1849 if (has_mbyte) /* move to first byte of char */ | |
1850 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1851 ccline.cmdbuff + ccline.cmdpos); | |
1852 #endif | |
1853 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1854 } | |
1456 | 1855 while (ccline.cmdpos > 0 |
1856 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1857 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1858 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1859 #ifdef FEAT_MBYTE | |
1860 if (has_mbyte) | |
1861 set_cmdspos_cursor(); | |
1862 #endif | |
1863 goto cmdline_not_changed; | |
1864 | |
1865 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
|
1866 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1867 goto cmdline_not_changed; |
7 | 1868 |
625 | 1869 #ifdef FEAT_GUI_W32 |
1870 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1871 * cancelled. */ | |
1872 case K_F4: | |
1873 if (mod_mask == MOD_MASK_ALT) | |
1874 { | |
1875 redrawcmd(); /* somehow the cmdline is cleared */ | |
1876 goto cmdline_not_changed; | |
1877 } | |
1878 break; | |
1879 #endif | |
1880 | |
7 | 1881 #ifdef FEAT_MOUSE |
1882 case K_MIDDLEDRAG: | |
1883 case K_MIDDLERELEASE: | |
1884 goto cmdline_not_changed; /* Ignore mouse */ | |
1885 | |
1886 case K_MIDDLEMOUSE: | |
1887 # ifdef FEAT_GUI | |
1888 /* When GUI is active, also paste when 'mouse' is empty */ | |
1889 if (!gui.in_use) | |
1890 # endif | |
1891 if (!mouse_has(MOUSE_COMMAND)) | |
1892 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1893 # ifdef FEAT_CLIPBOARD |
7 | 1894 if (clip_star.available) |
1015 | 1895 cmdline_paste('*', TRUE, TRUE); |
7 | 1896 else |
692 | 1897 # endif |
1015 | 1898 cmdline_paste(0, TRUE, TRUE); |
7 | 1899 redrawcmd(); |
1900 goto cmdline_changed; | |
1901 | |
692 | 1902 # ifdef FEAT_DND |
7 | 1903 case K_DROP: |
1015 | 1904 cmdline_paste('~', TRUE, FALSE); |
7 | 1905 redrawcmd(); |
1906 goto cmdline_changed; | |
692 | 1907 # endif |
7 | 1908 |
1909 case K_LEFTDRAG: | |
1910 case K_LEFTRELEASE: | |
1911 case K_RIGHTDRAG: | |
1912 case K_RIGHTRELEASE: | |
1913 /* Ignore drag and release events when the button-down wasn't | |
1914 * seen before. */ | |
1915 if (ignore_drag_release) | |
1916 goto cmdline_not_changed; | |
1917 /* FALLTHROUGH */ | |
1918 case K_LEFTMOUSE: | |
1919 case K_RIGHTMOUSE: | |
1920 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1921 ignore_drag_release = TRUE; | |
1922 else | |
1923 ignore_drag_release = FALSE; | |
1924 # ifdef FEAT_GUI | |
1925 /* When GUI is active, also move when 'mouse' is empty */ | |
1926 if (!gui.in_use) | |
1927 # endif | |
1928 if (!mouse_has(MOUSE_COMMAND)) | |
1929 goto cmdline_not_changed; /* Ignore mouse */ | |
1930 # ifdef FEAT_CLIPBOARD | |
1931 if (mouse_row < cmdline_row && clip_star.available) | |
1932 { | |
1933 int button, is_click, is_drag; | |
1934 | |
1935 /* | |
1936 * Handle modeless selection. | |
1937 */ | |
1938 button = get_mouse_button(KEY2TERMCAP1(c), | |
1939 &is_click, &is_drag); | |
1940 if (mouse_model_popup() && button == MOUSE_LEFT | |
1941 && (mod_mask & MOD_MASK_SHIFT)) | |
1942 { | |
1943 /* Translate shift-left to right button. */ | |
1944 button = MOUSE_RIGHT; | |
1945 mod_mask &= ~MOD_MASK_SHIFT; | |
1946 } | |
1947 clip_modeless(button, is_click, is_drag); | |
1948 goto cmdline_not_changed; | |
1949 } | |
1950 # endif | |
1951 | |
1952 set_cmdspos(); | |
1953 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1954 ++ccline.cmdpos) | |
1955 { | |
1956 i = cmdline_charsize(ccline.cmdpos); | |
1957 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1958 && mouse_col < ccline.cmdspos % Columns + i) | |
1959 break; | |
692 | 1960 # ifdef FEAT_MBYTE |
7 | 1961 if (has_mbyte) |
1962 { | |
1963 /* Count ">" for double-wide char that doesn't fit. */ | |
1964 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1965 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1966 + ccline.cmdpos) - 1; |
1967 } | |
692 | 1968 # endif |
7 | 1969 ccline.cmdspos += i; |
1970 } | |
1971 goto cmdline_not_changed; | |
1972 | |
1973 /* Mouse scroll wheel: ignored here */ | |
1974 case K_MOUSEDOWN: | |
1975 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1976 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1977 case K_MOUSERIGHT: |
7 | 1978 /* Alternate buttons ignored here */ |
1979 case K_X1MOUSE: | |
1980 case K_X1DRAG: | |
1981 case K_X1RELEASE: | |
1982 case K_X2MOUSE: | |
1983 case K_X2DRAG: | |
1984 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1985 case K_MOUSEMOVE: |
7 | 1986 goto cmdline_not_changed; |
1987 | |
1988 #endif /* FEAT_MOUSE */ | |
1989 | |
1990 #ifdef FEAT_GUI | |
1991 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1992 case K_LEFTRELEASE_NM: | |
1993 goto cmdline_not_changed; | |
1994 | |
1995 case K_VER_SCROLLBAR: | |
540 | 1996 if (msg_scrolled == 0) |
7 | 1997 { |
1998 gui_do_scroll(); | |
1999 redrawcmd(); | |
2000 } | |
2001 goto cmdline_not_changed; | |
2002 | |
2003 case K_HOR_SCROLLBAR: | |
540 | 2004 if (msg_scrolled == 0) |
7 | 2005 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2006 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2007 redrawcmd(); |
2008 } | |
2009 goto cmdline_not_changed; | |
2010 #endif | |
692 | 2011 #ifdef FEAT_GUI_TABLINE |
2012 case K_TABLINE: | |
2013 case K_TABMENU: | |
2014 /* Don't want to change any tabs here. Make sure the same tab | |
2015 * is still selected. */ | |
2016 if (gui_use_tabline()) | |
2017 gui_mch_set_curtab(tabpage_index(curtab)); | |
2018 goto cmdline_not_changed; | |
2019 #endif | |
2020 | |
7 | 2021 case K_SELECT: /* end of Select mode mapping - ignore */ |
2022 goto cmdline_not_changed; | |
2023 | |
2024 case Ctrl_B: /* begin of command line */ | |
2025 case K_HOME: | |
2026 case K_KHOME: | |
2027 case K_S_HOME: | |
2028 case K_C_HOME: | |
2029 ccline.cmdpos = 0; | |
2030 set_cmdspos(); | |
2031 goto cmdline_not_changed; | |
2032 | |
2033 case Ctrl_E: /* end of command line */ | |
2034 case K_END: | |
2035 case K_KEND: | |
2036 case K_S_END: | |
2037 case K_C_END: | |
2038 ccline.cmdpos = ccline.cmdlen; | |
2039 set_cmdspos_cursor(); | |
2040 goto cmdline_not_changed; | |
2041 | |
2042 case Ctrl_A: /* all matches */ | |
3961 | 2043 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2044 break; |
2045 goto cmdline_changed; | |
2046 | |
772 | 2047 case Ctrl_L: |
2048 #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
|
2049 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2050 goto cmdline_not_changed; |
2051 #endif | |
2052 | |
2053 /* completion: longest common part */ | |
3961 | 2054 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2055 break; |
2056 goto cmdline_changed; | |
2057 | |
2058 case Ctrl_N: /* next match */ | |
2059 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2060 if (xpc.xp_numfiles > 0) |
7 | 2061 { |
3961 | 2062 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2063 0, firstc != '@') == FAIL) | |
7 | 2064 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2065 goto cmdline_not_changed; |
7 | 2066 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2067 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2068 /* FALLTHROUGH */ |
7 | 2069 case K_UP: |
2070 case K_DOWN: | |
2071 case K_S_UP: | |
2072 case K_S_DOWN: | |
2073 case K_PAGEUP: | |
2074 case K_KPAGEUP: | |
2075 case K_PAGEDOWN: | |
2076 case K_KPAGEDOWN: | |
2077 if (hislen == 0 || firstc == NUL) /* no history */ | |
2078 goto cmdline_not_changed; | |
2079 | |
2080 i = hiscnt; | |
2081 | |
2082 /* save current command string so it can be restored later */ | |
2083 if (lookfor == NULL) | |
2084 { | |
2085 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2086 goto cmdline_not_changed; | |
2087 lookfor[ccline.cmdpos] = NUL; | |
2088 } | |
2089 | |
2090 j = (int)STRLEN(lookfor); | |
2091 for (;;) | |
2092 { | |
2093 /* one step backwards */ | |
230 | 2094 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2095 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2096 { |
2097 if (hiscnt == hislen) /* first time */ | |
2098 hiscnt = hisidx[histype]; | |
2099 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2100 hiscnt = hislen - 1; | |
2101 else if (hiscnt != hisidx[histype] + 1) | |
2102 --hiscnt; | |
2103 else /* at top of list */ | |
2104 { | |
2105 hiscnt = i; | |
2106 break; | |
2107 } | |
2108 } | |
2109 else /* one step forwards */ | |
2110 { | |
2111 /* on last entry, clear the line */ | |
2112 if (hiscnt == hisidx[histype]) | |
2113 { | |
2114 hiscnt = hislen; | |
2115 break; | |
2116 } | |
2117 | |
2118 /* not on a history line, nothing to do */ | |
2119 if (hiscnt == hislen) | |
2120 break; | |
2121 if (hiscnt == hislen - 1) /* wrap around */ | |
2122 hiscnt = 0; | |
2123 else | |
2124 ++hiscnt; | |
2125 } | |
2126 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2127 { | |
2128 hiscnt = i; | |
2129 break; | |
2130 } | |
230 | 2131 if ((c != K_UP && c != K_DOWN) |
180 | 2132 || hiscnt == i |
7 | 2133 || STRNCMP(history[histype][hiscnt].hisstr, |
2134 lookfor, (size_t)j) == 0) | |
2135 break; | |
2136 } | |
2137 | |
2138 if (hiscnt != i) /* jumped to other entry */ | |
2139 { | |
2140 char_u *p; | |
2141 int len; | |
2142 int old_firstc; | |
2143 | |
2144 vim_free(ccline.cmdbuff); | |
1718 | 2145 xpc.xp_context = EXPAND_NOTHING; |
7 | 2146 if (hiscnt == hislen) |
2147 p = lookfor; /* back to the old one */ | |
2148 else | |
2149 p = history[histype][hiscnt].hisstr; | |
2150 | |
2151 if (histype == HIST_SEARCH | |
2152 && p != lookfor | |
2153 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2154 { | |
2155 /* Correct for the separator character used when | |
2156 * adding the history entry vs the one used now. | |
2157 * First loop: count length. | |
2158 * Second loop: copy the characters. */ | |
2159 for (i = 0; i <= 1; ++i) | |
2160 { | |
2161 len = 0; | |
2162 for (j = 0; p[j] != NUL; ++j) | |
2163 { | |
2164 /* Replace old sep with new sep, unless it is | |
2165 * escaped. */ | |
2166 if (p[j] == old_firstc | |
2167 && (j == 0 || p[j - 1] != '\\')) | |
2168 { | |
2169 if (i > 0) | |
2170 ccline.cmdbuff[len] = firstc; | |
2171 } | |
2172 else | |
2173 { | |
2174 /* Escape new sep, unless it is already | |
2175 * escaped. */ | |
2176 if (p[j] == firstc | |
2177 && (j == 0 || p[j - 1] != '\\')) | |
2178 { | |
2179 if (i > 0) | |
2180 ccline.cmdbuff[len] = '\\'; | |
2181 ++len; | |
2182 } | |
2183 if (i > 0) | |
2184 ccline.cmdbuff[len] = p[j]; | |
2185 } | |
2186 ++len; | |
2187 } | |
2188 if (i == 0) | |
2189 { | |
2190 alloc_cmdbuff(len); | |
2191 if (ccline.cmdbuff == NULL) | |
2192 goto returncmd; | |
2193 } | |
2194 } | |
2195 ccline.cmdbuff[len] = NUL; | |
2196 } | |
2197 else | |
2198 { | |
2199 alloc_cmdbuff((int)STRLEN(p)); | |
2200 if (ccline.cmdbuff == NULL) | |
2201 goto returncmd; | |
2202 STRCPY(ccline.cmdbuff, p); | |
2203 } | |
2204 | |
2205 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2206 redrawcmd(); | |
2207 goto cmdline_changed; | |
2208 } | |
2209 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2210 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2211 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2212 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2213 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2214 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2215 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
|
2216 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
|
2217 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
|
2218 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2219 break; |
7 | 2220 #endif |
2221 | |
2222 case Ctrl_V: | |
2223 case Ctrl_Q: | |
2224 #ifdef FEAT_MOUSE | |
2225 ignore_drag_release = TRUE; | |
2226 #endif | |
2227 putcmdline('^', TRUE); | |
2228 c = get_literal(); /* get next (two) character(s) */ | |
2229 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
|
2230 extra_char = NUL; |
7 | 2231 #ifdef FEAT_MBYTE |
2232 /* may need to remove ^ when composing char was typed */ | |
2233 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2234 { | |
2235 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2236 msg_putchar(' '); | |
2237 cursorcmd(); | |
2238 } | |
2239 #endif | |
2240 break; | |
2241 | |
2242 #ifdef FEAT_DIGRAPHS | |
2243 case Ctrl_K: | |
2244 #ifdef FEAT_MOUSE | |
2245 ignore_drag_release = TRUE; | |
2246 #endif | |
2247 putcmdline('?', TRUE); | |
2248 #ifdef USE_ON_FLY_SCROLL | |
2249 dont_scroll = TRUE; /* disallow scrolling here */ | |
2250 #endif | |
2251 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
|
2252 extra_char = NUL; |
7 | 2253 if (c != NUL) |
2254 break; | |
2255 | |
2256 redrawcmd(); | |
2257 goto cmdline_not_changed; | |
2258 #endif /* FEAT_DIGRAPHS */ | |
2259 | |
2260 #ifdef FEAT_RIGHTLEFT | |
2261 case Ctrl__: /* CTRL-_: switch language mode */ | |
2262 if (!p_ari) | |
2263 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2264 # ifdef FEAT_FKMAP |
7 | 2265 if (p_altkeymap) |
2266 { | |
2267 cmd_fkmap = !cmd_fkmap; | |
2268 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2269 ccline.overstrike = FALSE; | |
2270 } | |
2271 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2272 # endif |
7 | 2273 cmd_hkmap = !cmd_hkmap; |
2274 goto cmdline_not_changed; | |
2275 #endif | |
2276 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2277 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
|
2278 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
|
2279 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
|
2280 |
7 | 2281 default: |
2282 #ifdef UNIX | |
2283 if (c == intr_char) | |
2284 { | |
2285 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2286 putting it in history */ | |
2287 goto returncmd; /* back to Normal mode */ | |
2288 } | |
2289 #endif | |
2290 /* | |
2291 * Normal character with no special meaning. Just set mod_mask | |
2292 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2293 * the string <S-Space>. This should only happen after ^V. | |
2294 */ | |
2295 if (!IS_SPECIAL(c)) | |
2296 mod_mask = 0x0; | |
2297 break; | |
2298 } | |
2299 /* | |
2300 * End of switch on command line character. | |
2301 * We come here if we have a normal character. | |
2302 */ | |
2303 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2304 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2305 #ifdef FEAT_MBYTE |
2306 /* Add ABBR_OFF for characters above 0x100, this is | |
2307 * what check_abbr() expects. */ | |
2308 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2309 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2310 c) || c == Ctrl_RSB)) |
7 | 2311 goto cmdline_changed; |
2312 | |
2313 /* | |
2314 * put the character in the command line | |
2315 */ | |
2316 if (IS_SPECIAL(c) || mod_mask != 0) | |
2317 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2318 else | |
2319 { | |
2320 #ifdef FEAT_MBYTE | |
2321 if (has_mbyte) | |
2322 { | |
2323 j = (*mb_char2bytes)(c, IObuff); | |
2324 IObuff[j] = NUL; /* exclude composing chars */ | |
2325 put_on_cmdline(IObuff, j, TRUE); | |
2326 } | |
2327 else | |
2328 #endif | |
2329 { | |
2330 IObuff[0] = c; | |
2331 put_on_cmdline(IObuff, 1, TRUE); | |
2332 } | |
2333 } | |
2334 goto cmdline_changed; | |
2335 | |
2336 /* | |
2337 * This part implements incremental searches for "/" and "?" | |
2338 * Jump to cmdline_not_changed when a character has been read but the command | |
2339 * line did not change. Then we only search and redraw if something changed in | |
2340 * the past. | |
2341 * Jump to cmdline_changed when the command line did change. | |
2342 * (Sorry for the goto's, I know it is ugly). | |
2343 */ | |
2344 cmdline_not_changed: | |
2345 #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
|
2346 if (!is_state.incsearch_postponed) |
7 | 2347 continue; |
2348 #endif | |
2349 | |
2350 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
|
2351 /* 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
|
2352 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
|
2353 |
7 | 2354 #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
|
2355 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2356 #endif |
2357 | |
2358 #ifdef FEAT_RIGHTLEFT | |
2359 if (cmdmsg_rl | |
2360 # ifdef FEAT_ARABIC | |
534 | 2361 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2362 # endif |
2363 ) | |
2364 /* Always redraw the whole command line to fix shaping and | |
3374 | 2365 * right-left typing. Not efficient, but it works. |
2366 * Do it only when there are no characters left to read | |
2367 * to avoid useless intermediate redraws. */ | |
2368 if (vpeekc() == NUL) | |
2369 redrawcmd(); | |
7 | 2370 #endif |
2371 } | |
2372 | |
2373 returncmd: | |
2374 | |
2375 #ifdef FEAT_RIGHTLEFT | |
2376 cmdmsg_rl = FALSE; | |
2377 #endif | |
2378 | |
2379 #ifdef FEAT_FKMAP | |
2380 cmd_fkmap = 0; | |
2381 #endif | |
2382 | |
2383 ExpandCleanup(&xpc); | |
1718 | 2384 ccline.xpc = NULL; |
7 | 2385 |
2386 #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
|
2387 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2388 #endif |
2389 | |
2390 if (ccline.cmdbuff != NULL) | |
2391 { | |
2392 /* | |
2393 * Put line in history buffer (":" and "=" only when it was typed). | |
2394 */ | |
2395 #ifdef FEAT_CMDHIST | |
2396 if (ccline.cmdlen && firstc != NUL | |
2397 && (some_key_typed || histype == HIST_SEARCH)) | |
2398 { | |
2399 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2400 histype == HIST_SEARCH ? firstc : NUL); | |
2401 if (firstc == ':') | |
2402 { | |
2403 vim_free(new_last_cmdline); | |
2404 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2405 } | |
2406 } | |
2407 #endif | |
2408 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2409 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
|
2410 abandon_cmdline(); |
7 | 2411 } |
2412 | |
2413 /* | |
2414 * If the screen was shifted up, redraw the whole screen (later). | |
2415 * If the line is too long, clear it, so ruler and shown command do | |
2416 * not get printed in the middle of it. | |
2417 */ | |
2418 msg_check(); | |
2419 msg_scroll = save_msg_scroll; | |
2420 redir_off = FALSE; | |
2421 | |
2422 /* When the command line was typed, no need for a wait-return prompt. */ | |
2423 if (some_key_typed) | |
2424 need_wait_return = FALSE; | |
2425 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2426 /* 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
|
2427 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
|
2428 |
7 | 2429 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2430 #ifdef HAVE_INPUT_METHOD |
7 | 2431 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2432 im_save_status(b_im_ptr); | |
2433 im_set_active(FALSE); | |
2434 #endif | |
2435 #ifdef FEAT_MOUSE | |
2436 setmouse(); | |
2437 #endif | |
2438 #ifdef CURSOR_SHAPE | |
2439 ui_cursor_shape(); /* may show different cursor shape */ | |
2440 #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
|
2441 sb_text_end_cmdline(); |
7 | 2442 |
95 | 2443 { |
2444 char_u *p = ccline.cmdbuff; | |
2445 | |
2446 /* Make ccline empty, getcmdline() may try to use it. */ | |
2447 ccline.cmdbuff = NULL; | |
2448 return p; | |
2449 } | |
7 | 2450 } |
2451 | |
2452 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2453 /* | |
2454 * Get a command line with a prompt. | |
2455 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2456 * f_input() when evaluating an expression from CTRL-R =). | |
2457 * Returns the command line in allocated memory, or NULL. | |
2458 */ | |
2459 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2460 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2461 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2462 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2463 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2464 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2465 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2466 { |
2467 char_u *s; | |
2468 struct cmdline_info save_ccline; | |
2469 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
|
2470 int msg_silent_save = msg_silent; |
7 | 2471 |
95 | 2472 save_cmdline(&save_ccline); |
7 | 2473 ccline.cmdprompt = prompt; |
2474 ccline.cmdattr = attr; | |
531 | 2475 # ifdef FEAT_EVAL |
2476 ccline.xp_context = xp_context; | |
2477 ccline.xp_arg = xp_arg; | |
2478 ccline.input_fn = (firstc == '@'); | |
2479 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2480 msg_silent = 0; |
7 | 2481 s = getcmdline(firstc, 1L, 0); |
95 | 2482 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2483 msg_silent = msg_silent_save; |
3020 | 2484 /* Restore msg_col, the prompt from input() may have changed it. |
2485 * But only if called recursively and the commandline is therefore being | |
2486 * restored to an old one; if not, the input() prompt stays on the screen, | |
2487 * so we need its modified msg_col left intact. */ | |
2488 if (ccline.cmdbuff != NULL) | |
2489 msg_col = msg_col_save; | |
7 | 2490 |
2491 return s; | |
2492 } | |
2493 #endif | |
2494 | |
632 | 2495 /* |
634 | 2496 * Return TRUE when the text must not be changed and we can't switch to |
2497 * another window or buffer. Used when editing the command line, evaluating | |
2498 * 'balloonexpr', etc. | |
632 | 2499 */ |
2500 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2501 text_locked(void) |
632 | 2502 { |
2503 #ifdef FEAT_CMDWIN | |
2504 if (cmdwin_type != 0) | |
2505 return TRUE; | |
2506 #endif | |
634 | 2507 return textlock != 0; |
632 | 2508 } |
2509 | |
2510 /* | |
2511 * Give an error message for a command that isn't allowed while the cmdline | |
2512 * window is open or editing the cmdline in another way. | |
2513 */ | |
2514 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2515 text_locked_msg(void) |
632 | 2516 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2517 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2518 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2519 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2520 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2521 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2522 { |
632 | 2523 #ifdef FEAT_CMDWIN |
2524 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2525 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2526 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2527 return e_secure; |
632 | 2528 } |
2529 | |
819 | 2530 /* |
1834 | 2531 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2532 * and give an error message. | |
819 | 2533 */ |
2534 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2535 curbuf_locked(void) |
819 | 2536 { |
2537 if (curbuf_lock > 0) | |
2538 { | |
2539 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2540 return TRUE; | |
2541 } | |
1834 | 2542 return allbuf_locked(); |
2543 } | |
2544 | |
2545 /* | |
2546 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2547 * message. | |
2548 */ | |
2549 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2550 allbuf_locked(void) |
1834 | 2551 { |
2552 if (allbuf_lock > 0) | |
2553 { | |
2554 EMSG(_("E811: Not allowed to change buffer information now")); | |
2555 return TRUE; | |
2556 } | |
819 | 2557 return FALSE; |
2558 } | |
2559 | |
7 | 2560 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2561 cmdline_charsize(int idx) |
7 | 2562 { |
2563 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2564 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2565 return 1; | |
2566 #endif | |
2567 return ptr2cells(ccline.cmdbuff + idx); | |
2568 } | |
2569 | |
2570 /* | |
2571 * Compute the offset of the cursor on the command line for the prompt and | |
2572 * indent. | |
2573 */ | |
2574 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2575 set_cmdspos(void) |
7 | 2576 { |
531 | 2577 if (ccline.cmdfirstc != NUL) |
7 | 2578 ccline.cmdspos = 1 + ccline.cmdindent; |
2579 else | |
2580 ccline.cmdspos = 0 + ccline.cmdindent; | |
2581 } | |
2582 | |
2583 /* | |
2584 * Compute the screen position for the cursor on the command line. | |
2585 */ | |
2586 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2587 set_cmdspos_cursor(void) |
7 | 2588 { |
2589 int i, m, c; | |
2590 | |
2591 set_cmdspos(); | |
2592 if (KeyTyped) | |
534 | 2593 { |
7 | 2594 m = Columns * Rows; |
534 | 2595 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2596 m = MAXCOL; | |
2597 } | |
7 | 2598 else |
2599 m = MAXCOL; | |
2600 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2601 { | |
2602 c = cmdline_charsize(i); | |
2603 #ifdef FEAT_MBYTE | |
2604 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2605 if (has_mbyte) | |
2606 correct_cmdspos(i, c); | |
2607 #endif | |
1612 | 2608 /* If the cmdline doesn't fit, show cursor on last visible char. |
2609 * Don't move the cursor itself, so we can still append. */ | |
7 | 2610 if ((ccline.cmdspos += c) >= m) |
2611 { | |
2612 ccline.cmdspos -= c; | |
2613 break; | |
2614 } | |
2615 #ifdef FEAT_MBYTE | |
2616 if (has_mbyte) | |
474 | 2617 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2618 #endif |
2619 } | |
2620 } | |
2621 | |
2622 #ifdef FEAT_MBYTE | |
2623 /* | |
2624 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2625 * character that doesn't fit, so that a ">" must be displayed. | |
2626 */ | |
2627 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2628 correct_cmdspos(int idx, int cells) |
7 | 2629 { |
474 | 2630 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2631 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2632 && ccline.cmdspos % Columns + cells > Columns) | |
2633 ccline.cmdspos++; | |
2634 } | |
2635 #endif | |
2636 | |
2637 /* | |
2638 * Get an Ex command line for the ":" command. | |
2639 */ | |
2640 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2641 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2642 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2643 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2644 int indent) /* indent for inside conditionals */ |
7 | 2645 { |
2646 /* When executing a register, remove ':' that's in front of each line. */ | |
2647 if (exec_from_reg && vpeekc() == ':') | |
2648 (void)vgetc(); | |
2649 return getcmdline(c, 1L, indent); | |
2650 } | |
2651 | |
2652 /* | |
2653 * Get an Ex command line for Ex mode. | |
2654 * In Ex mode we only use the OS supplied line editing features and no | |
2655 * mappings or abbreviations. | |
168 | 2656 * Returns a string in allocated memory or NULL. |
7 | 2657 */ |
2658 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2659 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2660 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2661 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2662 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2663 int indent) /* indent for inside conditionals */ |
7 | 2664 { |
168 | 2665 garray_T line_ga; |
2666 char_u *pend; | |
2667 int startcol = 0; | |
1329 | 2668 int c1 = 0; |
168 | 2669 int escaped = FALSE; /* CTRL-V typed */ |
2670 int vcol = 0; | |
2671 char_u *p; | |
1329 | 2672 int prev_char; |
5966 | 2673 int len; |
7 | 2674 |
2675 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2676 * confuses the system function that computes tabstops. */ | |
2677 cursor_on(); | |
2678 | |
2679 /* always start in column 0; write a newline if necessary */ | |
2680 compute_cmdrow(); | |
168 | 2681 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2682 msg_putchar('\n'); |
168 | 2683 if (promptc == ':') |
7 | 2684 { |
164 | 2685 /* indent that is only displayed, not in the line itself */ |
168 | 2686 if (p_prompt) |
2687 msg_putchar(':'); | |
7 | 2688 while (indent-- > 0) |
2689 msg_putchar(' '); | |
2690 startcol = msg_col; | |
2691 } | |
2692 | |
2693 ga_init2(&line_ga, 1, 30); | |
2694 | |
164 | 2695 /* autoindent for :insert and :append is in the line itself */ |
168 | 2696 if (promptc <= 0) |
164 | 2697 { |
2698 vcol = indent; | |
2699 while (indent >= 8) | |
2700 { | |
2701 ga_append(&line_ga, TAB); | |
2702 msg_puts((char_u *)" "); | |
2703 indent -= 8; | |
2704 } | |
2705 while (indent-- > 0) | |
2706 { | |
2707 ga_append(&line_ga, ' '); | |
2708 msg_putchar(' '); | |
2709 } | |
2710 } | |
168 | 2711 ++no_mapping; |
2712 ++allow_keys; | |
164 | 2713 |
7 | 2714 /* |
2715 * Get the line, one character at a time. | |
2716 */ | |
2717 got_int = FALSE; | |
168 | 2718 while (!got_int) |
7 | 2719 { |
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
|
2720 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
|
2721 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
|
2722 |
7 | 2723 if (ga_grow(&line_ga, 40) == FAIL) |
2724 break; | |
2725 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2726 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2727 * 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
|
2728 */ |
1329 | 2729 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
|
2730 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2731 /* 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
|
2732 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
|
2733 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
|
2734 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2735 c1 = vgetc(); |
7 | 2736 |
2737 /* | |
168 | 2738 * Handle line editing. |
2739 * Previously this was left to the system, putting the terminal in | |
2740 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2741 */ |
168 | 2742 if (got_int) |
2743 { | |
2744 msg_putchar('\n'); | |
2745 break; | |
2746 } | |
2747 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2748 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
|
2749 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2750 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
|
2751 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
|
2752 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2753 |
168 | 2754 if (!escaped) |
7 | 2755 { |
168 | 2756 /* CR typed means "enter", which is NL */ |
2757 if (c1 == '\r') | |
2758 c1 = '\n'; | |
2759 | |
2760 if (c1 == BS || c1 == K_BS | |
2761 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2762 { |
168 | 2763 if (line_ga.ga_len > 0) |
2764 { | |
5966 | 2765 #ifdef FEAT_MBYTE |
2766 if (has_mbyte) | |
2767 { | |
2768 p = (char_u *)line_ga.ga_data; | |
2769 p[line_ga.ga_len] = NUL; | |
2770 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2771 line_ga.ga_len -= len; | |
2772 } | |
2773 else | |
2774 #endif | |
2775 --line_ga.ga_len; | |
168 | 2776 goto redraw; |
2777 } | |
2778 continue; | |
7 | 2779 } |
2780 | |
168 | 2781 if (c1 == Ctrl_U) |
7 | 2782 { |
168 | 2783 msg_col = startcol; |
2784 msg_clr_eos(); | |
2785 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
|
2786 goto redraw; |
168 | 2787 } |
2788 | |
2789 if (c1 == Ctrl_T) | |
2790 { | |
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
|
2791 sw = get_sw_value(curbuf); |
168 | 2792 p = (char_u *)line_ga.ga_data; |
2793 p[line_ga.ga_len] = NUL; | |
5995 | 2794 indent = get_indent_str(p, 8, FALSE); |
3740 | 2795 indent += sw - indent % sw; |
168 | 2796 add_indent: |
5995 | 2797 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2798 { |
7009 | 2799 (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
|
2800 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
|
2801 s = skipwhite(p); |
168 | 2802 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2803 *s = ' '; | |
2804 ++line_ga.ga_len; | |
7 | 2805 } |
168 | 2806 redraw: |
2807 /* redraw the line */ | |
2808 msg_col = startcol; | |
2809 vcol = 0; | |
5966 | 2810 p = (char_u *)line_ga.ga_data; |
2811 p[line_ga.ga_len] = NUL; | |
2812 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2813 { |
168 | 2814 if (*p == TAB) |
7 | 2815 { |
168 | 2816 do |
7 | 2817 { |
168 | 2818 msg_putchar(' '); |
2819 } while (++vcol % 8); | |
5966 | 2820 ++p; |
7 | 2821 } |
168 | 2822 else |
164 | 2823 { |
5966 | 2824 len = MB_PTR2LEN(p); |
2825 msg_outtrans_len(p, len); | |
2826 vcol += ptr2cells(p); | |
2827 p += len; | |
7 | 2828 } |
2829 } | |
168 | 2830 msg_clr_eos(); |
1329 | 2831 windgoto(msg_row, msg_col); |
168 | 2832 continue; |
2833 } | |
2834 | |
2835 if (c1 == Ctrl_D) | |
2836 { | |
2837 /* Delete one shiftwidth. */ | |
2838 p = (char_u *)line_ga.ga_data; | |
2839 if (prev_char == '0' || prev_char == '^') | |
7 | 2840 { |
168 | 2841 if (prev_char == '^') |
2842 ex_keep_indent = TRUE; | |
2843 indent = 0; | |
2844 p[--line_ga.ga_len] = NUL; | |
7 | 2845 } |
2846 else | |
2847 { | |
168 | 2848 p[line_ga.ga_len] = NUL; |
5995 | 2849 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
|
2850 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
|
2851 { |
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
|
2852 --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
|
2853 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
|
2854 } |
168 | 2855 } |
5995 | 2856 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2857 { |
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
|
2858 s = skipwhite(p); |
168 | 2859 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2860 --line_ga.ga_len; | |
7 | 2861 } |
168 | 2862 goto add_indent; |
2863 } | |
2864 | |
2865 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2866 { | |
2867 escaped = TRUE; | |
2868 continue; | |
7 | 2869 } |
168 | 2870 |
2871 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2872 if (IS_SPECIAL(c1)) | |
2873 continue; | |
7 | 2874 } |
168 | 2875 |
2876 if (IS_SPECIAL(c1)) | |
2877 c1 = '?'; | |
5966 | 2878 #ifdef FEAT_MBYTE |
2879 if (has_mbyte) | |
2880 len = (*mb_char2bytes)(c1, | |
2881 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2882 else | |
2883 #endif | |
2884 { | |
2885 len = 1; | |
2886 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2887 } | |
168 | 2888 if (c1 == '\n') |
2889 msg_putchar('\n'); | |
2890 else if (c1 == TAB) | |
2891 { | |
2892 /* Don't use chartabsize(), 'ts' can be different */ | |
2893 do | |
2894 { | |
2895 msg_putchar(' '); | |
2896 } while (++vcol % 8); | |
2897 } | |
7 | 2898 else |
2899 { | |
168 | 2900 msg_outtrans_len( |
5966 | 2901 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2902 vcol += char2cells(c1); |
7 | 2903 } |
5966 | 2904 line_ga.ga_len += len; |
168 | 2905 escaped = FALSE; |
2906 | |
2907 windgoto(msg_row, msg_col); | |
164 | 2908 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2909 |
2590 | 2910 /* We are done when a NL is entered, but not when it comes after an |
2911 * odd number of backslashes, that results in a NUL. */ | |
2912 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2913 { |
2590 | 2914 int bcount = 0; |
2915 | |
2916 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2917 ++bcount; | |
2918 | |
2919 if (bcount > 0) | |
2920 { | |
2921 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2922 * "\NL", etc. */ | |
2923 line_ga.ga_len -= (bcount + 1) / 2; | |
2924 pend -= (bcount + 1) / 2; | |
2925 pend[-1] = '\n'; | |
2926 } | |
2927 | |
2928 if ((bcount & 1) == 0) | |
2929 { | |
2930 --line_ga.ga_len; | |
2931 --pend; | |
2932 *pend = NUL; | |
2933 break; | |
2934 } | |
7 | 2935 } |
2936 } | |
2937 | |
168 | 2938 --no_mapping; |
2939 --allow_keys; | |
2940 | |
7 | 2941 /* make following messages go to the next line */ |
2942 msg_didout = FALSE; | |
2943 msg_col = 0; | |
2944 if (msg_row < Rows - 1) | |
2945 ++msg_row; | |
2946 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2947 | |
2948 if (got_int) | |
2949 ga_clear(&line_ga); | |
2950 | |
2951 return (char_u *)line_ga.ga_data; | |
2952 } | |
2953 | |
502 | 2954 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2955 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2956 /* |
2957 * Return TRUE if ccline.overstrike is on. | |
2958 */ | |
2959 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2960 cmdline_overstrike(void) |
7 | 2961 { |
2962 return ccline.overstrike; | |
2963 } | |
2964 | |
2965 /* | |
2966 * Return TRUE if the cursor is at the end of the cmdline. | |
2967 */ | |
2968 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2969 cmdline_at_end(void) |
7 | 2970 { |
2971 return (ccline.cmdpos >= ccline.cmdlen); | |
2972 } | |
2973 #endif | |
2974 | |
574 | 2975 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2976 /* |
2977 * Return the virtual column number at the current cursor position. | |
2978 * This is used by the IM code to obtain the start of the preedit string. | |
2979 */ | |
2980 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2981 cmdline_getvcol_cursor(void) |
7 | 2982 { |
2983 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2984 return MAXCOL; | |
2985 | |
2986 # ifdef FEAT_MBYTE | |
2987 if (has_mbyte) | |
2988 { | |
2989 colnr_T col; | |
2990 int i = 0; | |
2991 | |
2992 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2993 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2994 |
2995 return col; | |
2996 } | |
2997 else | |
2998 # endif | |
2999 return ccline.cmdpos; | |
3000 } | |
3001 #endif | |
3002 | |
3003 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3004 /* | |
3005 * If part of the command line is an IM preedit string, redraw it with | |
3006 * IM feedback attributes. The cursor position is restored after drawing. | |
3007 */ | |
3008 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3009 redrawcmd_preedit(void) |
7 | 3010 { |
3011 if ((State & CMDLINE) | |
3012 && xic != NULL | |
976 | 3013 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3014 && !p_imdisable |
3015 && im_is_preediting()) | |
3016 { | |
3017 int cmdpos = 0; | |
3018 int cmdspos; | |
3019 int old_row; | |
3020 int old_col; | |
3021 colnr_T col; | |
3022 | |
3023 old_row = msg_row; | |
3024 old_col = msg_col; | |
531 | 3025 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3026 |
3027 # ifdef FEAT_MBYTE | |
3028 if (has_mbyte) | |
3029 { | |
3030 for (col = 0; col < preedit_start_col | |
3031 && cmdpos < ccline.cmdlen; ++col) | |
3032 { | |
3033 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3034 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3035 } |
3036 } | |
3037 else | |
3038 # endif | |
3039 { | |
3040 cmdspos += preedit_start_col; | |
3041 cmdpos += preedit_start_col; | |
3042 } | |
3043 | |
3044 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3045 msg_col = cmdspos % (int)Columns; | |
3046 if (msg_row >= Rows) | |
3047 msg_row = Rows - 1; | |
3048 | |
3049 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3050 { | |
3051 int char_len; | |
3052 int char_attr; | |
3053 | |
3054 char_attr = im_get_feedback_attr(col); | |
3055 if (char_attr < 0) | |
3056 break; /* end of preedit string */ | |
3057 | |
3058 # ifdef FEAT_MBYTE | |
3059 if (has_mbyte) | |
474 | 3060 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3061 else |
3062 # endif | |
3063 char_len = 1; | |
3064 | |
3065 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3066 cmdpos += char_len; | |
3067 } | |
3068 | |
3069 msg_row = old_row; | |
3070 msg_col = old_col; | |
3071 } | |
3072 } | |
3073 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3074 | |
3075 /* | |
3076 * Allocate a new command line buffer. | |
3077 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3078 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3079 */ | |
3080 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3081 alloc_cmdbuff(int len) |
7 | 3082 { |
3083 /* | |
3084 * give some extra space to avoid having to allocate all the time | |
3085 */ | |
3086 if (len < 80) | |
3087 len = 100; | |
3088 else | |
3089 len += 20; | |
3090 | |
3091 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3092 ccline.cmdbufflen = len; | |
3093 } | |
3094 | |
3095 /* | |
3096 * Re-allocate the command line to length len + something extra. | |
3097 * return FAIL for failure, OK otherwise | |
3098 */ | |
3099 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3100 realloc_cmdbuff(int len) |
7 | 3101 { |
3102 char_u *p; | |
3103 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3104 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3105 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
|
3106 |
7 | 3107 p = ccline.cmdbuff; |
3108 alloc_cmdbuff(len); /* will get some more */ | |
3109 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3110 { | |
3111 ccline.cmdbuff = p; /* keep the old one */ | |
3112 return FAIL; | |
3113 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3114 /* 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
|
3115 * 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
|
3116 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
|
3117 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3118 vim_free(p); |
1718 | 3119 |
3120 if (ccline.xpc != NULL | |
3121 && ccline.xpc->xp_pattern != NULL | |
3122 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3123 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3124 { | |
1754 | 3125 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3126 |
3127 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3128 * to point into the newly allocated memory. */ | |
3129 if (i >= 0 && i <= ccline.cmdlen) | |
3130 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3131 } | |
3132 | |
7 | 3133 return OK; |
3134 } | |
3135 | |
359 | 3136 #if defined(FEAT_ARABIC) || defined(PROTO) |
3137 static char_u *arshape_buf = NULL; | |
3138 | |
3139 # if defined(EXITFREE) || defined(PROTO) | |
3140 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3141 free_cmdline_buf(void) |
359 | 3142 { |
3143 vim_free(arshape_buf); | |
3144 } | |
3145 # endif | |
3146 #endif | |
3147 | |
7 | 3148 /* |
3149 * Draw part of the cmdline at the current cursor position. But draw stars | |
3150 * when cmdline_star is TRUE. | |
3151 */ | |
3152 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3153 draw_cmdline(int start, int len) |
7 | 3154 { |
3155 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3156 int i; | |
3157 | |
3158 if (cmdline_star > 0) | |
3159 for (i = 0; i < len; ++i) | |
3160 { | |
3161 msg_putchar('*'); | |
3162 # ifdef FEAT_MBYTE | |
3163 if (has_mbyte) | |
474 | 3164 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3165 # endif |
3166 } | |
3167 else | |
3168 #endif | |
3169 #ifdef FEAT_ARABIC | |
3170 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3171 { | |
3172 static int buflen = 0; | |
3173 char_u *p; | |
3174 int j; | |
3175 int newlen = 0; | |
3176 int mb_l; | |
719 | 3177 int pc, pc1 = 0; |
7 | 3178 int prev_c = 0; |
3179 int prev_c1 = 0; | |
714 | 3180 int u8c; |
3181 int u8cc[MAX_MCO]; | |
7 | 3182 int nc = 0; |
3183 | |
3184 /* | |
3185 * Do arabic shaping into a temporary buffer. This is very | |
3186 * inefficient! | |
3187 */ | |
507 | 3188 if (len * 2 + 2 > buflen) |
7 | 3189 { |
3190 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3191 * alloc()/free() calls. */ | |
359 | 3192 vim_free(arshape_buf); |
507 | 3193 buflen = len * 2 + 2; |
359 | 3194 arshape_buf = alloc(buflen); |
3195 if (arshape_buf == NULL) | |
7 | 3196 return; /* out of memory */ |
3197 } | |
3198 | |
507 | 3199 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3200 { | |
3201 /* Prepend a space to draw the leading composing char on. */ | |
3202 arshape_buf[0] = ' '; | |
3203 newlen = 1; | |
3204 } | |
3205 | |
7 | 3206 for (j = start; j < start + len; j += mb_l) |
3207 { | |
3208 p = ccline.cmdbuff + j; | |
714 | 3209 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3210 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3211 if (ARABIC_CHAR(u8c)) |
3212 { | |
3213 /* Do Arabic shaping. */ | |
3214 if (cmdmsg_rl) | |
3215 { | |
3216 /* displaying from right to left */ | |
3217 pc = prev_c; | |
3218 pc1 = prev_c1; | |
714 | 3219 prev_c1 = u8cc[0]; |
7 | 3220 if (j + mb_l >= start + len) |
3221 nc = NUL; | |
3222 else | |
3223 nc = utf_ptr2char(p + mb_l); | |
3224 } | |
3225 else | |
3226 { | |
3227 /* displaying from left to right */ | |
3228 if (j + mb_l >= start + len) | |
3229 pc = NUL; | |
3230 else | |
714 | 3231 { |
3232 int pcc[MAX_MCO]; | |
3233 | |
3234 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3235 start + len - j - mb_l); |
714 | 3236 pc1 = pcc[0]; |
3237 } | |
7 | 3238 nc = prev_c; |
3239 } | |
3240 prev_c = u8c; | |
3241 | |
714 | 3242 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3243 |
359 | 3244 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3245 if (u8cc[0] != 0) |
7 | 3246 { |
714 | 3247 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3248 if (u8cc[1] != 0) | |
3249 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3250 arshape_buf + newlen); |
7 | 3251 } |
3252 } | |
3253 else | |
3254 { | |
3255 prev_c = u8c; | |
359 | 3256 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3257 newlen += mb_l; |
3258 } | |
3259 } | |
3260 | |
359 | 3261 msg_outtrans_len(arshape_buf, newlen); |
7 | 3262 } |
3263 else | |
3264 #endif | |
3265 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3266 } | |
3267 | |
3268 /* | |
3269 * Put a character on the command line. Shifts the following text to the | |
3270 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3271 * "c" must be printable (fit in one display cell)! | |
3272 */ | |
3273 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3274 putcmdline(int c, int shift) |
7 | 3275 { |
3276 if (cmd_silent) | |
3277 return; | |
3278 msg_no_more = TRUE; | |
3279 msg_putchar(c); | |
3280 if (shift) | |
3281 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3282 msg_no_more = FALSE; | |
3283 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3284 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3285 extra_char_shift = shift; |
7 | 3286 } |
3287 | |
3288 /* | |
3289 * Undo a putcmdline(c, FALSE). | |
3290 */ | |
3291 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3292 unputcmdline(void) |
7 | 3293 { |
3294 if (cmd_silent) | |
3295 return; | |
3296 msg_no_more = TRUE; | |
3297 if (ccline.cmdlen == ccline.cmdpos) | |
3298 msg_putchar(' '); | |
3558 | 3299 #ifdef FEAT_MBYTE |
3300 else if (has_mbyte) | |
3301 draw_cmdline(ccline.cmdpos, | |
3302 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3303 #endif | |
7 | 3304 else |
3305 draw_cmdline(ccline.cmdpos, 1); | |
3306 msg_no_more = FALSE; | |
3307 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3308 extra_char = NUL; |
7 | 3309 } |
3310 | |
3311 /* | |
3312 * Put the given string, of the given length, onto the command line. | |
3313 * If len is -1, then STRLEN() is used to calculate the length. | |
3314 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3315 * part will be redrawn, otherwise it will not. If this function is called | |
3316 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3317 * called afterwards. | |
3318 */ | |
3319 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3320 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3321 { |
3322 int retval; | |
3323 int i; | |
3324 int m; | |
3325 int c; | |
3326 | |
3327 if (len < 0) | |
3328 len = (int)STRLEN(str); | |
3329 | |
3330 /* Check if ccline.cmdbuff needs to be longer */ | |
3331 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
|
3332 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3333 else |
3334 retval = OK; | |
3335 if (retval == OK) | |
3336 { | |
3337 if (!ccline.overstrike) | |
3338 { | |
3339 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3340 ccline.cmdbuff + ccline.cmdpos, | |
3341 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3342 ccline.cmdlen += len; | |
3343 } | |
3344 else | |
3345 { | |
3346 #ifdef FEAT_MBYTE | |
3347 if (has_mbyte) | |
3348 { | |
3349 /* Count nr of characters in the new string. */ | |
3350 m = 0; | |
474 | 3351 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3352 ++m; |
3353 /* Count nr of bytes in cmdline that are overwritten by these | |
3354 * characters. */ | |
3355 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3356 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3357 --m; |
3358 if (i < ccline.cmdlen) | |
3359 { | |
3360 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3361 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3362 ccline.cmdlen += ccline.cmdpos + len - i; | |
3363 } | |
3364 else | |
3365 ccline.cmdlen = ccline.cmdpos + len; | |
3366 } | |
3367 else | |
3368 #endif | |
3369 if (ccline.cmdpos + len > ccline.cmdlen) | |
3370 ccline.cmdlen = ccline.cmdpos + len; | |
3371 } | |
3372 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3373 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3374 | |
3375 #ifdef FEAT_MBYTE | |
3376 if (enc_utf8) | |
3377 { | |
3378 /* When the inserted text starts with a composing character, | |
3379 * backup to the character before it. There could be two of them. | |
3380 */ | |
3381 i = 0; | |
3382 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3383 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3384 { | |
3385 i = (*mb_head_off)(ccline.cmdbuff, | |
3386 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3387 ccline.cmdpos -= i; | |
3388 len += i; | |
3389 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3390 } | |
3391 # ifdef FEAT_ARABIC | |
3392 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3393 { | |
3394 /* Check the previous character for Arabic combining pair. */ | |
3395 i = (*mb_head_off)(ccline.cmdbuff, | |
3396 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3397 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3398 + ccline.cmdpos - i), c)) | |
3399 { | |
3400 ccline.cmdpos -= i; | |
3401 len += i; | |
3402 } | |
3403 else | |
3404 i = 0; | |
3405 } | |
3406 # endif | |
3407 if (i != 0) | |
3408 { | |
3409 /* Also backup the cursor position. */ | |
3410 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3411 ccline.cmdspos -= i; | |
3412 msg_col -= i; | |
3413 if (msg_col < 0) | |
3414 { | |
3415 msg_col += Columns; | |
3416 --msg_row; | |
3417 } | |
3418 } | |
3419 } | |
3420 #endif | |
3421 | |
3422 if (redraw && !cmd_silent) | |
3423 { | |
3424 msg_no_more = TRUE; | |
3425 i = cmdline_row; | |
3114 | 3426 cursorcmd(); |
7 | 3427 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3428 /* Avoid clearing the rest of the line too often. */ | |
3429 if (cmdline_row != i || ccline.overstrike) | |
3430 msg_clr_eos(); | |
3431 msg_no_more = FALSE; | |
3432 } | |
3433 #ifdef FEAT_FKMAP | |
3434 /* | |
3435 * If we are in Farsi command mode, the character input must be in | |
3436 * Insert mode. So do not advance the cmdpos. | |
3437 */ | |
3438 if (!cmd_fkmap) | |
3439 #endif | |
3440 { | |
3441 if (KeyTyped) | |
534 | 3442 { |
7 | 3443 m = Columns * Rows; |
534 | 3444 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3445 m = MAXCOL; | |
3446 } | |
7 | 3447 else |
3448 m = MAXCOL; | |
3449 for (i = 0; i < len; ++i) | |
3450 { | |
3451 c = cmdline_charsize(ccline.cmdpos); | |
3452 #ifdef FEAT_MBYTE | |
3453 /* count ">" for a double-wide char that doesn't fit. */ | |
3454 if (has_mbyte) | |
3455 correct_cmdspos(ccline.cmdpos, c); | |
3456 #endif | |
1612 | 3457 /* Stop cursor at the end of the screen, but do increment the |
3458 * insert position, so that entering a very long command | |
3459 * works, even though you can't see it. */ | |
3460 if (ccline.cmdspos + c < m) | |
3461 ccline.cmdspos += c; | |
7 | 3462 #ifdef FEAT_MBYTE |
3463 if (has_mbyte) | |
3464 { | |
474 | 3465 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3466 if (c > len - i - 1) |
3467 c = len - i - 1; | |
3468 ccline.cmdpos += c; | |
3469 i += c; | |
3470 } | |
3471 #endif | |
3472 ++ccline.cmdpos; | |
3473 } | |
3474 } | |
3475 } | |
3476 if (redraw) | |
3477 msg_check(); | |
3478 return retval; | |
3479 } | |
3480 | |
95 | 3481 static struct cmdline_info prev_ccline; |
3482 static int prev_ccline_used = FALSE; | |
3483 | |
3484 /* | |
3485 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3486 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3487 * available globally in prev_ccline. | |
3488 */ | |
3489 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3490 save_cmdline(struct cmdline_info *ccp) |
95 | 3491 { |
3492 if (!prev_ccline_used) | |
3493 { | |
3494 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3495 prev_ccline_used = TRUE; | |
3496 } | |
3497 *ccp = prev_ccline; | |
3498 prev_ccline = ccline; | |
3499 ccline.cmdbuff = NULL; | |
3500 ccline.cmdprompt = NULL; | |
1718 | 3501 ccline.xpc = NULL; |
95 | 3502 } |
3503 | |
3504 /* | |
1214 | 3505 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3506 */ |
3507 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3508 restore_cmdline(struct cmdline_info *ccp) |
95 | 3509 { |
3510 ccline = prev_ccline; | |
3511 prev_ccline = *ccp; | |
3512 } | |
3513 | |
849 | 3514 #if defined(FEAT_EVAL) || defined(PROTO) |
3515 /* | |
3516 * Save the command line into allocated memory. Returns a pointer to be | |
3517 * passed to restore_cmdline_alloc() later. | |
3518 * Returns NULL when failed. | |
3519 */ | |
3520 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3521 save_cmdline_alloc(void) |
849 | 3522 { |
3523 struct cmdline_info *p; | |
3524 | |
3525 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3526 if (p != NULL) | |
3527 save_cmdline(p); | |
3528 return (char_u *)p; | |
3529 } | |
3530 | |
3531 /* | |
3532 * Restore the command line from the return value of save_cmdline_alloc(). | |
3533 */ | |
3534 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3535 restore_cmdline_alloc(char_u *p) |
849 | 3536 { |
3537 if (p != NULL) | |
3538 { | |
3539 restore_cmdline((struct cmdline_info *)p); | |
3540 vim_free(p); | |
3541 } | |
3542 } | |
3543 #endif | |
3544 | |
15 | 3545 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3546 * 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
|
3547 * Used by CTRL-R command in command-line mode. |
15 | 3548 * insert_reg() can't be used here, because special characters from the |
3549 * register contents will be interpreted as commands. | |
3550 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3551 * Return FAIL for failure, OK otherwise. |
15 | 3552 */ |
3553 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3554 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3555 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3556 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
|
3557 int remcr) /* remove trailing CR */ |
15 | 3558 { |
3559 long i; | |
3560 char_u *arg; | |
772 | 3561 char_u *p; |
15 | 3562 int allocated; |
3563 struct cmdline_info save_ccline; | |
3564 | |
3565 /* check for valid regname; also accept special characters for CTRL-R in | |
3566 * the command line */ | |
3567 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
|
3568 && 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
|
3569 && !valid_yank_reg(regname, FALSE)) |
15 | 3570 return FAIL; |
3571 | |
3572 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3573 * CTRL-C to break the loop. */ | |
3574 line_breakcheck(); | |
3575 if (got_int) | |
3576 return FAIL; | |
3577 | |
3578 #ifdef FEAT_CLIPBOARD | |
3579 regname = may_get_selection(regname); | |
3580 #endif | |
3581 | |
634 | 3582 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3583 * things like going to another buffer when evaluating an expression. */ |
95 | 3584 save_cmdline(&save_ccline); |
634 | 3585 ++textlock; |
15 | 3586 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3587 --textlock; |
95 | 3588 restore_cmdline(&save_ccline); |
15 | 3589 |
3590 if (i) | |
3591 { | |
3592 /* Got the value of a special register in "arg". */ | |
3593 if (arg == NULL) | |
3594 return FAIL; | |
772 | 3595 |
3596 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3597 * part of the word. */ | |
3598 p = arg; | |
3599 if (p_is && regname == Ctrl_W) | |
3600 { | |
3601 char_u *w; | |
3602 int len; | |
3603 | |
3604 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3605 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3606 { |
3607 #ifdef FEAT_MBYTE | |
3608 if (has_mbyte) | |
3609 { | |
3610 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3611 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3612 break; | |
3613 w -= len; | |
3614 } | |
3615 else | |
3616 #endif | |
3617 { | |
3618 if (!vim_iswordc(w[-1])) | |
3619 break; | |
3620 --w; | |
3621 } | |
3622 } | |
2937 | 3623 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3624 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3625 p += len; | |
3626 } | |
3627 | |
3628 cmdline_paste_str(p, literally); | |
15 | 3629 if (allocated) |
3630 vim_free(arg); | |
3631 return OK; | |
3632 } | |
3633 | |
1015 | 3634 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3635 } |
3636 | |
3637 /* | |
3638 * Put a string on the command line. | |
3639 * When "literally" is TRUE, insert literally. | |
3640 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3641 * line. | |
3642 */ | |
3643 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3644 cmdline_paste_str(char_u *s, int literally) |
15 | 3645 { |
3646 int c, cv; | |
3647 | |
3648 if (literally) | |
3649 put_on_cmdline(s, -1, TRUE); | |
3650 else | |
3651 while (*s != NUL) | |
3652 { | |
3653 cv = *s; | |
3654 if (cv == Ctrl_V && s[1]) | |
3655 ++s; | |
3656 #ifdef FEAT_MBYTE | |
3657 if (has_mbyte) | |
1606 | 3658 c = mb_cptr2char_adv(&s); |
15 | 3659 else |
3660 #endif | |
3661 c = *s++; | |
3628 | 3662 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3663 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3664 #ifdef UNIX |
3665 || c == intr_char | |
3666 #endif | |
3667 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3668 stuffcharReadbuff(Ctrl_V); | |
3669 stuffcharReadbuff(c); | |
3670 } | |
3671 } | |
3672 | |
7 | 3673 #ifdef FEAT_WILDMENU |
3674 /* | |
3675 * Delete characters on the command line, from "from" to the current | |
3676 * position. | |
3677 */ | |
3678 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3679 cmdline_del(int from) |
7 | 3680 { |
3681 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3682 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3683 ccline.cmdlen -= ccline.cmdpos - from; | |
3684 ccline.cmdpos = from; | |
3685 } | |
3686 #endif | |
3687 | |
3688 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3689 * 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
|
3690 * 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
|
3691 * overwritten. |
7 | 3692 */ |
3693 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3694 redrawcmdline(void) |
7 | 3695 { |
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
|
3696 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
|
3697 } |
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
|
3698 |
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
|
3699 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
|
3700 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
|
3701 { |
7 | 3702 if (cmd_silent) |
3703 return; | |
3704 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
|
3705 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
|
3706 compute_cmdrow(); |
7 | 3707 redrawcmd(); |
3708 cursorcmd(); | |
3709 } | |
3710 | |
3711 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3712 redrawcmdprompt(void) |
7 | 3713 { |
3714 int i; | |
3715 | |
3716 if (cmd_silent) | |
3717 return; | |
531 | 3718 if (ccline.cmdfirstc != NUL) |
7 | 3719 msg_putchar(ccline.cmdfirstc); |
3720 if (ccline.cmdprompt != NULL) | |
3721 { | |
3722 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3723 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3724 /* do the reverse of set_cmdspos() */ | |
531 | 3725 if (ccline.cmdfirstc != NUL) |
7 | 3726 --ccline.cmdindent; |
3727 } | |
3728 else | |
3729 for (i = ccline.cmdindent; i > 0; --i) | |
3730 msg_putchar(' '); | |
3731 } | |
3732 | |
3733 /* | |
3734 * Redraw what is currently on the command line. | |
3735 */ | |
3736 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3737 redrawcmd(void) |
7 | 3738 { |
3739 if (cmd_silent) | |
3740 return; | |
3741 | |
683 | 3742 /* when 'incsearch' is set there may be no command line while redrawing */ |
3743 if (ccline.cmdbuff == NULL) | |
3744 { | |
3745 windgoto(cmdline_row, 0); | |
3746 msg_clr_eos(); | |
3747 return; | |
3748 } | |
3749 | |
7 | 3750 msg_start(); |
3751 redrawcmdprompt(); | |
3752 | |
3753 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3754 msg_no_more = TRUE; | |
3755 draw_cmdline(0, ccline.cmdlen); | |
3756 msg_clr_eos(); | |
3757 msg_no_more = FALSE; | |
3758 | |
3759 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
|
3760 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
|
3761 putcmdline(extra_char, extra_char_shift); |
7 | 3762 |
3763 /* | |
3764 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3765 * in cmdline mode we can reset them now. | |
3766 */ | |
3767 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3768 | |
3769 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3770 * in cmdline mode */ | |
3771 skip_redraw = FALSE; | |
3772 } | |
3773 | |
3774 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3775 compute_cmdrow(void) |
7 | 3776 { |
540 | 3777 if (exmode_active || msg_scrolled != 0) |
7 | 3778 cmdline_row = Rows - 1; |
3779 else | |
3780 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
|
3781 + lastwin->w_status_height; |
7 | 3782 } |
3783 | |
3784 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3785 cursorcmd(void) |
7 | 3786 { |
3787 if (cmd_silent) | |
3788 return; | |
3789 | |
3790 #ifdef FEAT_RIGHTLEFT | |
3791 if (cmdmsg_rl) | |
3792 { | |
3793 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3794 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3795 if (msg_row <= 0) | |
3796 msg_row = Rows - 1; | |
3797 } | |
3798 else | |
3799 #endif | |
3800 { | |
3801 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3802 msg_col = ccline.cmdspos % (int)Columns; | |
3803 if (msg_row >= Rows) | |
3804 msg_row = Rows - 1; | |
3805 } | |
3806 | |
3807 windgoto(msg_row, msg_col); | |
3808 #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
|
3809 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
|
3810 redrawcmd_preedit(); |
7 | 3811 #endif |
3812 #ifdef MCH_CURSOR_SHAPE | |
3813 mch_update_cursor(); | |
3814 #endif | |
3815 } | |
3816 | |
3817 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3818 gotocmdline(int clr) |
7 | 3819 { |
3820 msg_start(); | |
3821 #ifdef FEAT_RIGHTLEFT | |
3822 if (cmdmsg_rl) | |
3823 msg_col = Columns - 1; | |
3824 else | |
3825 #endif | |
3826 msg_col = 0; /* always start in column 0 */ | |
3827 if (clr) /* clear the bottom line(s) */ | |
3828 msg_clr_eos(); /* will reset clear_cmdline */ | |
3829 windgoto(cmdline_row, 0); | |
3830 } | |
3831 | |
3832 /* | |
3833 * Check the word in front of the cursor for an abbreviation. | |
3834 * Called when the non-id character "c" has been entered. | |
3835 * When an abbreviation is recognized it is removed from the text with | |
3836 * backspaces and the replacement string is inserted, followed by "c". | |
3837 */ | |
3838 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3839 ccheck_abbr(int c) |
7 | 3840 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3841 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3842 |
7 | 3843 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3844 return FALSE; | |
3845 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3846 /* 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
|
3847 * 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
|
3848 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
|
3849 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3850 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
|
3851 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3852 && 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
|
3853 && 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
|
3854 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3855 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3856 /* 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
|
3857 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3858 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3859 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3860 } |
3861 | |
3164 | 3862 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3863 static int | |
3864 #ifdef __BORLANDC__ | |
3865 _RTLENTRYF | |
3866 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3867 sort_func_compare(const void *s1, const void *s2) |
3164 | 3868 { |
3869 char_u *p1 = *(char_u **)s1; | |
3870 char_u *p2 = *(char_u **)s2; | |
3871 | |
3872 if (*p1 != '<' && *p2 == '<') return -1; | |
3873 if (*p1 == '<' && *p2 != '<') return 1; | |
3874 return STRCMP(p1, p2); | |
3875 } | |
3876 #endif | |
3877 | |
7 | 3878 /* |
3879 * Return FAIL if this is not an appropriate context in which to do | |
3880 * completion of anything, return OK if it is (even if there are no matches). | |
3881 * For the caller, this means that the character is just passed through like a | |
3882 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3883 */ | |
3884 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3885 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3886 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3887 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3888 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3889 int escape) /* if TRUE, escape the returned matches */ |
7 | 3890 { |
3891 int i, j; | |
3892 char_u *p1; | |
3893 char_u *p2; | |
3894 int difflen; | |
3895 int v; | |
3896 | |
3897 if (xp->xp_numfiles == -1) | |
3898 { | |
3899 set_expand_context(xp); | |
3900 cmd_showtail = expand_showtail(xp); | |
3901 } | |
3902 | |
3903 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3904 { | |
3905 beep_flush(); | |
3906 return OK; /* Something illegal on command line */ | |
3907 } | |
3908 if (xp->xp_context == EXPAND_NOTHING) | |
3909 { | |
3910 /* Caller can use the character as a normal char instead */ | |
3911 return FAIL; | |
3912 } | |
3913 | |
3914 MSG_PUTS("..."); /* show that we are busy */ | |
3915 out_flush(); | |
3916 | |
3917 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3918 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3919 |
3920 if (type == WILD_NEXT || type == WILD_PREV) | |
3921 { | |
3922 /* | |
3923 * Get next/previous match for a previous expanded pattern. | |
3924 */ | |
3925 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3926 } | |
3927 else | |
3928 { | |
3929 /* | |
3930 * Translate string into pattern and expand it. | |
3931 */ | |
1965 | 3932 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3933 xp->xp_context)) == NULL) | |
7 | 3934 p2 = NULL; |
3935 else | |
3936 { | |
2652 | 3937 int use_options = options | |
3961 | 3938 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3939 if (escape) | |
3940 use_options |= WILD_ESCAPE; | |
2652 | 3941 |
3942 if (p_wic) | |
3943 use_options += WILD_ICASE; | |
1965 | 3944 p2 = ExpandOne(xp, p1, |
3945 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3946 use_options, type); |
7 | 3947 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3948 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3949 if (p2 != NULL && type == WILD_LONGEST) |
3950 { | |
1965 | 3951 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3952 if (ccline.cmdbuff[i + j] == '*' |
3953 || ccline.cmdbuff[i + j] == '?') | |
3954 break; | |
3955 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
|
3956 VIM_CLEAR(p2); |
7 | 3957 } |
3958 } | |
3959 } | |
3960 | |
3961 if (p2 != NULL && !got_int) | |
3962 { | |
1965 | 3963 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
|
3964 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3965 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3966 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3967 xp->xp_pattern = ccline.cmdbuff + i; |
3968 } | |
3969 else | |
3970 v = OK; | |
3971 if (v == OK) | |
3972 { | |
323 | 3973 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3974 &ccline.cmdbuff[ccline.cmdpos], | |
3975 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3976 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3977 ccline.cmdlen += difflen; |
3978 ccline.cmdpos += difflen; | |
3979 } | |
3980 } | |
3981 vim_free(p2); | |
3982 | |
3983 redrawcmd(); | |
33 | 3984 cursorcmd(); |
7 | 3985 |
3986 /* When expanding a ":map" command and no matches are found, assume that | |
3987 * the key is supposed to be inserted literally */ | |
3988 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3989 return FAIL; | |
3990 | |
3991 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3992 beep_flush(); | |
3993 else if (xp->xp_numfiles == 1) | |
3994 /* free expanded pattern */ | |
3995 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3996 | |
3997 return OK; | |
3998 } | |
3999 | |
4000 /* | |
4001 * Do wildcard expansion on the string 'str'. | |
4002 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4003 * Return a pointer to allocated memory containing the new string. |
7 | 4004 * Return NULL for failure. |
4005 * | |
1412 | 4006 * "orig" is the originally expanded string, copied to allocated memory. It |
4007 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4008 * WILD_PREV "orig" should be NULL. | |
4009 * | |
838 | 4010 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4011 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4012 * |
4013 * mode = WILD_FREE: just free previously expanded matches | |
4014 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4015 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4016 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4017 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4018 * mode = WILD_ALL: return all matches concatenated | |
4019 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4020 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4021 * |
4022 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4023 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4024 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4025 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4026 * options = WILD_ADD_SLASH: add a slash after directory names | |
4027 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4028 * options = WILD_SILENT: don't print warning messages | |
4029 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4030 * options = WILD_ICASE: ignore case for files |
7 | 4031 * |
4032 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4033 */ | |
4034 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4035 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4036 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4037 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4038 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
|
4039 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4040 int mode) |
7 | 4041 { |
4042 char_u *ss = NULL; | |
4043 static int findex; | |
4044 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4045 int orig_saved = FALSE; |
7 | 4046 int i; |
4047 long_u len; | |
4048 int non_suf_match; /* number without matching suffix */ | |
4049 | |
4050 /* | |
4051 * first handle the case of using an old match | |
4052 */ | |
4053 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4054 { | |
4055 if (xp->xp_numfiles > 0) | |
4056 { | |
4057 if (mode == WILD_PREV) | |
4058 { | |
4059 if (findex == -1) | |
4060 findex = xp->xp_numfiles; | |
4061 --findex; | |
4062 } | |
4063 else /* mode == WILD_NEXT */ | |
4064 ++findex; | |
4065 | |
4066 /* | |
4067 * When wrapping around, return the original string, set findex to | |
4068 * -1. | |
4069 */ | |
4070 if (findex < 0) | |
4071 { | |
4072 if (orig_save == NULL) | |
4073 findex = xp->xp_numfiles - 1; | |
4074 else | |
4075 findex = -1; | |
4076 } | |
4077 if (findex >= xp->xp_numfiles) | |
4078 { | |
4079 if (orig_save == NULL) | |
4080 findex = 0; | |
4081 else | |
4082 findex = -1; | |
4083 } | |
4084 #ifdef FEAT_WILDMENU | |
4085 if (p_wmnu) | |
4086 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4087 findex, cmd_showtail); | |
4088 #endif | |
4089 if (findex == -1) | |
4090 return vim_strsave(orig_save); | |
4091 return vim_strsave(xp->xp_files[findex]); | |
4092 } | |
4093 else | |
4094 return NULL; | |
4095 } | |
4096 | |
1412 | 4097 /* free old names */ |
7 | 4098 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4099 { | |
4100 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4101 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
|
4102 VIM_CLEAR(orig_save); |
7 | 4103 } |
4104 findex = 0; | |
4105 | |
4106 if (mode == WILD_FREE) /* only release file name */ | |
4107 return NULL; | |
4108 | |
4109 if (xp->xp_numfiles == -1) | |
4110 { | |
4111 vim_free(orig_save); | |
4112 orig_save = orig; | |
1432 | 4113 orig_saved = TRUE; |
7 | 4114 |
4115 /* | |
4116 * Do the expansion. | |
4117 */ | |
4118 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4119 options) == FAIL) | |
4120 { | |
4121 #ifdef FNAME_ILLEGAL | |
4122 /* Illegal file name has been silently skipped. But when there | |
4123 * are wildcards, the real problem is that there was no match, | |
4124 * causing the pattern to be added, which has illegal characters. | |
4125 */ | |
4126 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4127 EMSG2(_(e_nomatch2), str); | |
4128 #endif | |
4129 } | |
4130 else if (xp->xp_numfiles == 0) | |
4131 { | |
4132 if (!(options & WILD_SILENT)) | |
4133 EMSG2(_(e_nomatch2), str); | |
4134 } | |
4135 else | |
4136 { | |
4137 /* Escape the matches for use on the command line. */ | |
4138 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4139 | |
4140 /* | |
4141 * Check for matching suffixes in file names. | |
4142 */ | |
3398 | 4143 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4144 && mode != WILD_LONGEST) | |
7 | 4145 { |
4146 if (xp->xp_numfiles) | |
4147 non_suf_match = xp->xp_numfiles; | |
4148 else | |
4149 non_suf_match = 1; | |
4150 if ((xp->xp_context == EXPAND_FILES | |
4151 || xp->xp_context == EXPAND_DIRECTORIES) | |
4152 && xp->xp_numfiles > 1) | |
4153 { | |
4154 /* | |
4155 * More than one match; check suffix. | |
4156 * The files will have been sorted on matching suffix in | |
4157 * expand_wildcards, only need to check the first two. | |
4158 */ | |
4159 non_suf_match = 0; | |
4160 for (i = 0; i < 2; ++i) | |
4161 if (match_suffix(xp->xp_files[i])) | |
4162 ++non_suf_match; | |
4163 } | |
4164 if (non_suf_match != 1) | |
4165 { | |
4166 /* Can we ever get here unless it's while expanding | |
4167 * interactively? If not, we can get rid of this all | |
4168 * together. Don't really want to wait for this message | |
4169 * (and possibly have to hit return to continue!). | |
4170 */ | |
4171 if (!(options & WILD_SILENT)) | |
4172 EMSG(_(e_toomany)); | |
4173 else if (!(options & WILD_NO_BEEP)) | |
4174 beep_flush(); | |
4175 } | |
4176 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4177 ss = vim_strsave(xp->xp_files[0]); | |
4178 } | |
4179 } | |
4180 } | |
4181 | |
4182 /* Find longest common part */ | |
4183 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4184 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4185 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4186 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4187 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4188 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4189 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4190 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4191 if (has_mbyte) |
7 | 4192 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4193 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
|
4194 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
|
4195 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4196 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4197 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4198 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
|
4199 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
|
4200 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4201 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4202 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4203 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
|
4204 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4205 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4206 ci = xp->xp_files[i][len]; |
4242 | 4207 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4208 || xp->xp_context == EXPAND_FILES |
714 | 4209 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4210 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4211 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4212 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4213 break; |
4214 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4215 else if (c0 != ci) |
7 | 4216 break; |
4217 } | |
4218 if (i < xp->xp_numfiles) | |
4219 { | |
4220 if (!(options & WILD_NO_BEEP)) | |
6949 | 4221 vim_beep(BO_WILD); |
7 | 4222 break; |
4223 } | |
4224 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4225 |
7 | 4226 ss = alloc((unsigned)len + 1); |
4227 if (ss) | |
419 | 4228 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4229 findex = -1; /* next p_wc gets first one */ |
4230 } | |
4231 | |
4232 /* Concatenate all matching names */ | |
4233 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4234 { | |
4235 len = 0; | |
4236 for (i = 0; i < xp->xp_numfiles; ++i) | |
4237 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4238 ss = lalloc(len, TRUE); | |
4239 if (ss != NULL) | |
4240 { | |
4241 *ss = NUL; | |
4242 for (i = 0; i < xp->xp_numfiles; ++i) | |
4243 { | |
4244 STRCAT(ss, xp->xp_files[i]); | |
4245 if (i != xp->xp_numfiles - 1) | |
4246 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4247 } | |
4248 } | |
4249 } | |
4250 | |
4251 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4252 ExpandCleanup(xp); | |
4253 | |
1412 | 4254 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4255 if (!orig_saved) |
1412 | 4256 vim_free(orig); |
4257 | |
7 | 4258 return ss; |
4259 } | |
4260 | |
4261 /* | |
4262 * Prepare an expand structure for use. | |
4263 */ | |
4264 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4265 ExpandInit(expand_T *xp) |
7 | 4266 { |
1718 | 4267 xp->xp_pattern = NULL; |
1965 | 4268 xp->xp_pattern_len = 0; |
7 | 4269 xp->xp_backslash = XP_BS_NONE; |
632 | 4270 #ifndef BACKSLASH_IN_FILENAME |
4271 xp->xp_shell = FALSE; | |
4272 #endif | |
7 | 4273 xp->xp_numfiles = -1; |
4274 xp->xp_files = NULL; | |
632 | 4275 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4276 xp->xp_arg = NULL; | |
4277 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4278 xp->xp_line = NULL; |
7 | 4279 } |
4280 | |
4281 /* | |
4282 * Cleanup an expand structure after use. | |
4283 */ | |
4284 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4285 ExpandCleanup(expand_T *xp) |
7 | 4286 { |
4287 if (xp->xp_numfiles >= 0) | |
4288 { | |
4289 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4290 xp->xp_numfiles = -1; | |
4291 } | |
4292 } | |
4293 | |
4294 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4295 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4296 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4297 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4298 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4299 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4300 int options) |
7 | 4301 { |
4302 int i; | |
4303 char_u *p; | |
4304 | |
4305 /* | |
4306 * May change home directory back to "~" | |
4307 */ | |
4308 if (options & WILD_HOME_REPLACE) | |
4309 tilde_replace(str, numfiles, files); | |
4310 | |
4311 if (options & WILD_ESCAPE) | |
4312 { | |
4313 if (xp->xp_context == EXPAND_FILES | |
2778 | 4314 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4315 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4316 || xp->xp_context == EXPAND_BUFFERS |
4317 || xp->xp_context == EXPAND_DIRECTORIES) | |
4318 { | |
4319 /* | |
4320 * Insert a backslash into a file name before a space, \, %, # | |
4321 * and wildmatch characters, except '~'. | |
4322 */ | |
4323 for (i = 0; i < numfiles; ++i) | |
4324 { | |
4325 /* for ":set path=" we need to escape spaces twice */ | |
4326 if (xp->xp_backslash == XP_BS_THREE) | |
4327 { | |
4328 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4329 if (p != NULL) | |
4330 { | |
4331 vim_free(files[i]); | |
4332 files[i] = p; | |
719 | 4333 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4334 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4335 if (p != NULL) | |
4336 { | |
4337 vim_free(files[i]); | |
4338 files[i] = p; | |
4339 } | |
4340 #endif | |
4341 } | |
4342 } | |
1589 | 4343 #ifdef BACKSLASH_IN_FILENAME |
4344 p = vim_strsave_fnameescape(files[i], FALSE); | |
4345 #else | |
1586 | 4346 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4347 #endif |
7 | 4348 if (p != NULL) |
4349 { | |
4350 vim_free(files[i]); | |
4351 files[i] = p; | |
4352 } | |
4353 | |
4354 /* If 'str' starts with "\~", replace "~" at start of | |
4355 * files[i] with "\~". */ | |
4356 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4357 escape_fname(&files[i]); |
7 | 4358 } |
4359 xp->xp_backslash = XP_BS_NONE; | |
435 | 4360 |
4361 /* If the first file starts with a '+' escape it. Otherwise it | |
4362 * could be seen as "+cmd". */ | |
4363 if (*files[0] == '+') | |
4364 escape_fname(&files[0]); | |
7 | 4365 } |
4366 else if (xp->xp_context == EXPAND_TAGS) | |
4367 { | |
4368 /* | |
4369 * Insert a backslash before characters in a tag name that | |
4370 * would terminate the ":tag" command. | |
4371 */ | |
4372 for (i = 0; i < numfiles; ++i) | |
4373 { | |
4374 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4375 if (p != NULL) | |
4376 { | |
4377 vim_free(files[i]); | |
4378 files[i] = p; | |
4379 } | |
4380 } | |
4381 } | |
4382 } | |
4383 } | |
4384 | |
4385 /* | |
1586 | 4386 * Escape special characters in "fname" for when used as a file name argument |
4387 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4388 * Returns the result in allocated memory. | |
4389 */ | |
4390 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4391 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4392 { |
1685 | 4393 char_u *p; |
1586 | 4394 #ifdef BACKSLASH_IN_FILENAME |
4395 char_u buf[20]; | |
4396 int j = 0; | |
4397 | |
5481 | 4398 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4399 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4400 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4401 buf[j++] = *p; |
4402 buf[j] = NUL; | |
1700 | 4403 p = vim_strsave_escaped(fname, buf); |
1586 | 4404 #else |
1685 | 4405 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4406 if (shell && csh_like_shell() && p != NULL) | |
4407 { | |
4408 char_u *s; | |
4409 | |
4410 /* For csh and similar shells need to put two backslashes before '!'. | |
4411 * One is taken by Vim, one by the shell. */ | |
4412 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4413 vim_free(p); | |
4414 p = s; | |
4415 } | |
1700 | 4416 #endif |
4417 | |
4418 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4419 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4420 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4421 escape_fname(&p); |
4422 | |
1685 | 4423 return p; |
1586 | 4424 } |
4425 | |
4426 /* | |
435 | 4427 * Put a backslash before the file name in "pp", which is in allocated memory. |
4428 */ | |
4429 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4430 escape_fname(char_u **pp) |
435 | 4431 { |
4432 char_u *p; | |
4433 | |
4434 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4435 if (p != NULL) | |
4436 { | |
4437 p[0] = '\\'; | |
4438 STRCPY(p + 1, *pp); | |
4439 vim_free(*pp); | |
4440 *pp = p; | |
4441 } | |
4442 } | |
4443 | |
4444 /* | |
7 | 4445 * For each file name in files[num_files]: |
4446 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4447 */ | |
4448 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4449 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4450 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4451 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4452 char_u **files) |
7 | 4453 { |
4454 int i; | |
4455 char_u *p; | |
4456 | |
4457 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4458 { | |
4459 for (i = 0; i < num_files; ++i) | |
4460 { | |
4461 p = home_replace_save(NULL, files[i]); | |
4462 if (p != NULL) | |
4463 { | |
4464 vim_free(files[i]); | |
4465 files[i] = p; | |
4466 } | |
4467 } | |
4468 } | |
4469 } | |
4470 | |
4471 /* | |
4472 * Show all matches for completion on the command line. | |
4473 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4474 * be inserted like a normal character. | |
4475 */ | |
4476 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4477 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4478 { |
4479 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4480 int num_files; | |
4481 char_u **files_found; | |
4482 int i, j, k; | |
4483 int maxlen; | |
4484 int lines; | |
4485 int columns; | |
4486 char_u *p; | |
4487 int lastlen; | |
4488 int attr; | |
4489 int showtail; | |
4490 | |
4491 if (xp->xp_numfiles == -1) | |
4492 { | |
4493 set_expand_context(xp); | |
4494 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4495 &num_files, &files_found); | |
4496 showtail = expand_showtail(xp); | |
4497 if (i != EXPAND_OK) | |
4498 return i; | |
4499 | |
4500 } | |
4501 else | |
4502 { | |
4503 num_files = xp->xp_numfiles; | |
4504 files_found = xp->xp_files; | |
4505 showtail = cmd_showtail; | |
4506 } | |
4507 | |
4508 #ifdef FEAT_WILDMENU | |
4509 if (!wildmenu) | |
4510 { | |
4511 #endif | |
4512 msg_didany = FALSE; /* lines_left will be set */ | |
4513 msg_start(); /* prepare for paging */ | |
4514 msg_putchar('\n'); | |
4515 out_flush(); | |
4516 cmdline_row = msg_row; | |
4517 msg_didany = FALSE; /* lines_left will be set again */ | |
4518 msg_start(); /* prepare for paging */ | |
4519 #ifdef FEAT_WILDMENU | |
4520 } | |
4521 #endif | |
4522 | |
4523 if (got_int) | |
4524 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4525 #ifdef FEAT_WILDMENU | |
4526 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
|
4527 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4528 #endif |
4529 else | |
4530 { | |
4531 /* find the length of the longest file name */ | |
4532 maxlen = 0; | |
4533 for (i = 0; i < num_files; ++i) | |
4534 { | |
4535 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4536 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4537 || xp->xp_context == EXPAND_BUFFERS)) |
4538 { | |
4539 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4540 j = vim_strsize(NameBuff); | |
4541 } | |
4542 else | |
4543 j = vim_strsize(L_SHOWFILE(i)); | |
4544 if (j > maxlen) | |
4545 maxlen = j; | |
4546 } | |
4547 | |
4548 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4549 lines = num_files; | |
4550 else | |
4551 { | |
4552 /* compute the number of columns and lines for the listing */ | |
4553 maxlen += 2; /* two spaces between file names */ | |
4554 columns = ((int)Columns + 2) / maxlen; | |
4555 if (columns < 1) | |
4556 columns = 1; | |
4557 lines = (num_files + columns - 1) / columns; | |
4558 } | |
4559 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4560 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4561 |
4562 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4563 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4564 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4565 msg_clr_eos(); |
4566 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
|
4567 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4568 } |
4569 | |
4570 /* list the files line by line */ | |
4571 for (i = 0; i < lines; ++i) | |
4572 { | |
4573 lastlen = 999; | |
4574 for (k = i; k < num_files; k += lines) | |
4575 { | |
4576 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4577 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4578 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4579 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4580 msg_advance(maxlen + 1); | |
4581 msg_puts(p); | |
4582 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
|
4583 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4584 break; |
4585 } | |
4586 for (j = maxlen - lastlen; --j >= 0; ) | |
4587 msg_putchar(' '); | |
4588 if (xp->xp_context == EXPAND_FILES | |
714 | 4589 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4590 || xp->xp_context == EXPAND_BUFFERS) |
4591 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4592 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4593 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4594 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4595 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4596 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4597 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4598 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4599 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4600 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4601 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
|
4602 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4603 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4604 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4605 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4606 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4607 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4608 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4609 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4610 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4611 j = mch_isdir(files_found[k]); |
7 | 4612 if (showtail) |
4613 p = L_SHOWFILE(k); | |
4614 else | |
4615 { | |
4616 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4617 TRUE); | |
4618 p = NameBuff; | |
4619 } | |
4620 } | |
4621 else | |
4622 { | |
4623 j = FALSE; | |
4624 p = L_SHOWFILE(k); | |
4625 } | |
4626 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4627 } | |
4628 if (msg_col > 0) /* when not wrapped around */ | |
4629 { | |
4630 msg_clr_eos(); | |
4631 msg_putchar('\n'); | |
4632 } | |
4633 out_flush(); /* show one line at a time */ | |
4634 if (got_int) | |
4635 { | |
4636 got_int = FALSE; | |
4637 break; | |
4638 } | |
4639 } | |
4640 | |
4641 /* | |
4642 * we redraw the command below the lines that we have just listed | |
4643 * This is a bit tricky, but it saves a lot of screen updating. | |
4644 */ | |
4645 cmdline_row = msg_row; /* will put it back later */ | |
4646 } | |
4647 | |
4648 if (xp->xp_numfiles == -1) | |
4649 FreeWild(num_files, files_found); | |
4650 | |
4651 return EXPAND_OK; | |
4652 } | |
4653 | |
4654 /* | |
4655 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4656 * Find tail of file name path, but ignore trailing "/". | |
4657 */ | |
4658 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4659 sm_gettail(char_u *s) |
7 | 4660 { |
4661 char_u *p; | |
4662 char_u *t = s; | |
4663 int had_sep = FALSE; | |
4664 | |
4665 for (p = s; *p != NUL; ) | |
4666 { | |
4667 if (vim_ispathsep(*p) | |
4668 #ifdef BACKSLASH_IN_FILENAME | |
4669 && !rem_backslash(p) | |
4670 #endif | |
4671 ) | |
4672 had_sep = TRUE; | |
4673 else if (had_sep) | |
4674 { | |
4675 t = p; | |
4676 had_sep = FALSE; | |
4677 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4678 MB_PTR_ADV(p); |
7 | 4679 } |
4680 return t; | |
4681 } | |
4682 | |
4683 /* | |
4684 * Return TRUE if we only need to show the tail of completion matches. | |
4685 * When not completing file names or there is a wildcard in the path FALSE is | |
4686 * returned. | |
4687 */ | |
4688 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4689 expand_showtail(expand_T *xp) |
7 | 4690 { |
4691 char_u *s; | |
4692 char_u *end; | |
4693 | |
4694 /* When not completing file names a "/" may mean something different. */ | |
714 | 4695 if (xp->xp_context != EXPAND_FILES |
4696 && xp->xp_context != EXPAND_SHELLCMD | |
4697 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4698 return FALSE; |
4699 | |
4700 end = gettail(xp->xp_pattern); | |
4701 if (end == xp->xp_pattern) /* there is no path separator */ | |
4702 return FALSE; | |
4703 | |
4704 for (s = xp->xp_pattern; s < end; s++) | |
4705 { | |
4706 /* Skip escaped wildcards. Only when the backslash is not a path | |
4707 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4708 if (rem_backslash(s)) | |
4709 ++s; | |
4710 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4711 return FALSE; | |
4712 } | |
4713 return TRUE; | |
4714 } | |
4715 | |
4716 /* | |
4717 * Prepare a string for expansion. | |
4718 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4719 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4720 * When expanding other names: The string will be used with regcomp(). Copy |
4721 * the name into allocated memory and prepend "^". | |
4722 */ | |
4723 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4724 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4725 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4726 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4727 int context) /* EXPAND_FILES etc. */ |
7 | 4728 { |
4729 char_u *retval; | |
4730 int i, j; | |
4731 int new_len; | |
4732 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4733 int ends_in_star; |
7 | 4734 |
714 | 4735 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4736 && context != EXPAND_FILES_IN_PATH |
714 | 4737 && context != EXPAND_SHELLCMD |
4738 && context != EXPAND_DIRECTORIES) | |
7 | 4739 { |
4740 /* | |
4741 * Matching will be done internally (on something other than files). | |
4742 * So we convert the file-matching-type wildcards into our kind for | |
4743 * use with vim_regcomp(). First work out how long it will be: | |
4744 */ | |
4745 | |
4746 /* For help tags the translation is done in find_help_tags(). | |
4747 * For a tag pattern starting with "/" no translation is needed. */ | |
4748 if (context == EXPAND_HELP | |
4749 || context == EXPAND_COLORS | |
4750 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4751 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4752 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4753 || 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
|
4754 || ((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
|
4755 || 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
|
4756 && fname[0] == '/')) |
7 | 4757 retval = vim_strnsave(fname, len); |
4758 else | |
4759 { | |
4760 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4761 for (i = 0; i < len; i++) | |
4762 { | |
4763 if (fname[i] == '*' || fname[i] == '~') | |
4764 new_len++; /* '*' needs to be replaced by ".*" | |
4765 '~' needs to be replaced by "\~" */ | |
4766 | |
4767 /* Buffer names are like file names. "." should be literal */ | |
4768 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4769 new_len++; /* "." becomes "\." */ | |
4770 | |
4771 /* Custom expansion takes care of special things, match | |
4772 * backslashes literally (perhaps also for other types?) */ | |
634 | 4773 if ((context == EXPAND_USER_DEFINED |
4774 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4775 new_len++; /* '\' becomes "\\" */ |
4776 } | |
4777 retval = alloc(new_len); | |
4778 if (retval != NULL) | |
4779 { | |
4780 retval[0] = '^'; | |
4781 j = 1; | |
4782 for (i = 0; i < len; i++, j++) | |
4783 { | |
4784 /* Skip backslash. But why? At least keep it for custom | |
4785 * expansion. */ | |
4786 if (context != EXPAND_USER_DEFINED | |
407 | 4787 && context != EXPAND_USER_LIST |
4788 && fname[i] == '\\' | |
4789 && ++i == len) | |
7 | 4790 break; |
4791 | |
4792 switch (fname[i]) | |
4793 { | |
4794 case '*': retval[j++] = '.'; | |
4795 break; | |
4796 case '~': retval[j++] = '\\'; | |
4797 break; | |
4798 case '?': retval[j] = '.'; | |
4799 continue; | |
4800 case '.': if (context == EXPAND_BUFFERS) | |
4801 retval[j++] = '\\'; | |
4802 break; | |
407 | 4803 case '\\': if (context == EXPAND_USER_DEFINED |
4804 || context == EXPAND_USER_LIST) | |
7 | 4805 retval[j++] = '\\'; |
4806 break; | |
4807 } | |
4808 retval[j] = fname[i]; | |
4809 } | |
4810 retval[j] = NUL; | |
4811 } | |
4812 } | |
4813 } | |
4814 else | |
4815 { | |
4816 retval = alloc(len + 4); | |
4817 if (retval != NULL) | |
4818 { | |
419 | 4819 vim_strncpy(retval, fname, len); |
7 | 4820 |
4821 /* | |
831 | 4822 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4823 * * would become **, which walks the whole tree. | |
7 | 4824 * ~ would be at the start of the file name, but not the tail. |
4825 * $ could be anywhere in the tail. | |
4826 * ` could be anywhere in the file name. | |
1484 | 4827 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4828 */ |
4829 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4830 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
|
4831 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4832 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4833 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4834 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4835 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4836 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4837 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4838 #endif |
7 | 4839 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4840 && !ends_in_star |
7 | 4841 && vim_strchr(tail, '$') == NULL |
4842 && vim_strchr(retval, '`') == NULL) | |
4843 retval[len++] = '*'; | |
1484 | 4844 else if (len > 0 && retval[len - 1] == '$') |
4845 --len; | |
7 | 4846 retval[len] = NUL; |
4847 } | |
4848 } | |
4849 return retval; | |
4850 } | |
4851 | |
4852 /* | |
4853 * Must parse the command line so far to work out what context we are in. | |
4854 * Completion can then be done based on that context. | |
4855 * This routine sets the variables: | |
4856 * xp->xp_pattern The start of the pattern to be expanded within | |
4857 * the command line (ends at the cursor). | |
4858 * xp->xp_context The type of thing to expand. Will be one of: | |
4859 * | |
4860 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4861 * the command line, like an unknown command. Caller | |
4862 * should beep. | |
4863 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4864 * a normal char, rather than for completion. eg | |
4865 * :s/^I/ | |
4866 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4867 * it. | |
4868 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4869 * EXPAND_FILES After command with XFILE set, or after setting | |
4870 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4871 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4872 * when we know only directories are of interest. eg | |
4873 * :set dir=^I | |
714 | 4874 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4875 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4876 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4877 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4878 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4879 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4880 * EXPAND_EVENTS Complete event names | |
4881 * EXPAND_SYNTAX Complete :syntax command arguments | |
4882 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4883 * EXPAND_AUGROUP Complete autocommand group names | |
4884 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4885 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4886 * eg :unmap a^I , :cunab x^I | |
4887 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4888 * eg :call sub^I | |
4889 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4890 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4891 * names in expressions, eg :while s^I | |
4892 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4893 * EXPAND_USER Complete user names |
7 | 4894 */ |
4895 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4896 set_expand_context(expand_T *xp) |
7 | 4897 { |
168 | 4898 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4899 if (ccline.cmdfirstc != ':' |
4900 #ifdef FEAT_EVAL | |
168 | 4901 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4902 && !ccline.input_fn |
7 | 4903 #endif |
4904 ) | |
4905 { | |
4906 xp->xp_context = EXPAND_NOTHING; | |
4907 return; | |
4908 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4909 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4910 } |
4911 | |
4912 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4913 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4914 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4915 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
|
4916 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
|
4917 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4918 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4919 { |
4920 int old_char = NUL; | |
4921 char_u *nextcomm; | |
4922 | |
4923 /* | |
4924 * Avoid a UMR warning from Purify, only save the character if it has been | |
4925 * written before. | |
4926 */ | |
4927 if (col < len) | |
4928 old_char = str[col]; | |
4929 str[col] = NUL; | |
4930 nextcomm = str; | |
168 | 4931 |
4932 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4933 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4934 { |
4935 # ifdef FEAT_CMDL_COMPL | |
168 | 4936 /* pass CMD_SIZE because there is no real command */ |
4937 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4938 # endif |
4939 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4940 else if (use_ccline && ccline.input_fn) |
531 | 4941 { |
4942 xp->xp_context = ccline.xp_context; | |
4943 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4944 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4945 xp->xp_arg = ccline.xp_arg; |
1322 | 4946 # endif |
531 | 4947 } |
168 | 4948 else |
4949 #endif | |
4950 while (nextcomm != NULL) | |
4951 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4952 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4953 /* 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
|
4954 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4955 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4956 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4957 |
7 | 4958 str[col] = old_char; |
4959 } | |
4960 | |
4961 /* | |
4962 * Expand the command line "str" from context "xp". | |
4963 * "xp" must have been set by set_cmd_context(). | |
4964 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4965 * starts. | |
4966 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4967 * cursor. | |
4968 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4969 * key that triggered expansion literally. | |
4970 * Returns EXPAND_OK otherwise. | |
4971 */ | |
4972 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4973 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4974 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4975 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
|
4976 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4977 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4978 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4979 { |
4980 char_u *file_str = NULL; | |
2652 | 4981 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4982 |
4983 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4984 { | |
4985 beep_flush(); | |
4986 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4987 } | |
4988 if (xp->xp_context == EXPAND_NOTHING) | |
4989 { | |
4990 /* Caller can use the character as a normal char instead */ | |
4991 return EXPAND_NOTHING; | |
4992 } | |
4993 | |
4994 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4995 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4996 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4997 if (file_str == NULL) |
4998 return EXPAND_UNSUCCESSFUL; | |
4999 | |
2652 | 5000 if (p_wic) |
5001 options += WILD_ICASE; | |
5002 | |
7 | 5003 /* find all files that match the description */ |
2652 | 5004 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5005 { |
5006 *matchcount = 0; | |
5007 *matches = NULL; | |
5008 } | |
5009 vim_free(file_str); | |
5010 | |
5011 return EXPAND_OK; | |
5012 } | |
5013 | |
5014 #ifdef FEAT_MULTI_LANG | |
5015 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5016 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5017 * 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
|
5018 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5019 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5020 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5021 |
5022 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5023 cleanup_help_tags(int num_file, char_u **file) |
7 | 5024 { |
5025 int i, j; | |
5026 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5027 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5028 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5029 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5030 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
|
5031 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5032 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5033 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5034 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5035 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5036 *p = NUL; |
7 | 5037 |
5038 for (i = 0; i < num_file; ++i) | |
5039 { | |
5040 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
|
5041 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5042 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5043 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5044 { |
5045 /* Sorting on priority means the same item in another language may | |
5046 * be anywhere. Search all items for a match up to the "@en". */ | |
5047 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
|
5048 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
|
5049 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5050 break; |
5051 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5052 /* item only exists with @en, remove it */ |
7 | 5053 file[i][len] = NUL; |
5054 } | |
5055 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5056 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5057 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5058 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
|
5059 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5060 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5061 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5062 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5063 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
|
5064 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5065 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5066 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5067 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5068 } |
7 | 5069 } |
5070 #endif | |
5071 | |
5072 /* | |
5073 * Do the expansion based on xp->xp_context and "pat". | |
5074 */ | |
5075 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5076 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5077 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5078 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5079 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5080 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5081 int options) /* EW_ flags */ |
7 | 5082 { |
5083 #ifdef FEAT_CMDL_COMPL | |
5084 regmatch_T regmatch; | |
5085 #endif | |
5086 int ret; | |
5087 int flags; | |
5088 | |
5089 flags = EW_DIR; /* include directories */ | |
5090 if (options & WILD_LIST_NOTFOUND) | |
5091 flags |= EW_NOTFOUND; | |
5092 if (options & WILD_ADD_SLASH) | |
5093 flags |= EW_ADDSLASH; | |
5094 if (options & WILD_KEEP_ALL) | |
5095 flags |= EW_KEEPALL; | |
5096 if (options & WILD_SILENT) | |
5097 flags |= EW_SILENT; | |
6659 | 5098 if (options & WILD_ALLLINKS) |
5099 flags |= EW_ALLLINKS; | |
7 | 5100 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5101 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5102 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5103 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5104 { |
5105 /* | |
5106 * Expand file or directory names. | |
5107 */ | |
5108 int free_pat = FALSE; | |
5109 int i; | |
5110 | |
5111 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5112 * space */ | |
5113 if (xp->xp_backslash != XP_BS_NONE) | |
5114 { | |
5115 free_pat = TRUE; | |
5116 pat = vim_strsave(pat); | |
5117 for (i = 0; pat[i]; ++i) | |
5118 if (pat[i] == '\\') | |
5119 { | |
5120 if (xp->xp_backslash == XP_BS_THREE | |
5121 && pat[i + 1] == '\\' | |
5122 && pat[i + 2] == '\\' | |
5123 && pat[i + 3] == ' ') | |
1621 | 5124 STRMOVE(pat + i, pat + i + 3); |
7 | 5125 if (xp->xp_backslash == XP_BS_ONE |
5126 && pat[i + 1] == ' ') | |
1621 | 5127 STRMOVE(pat + i, pat + i + 1); |
7 | 5128 } |
5129 } | |
5130 | |
5131 if (xp->xp_context == EXPAND_FILES) | |
5132 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5133 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
|
5134 flags |= (EW_FILE | EW_PATH); |
7 | 5135 else |
5136 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5137 if (options & WILD_ICASE) |
5138 flags |= EW_ICASE; | |
5139 | |
2016 | 5140 /* Expand wildcards, supporting %:h and the like. */ |
5141 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5142 if (free_pat) |
5143 vim_free(pat); | |
5144 return ret; | |
5145 } | |
5146 | |
5147 *file = (char_u **)""; | |
5148 *num_file = 0; | |
5149 if (xp->xp_context == EXPAND_HELP) | |
5150 { | |
1696 | 5151 /* With an empty argument we would get all the help tags, which is |
5152 * very slow. Get matches for "help" instead. */ | |
5153 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5154 num_file, file, FALSE) == OK) | |
7 | 5155 { |
5156 #ifdef FEAT_MULTI_LANG | |
5157 cleanup_help_tags(*num_file, *file); | |
5158 #endif | |
5159 return OK; | |
5160 } | |
5161 return FAIL; | |
5162 } | |
5163 | |
5164 #ifndef FEAT_CMDL_COMPL | |
5165 return FAIL; | |
5166 #else | |
716 | 5167 if (xp->xp_context == EXPAND_SHELLCMD) |
5168 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5169 if (xp->xp_context == EXPAND_OLD_SETTING) |
5170 return ExpandOldSetting(num_file, file); | |
5171 if (xp->xp_context == EXPAND_BUFFERS) | |
5172 return ExpandBufnames(pat, num_file, file, options); | |
5173 if (xp->xp_context == EXPAND_TAGS | |
5174 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5175 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5176 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5177 { |
5178 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5179 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
|
5180 directories); |
2929 | 5181 } |
7 | 5182 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5183 { |
3106 | 5184 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5185 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5186 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5187 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5188 { |
5189 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5190 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5191 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5192 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5193 { |
5194 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
|
5195 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5196 } |
407 | 5197 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5198 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5199 return ExpandUserList(xp, num_file, file); |
407 | 5200 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5201 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5202 return ExpandPackAddDir(pat, num_file, file); |
7 | 5203 |
5204 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5205 if (regmatch.regprog == NULL) | |
5206 return FAIL; | |
5207 | |
5208 /* set ignore-case according to p_ic, p_scs and pat */ | |
5209 regmatch.rm_ic = ignorecase(pat); | |
5210 | |
5211 if (xp->xp_context == EXPAND_SETTINGS | |
5212 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5213 ret = ExpandSettings(xp, ®match, num_file, file); | |
5214 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5215 ret = ExpandMappings(®match, num_file, file); | |
5216 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5217 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5218 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5219 # endif | |
5220 else | |
5221 { | |
5222 static struct expgen | |
5223 { | |
5224 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5225 char_u *((*func)(expand_T *, int)); |
7 | 5226 int ic; |
2849 | 5227 int escaped; |
7 | 5228 } tab[] = |
5229 { | |
2849 | 5230 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5231 {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
|
5232 {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
|
5233 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5234 #ifdef FEAT_CMDHIST |
5235 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5236 #endif | |
7 | 5237 #ifdef FEAT_USR_CMDS |
2849 | 5238 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5239 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5240 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5241 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5242 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5243 #endif |
5244 #ifdef FEAT_EVAL | |
2849 | 5245 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5246 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5247 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5248 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5249 #endif |
5250 #ifdef FEAT_MENU | |
2849 | 5251 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5252 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5253 #endif |
5254 #ifdef FEAT_SYN_HL | |
2849 | 5255 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5256 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5257 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5258 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5259 #endif |
2849 | 5260 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5261 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5262 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5263 #ifdef FEAT_CSCOPE |
2849 | 5264 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5265 #endif |
1868 | 5266 #ifdef FEAT_SIGNS |
2849 | 5267 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5268 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5269 #ifdef FEAT_PROFILE |
2849 | 5270 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5271 #endif |
7 | 5272 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5273 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5274 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5275 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5276 #endif | |
5277 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5278 {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
|
5279 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5280 }; |
5281 int i; | |
5282 | |
5283 /* | |
5284 * Find a context in the table and call the ExpandGeneric() with the | |
5285 * right function to do the expansion. | |
5286 */ | |
5287 ret = FAIL; | |
1880 | 5288 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5289 if (xp->xp_context == tab[i].context) |
5290 { | |
5291 if (tab[i].ic) | |
5292 regmatch.rm_ic = TRUE; | |
2849 | 5293 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5294 tab[i].func, tab[i].escaped); |
7 | 5295 break; |
5296 } | |
5297 } | |
5298 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5299 vim_regfree(regmatch.regprog); |
7 | 5300 |
5301 return ret; | |
5302 #endif /* FEAT_CMDL_COMPL */ | |
5303 } | |
5304 | |
5305 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5306 /* | |
5307 * Expand a list of names. | |
5308 * | |
5309 * Generic function for command line completion. It calls a function to | |
5310 * obtain strings, one by one. The strings are matched against a regexp | |
5311 * program. Matching strings are copied into an array, which is returned. | |
5312 * | |
5313 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5314 */ | |
5315 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5316 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5317 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5318 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5319 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5320 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5321 char_u *((*func)(expand_T *, int)), |
7 | 5322 /* 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
|
5323 int escaped) |
7 | 5324 { |
5325 int i; | |
5326 int count = 0; | |
480 | 5327 int round; |
7 | 5328 char_u *str; |
5329 | |
5330 /* do this loop twice: | |
480 | 5331 * round == 0: count the number of matching names |
5332 * round == 1: copy the matching names into allocated memory | |
7 | 5333 */ |
480 | 5334 for (round = 0; round <= 1; ++round) |
7 | 5335 { |
5336 for (i = 0; ; ++i) | |
5337 { | |
5338 str = (*func)(xp, i); | |
5339 if (str == NULL) /* end of list */ | |
5340 break; | |
5341 if (*str == NUL) /* skip empty strings */ | |
5342 continue; | |
5343 | |
5344 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5345 { | |
480 | 5346 if (round) |
7 | 5347 { |
2849 | 5348 if (escaped) |
5349 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5350 else | |
5351 str = vim_strsave(str); | |
7 | 5352 (*file)[count] = str; |
5353 #ifdef FEAT_MENU | |
5354 if (func == get_menu_names && str != NULL) | |
5355 { | |
5356 /* test for separator added by get_menu_names() */ | |
5357 str += STRLEN(str) - 1; | |
5358 if (*str == '\001') | |
5359 *str = '.'; | |
5360 } | |
5361 #endif | |
5362 } | |
5363 ++count; | |
5364 } | |
5365 } | |
480 | 5366 if (round == 0) |
7 | 5367 { |
5368 if (count == 0) | |
5369 return OK; | |
5370 *num_file = count; | |
5371 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5372 if (*file == NULL) | |
5373 { | |
5374 *file = (char_u **)""; | |
5375 return FAIL; | |
5376 } | |
5377 count = 0; | |
5378 } | |
5379 } | |
480 | 5380 |
828 | 5381 /* Sort the results. Keep menu's in the specified order. */ |
5382 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5383 { |
5384 if (xp->xp_context == EXPAND_EXPRESSION | |
5385 || xp->xp_context == EXPAND_FUNCTIONS | |
5386 || xp->xp_context == EXPAND_USER_FUNC) | |
5387 /* <SNR> functions should be sorted to the end. */ | |
5388 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5389 sort_func_compare); | |
5390 else | |
5391 sort_strings(*file, *num_file); | |
5392 } | |
480 | 5393 |
1322 | 5394 #ifdef FEAT_CMDL_COMPL |
5395 /* Reset the variables used for special highlight names expansion, so that | |
5396 * they don't show up when getting normal highlight names by ID. */ | |
5397 reset_expand_highlight(); | |
5398 #endif | |
5399 | |
7 | 5400 return OK; |
5401 } | |
5402 | |
716 | 5403 /* |
5404 * Complete a shell command. | |
5405 * Returns FAIL or OK; | |
5406 */ | |
5407 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5408 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5409 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
|
5410 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
|
5411 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
|
5412 int flagsarg) /* EW_ flags */ |
716 | 5413 { |
5414 char_u *pat; | |
5415 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5416 char_u *path = NULL; |
716 | 5417 int mustfree = FALSE; |
5418 garray_T ga; | |
5419 char_u *buf = alloc(MAXPATHL); | |
5420 size_t l; | |
5421 char_u *s, *e; | |
5422 int flags = flagsarg; | |
5423 int ret; | |
6695 | 5424 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5425 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5426 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5427 hash_T hash; |
716 | 5428 |
5429 if (buf == NULL) | |
5430 return FAIL; | |
5431 | |
5432 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5433 * space */ | |
5434 pat = vim_strsave(filepat); | |
5435 for (i = 0; pat[i]; ++i) | |
5436 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5437 STRMOVE(pat + i, pat + i + 1); |
716 | 5438 |
6695 | 5439 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5440 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5441 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
|
5442 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5443 path = (char_u *)"."; |
5444 else | |
2630 | 5445 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5446 /* 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
|
5447 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5448 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5449 if (path == NULL) |
5450 path = (char_u *)""; | |
5451 } | |
716 | 5452 |
5453 /* | |
5454 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5455 * collect them in "ga". When "." is not in $PATH also expand for the |
5456 * current directory, to find "subdir/cmd". | |
716 | 5457 */ |
5458 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
|
5459 hash_init(&found_ht); |
6695 | 5460 for (s = path; ; s = e) |
716 | 5461 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5462 #if defined(MSWIN) |
716 | 5463 e = vim_strchr(s, ';'); |
5464 #else | |
5465 e = vim_strchr(s, ':'); | |
5466 #endif | |
5467 if (e == NULL) | |
5468 e = s + STRLEN(s); | |
5469 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5470 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
|
5471 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5472 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
|
5473 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5474 // 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
|
5475 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
|
5476 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
|
5477 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5478 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
|
5479 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5480 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
|
5481 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
|
5482 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5483 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5484 // 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
|
5485 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
|
5486 |
716 | 5487 l = e - s; |
5488 if (l > MAXPATHL - 5) | |
5489 break; | |
5490 vim_strncpy(buf, s, l); | |
5491 add_pathsep(buf); | |
5492 l = STRLEN(buf); | |
5493 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5494 | |
5495 /* Expand matches in one directory of $PATH. */ | |
5496 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5497 if (ret == OK) | |
5498 { | |
5499 if (ga_grow(&ga, *num_file) == FAIL) | |
5500 FreeWild(*num_file, *file); | |
5501 else | |
5502 { | |
5503 for (i = 0; i < *num_file; ++i) | |
5504 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5505 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5506 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5507 if (STRLEN(name) > l) |
716 | 5508 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5509 // 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
|
5510 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5511 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
|
5512 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5513 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5514 // 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
|
5515 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5516 ((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
|
5517 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
|
5518 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5519 } |
716 | 5520 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5521 vim_free(name); |
716 | 5522 } |
5523 vim_free(*file); | |
5524 } | |
5525 } | |
5526 if (*e != NUL) | |
5527 ++e; | |
5528 } | |
5529 *file = ga.ga_data; | |
5530 *num_file = ga.ga_len; | |
5531 | |
5532 vim_free(buf); | |
5533 vim_free(pat); | |
5534 if (mustfree) | |
5535 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5536 hash_clear(&found_ht); |
716 | 5537 return OK; |
5538 } | |
5539 | |
5540 | |
7 | 5541 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5542 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5543 * 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
|
5544 * return the result (either a string or a List). |
7 | 5545 */ |
407 | 5546 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5547 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
|
5548 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
|
5549 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5550 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5551 char_u ***file) |
7 | 5552 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5553 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
|
5554 typval_T args[4]; |
7 | 5555 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5556 char_u *pat = NULL; |
407 | 5557 void *ret; |
13 | 5558 struct cmdline_info save_ccline; |
7 | 5559 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5560 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5561 return NULL; |
7 | 5562 *num_file = 0; |
5563 *file = NULL; | |
5564 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5565 if (ccline.cmdbuff != NULL) |
1518 | 5566 { |
5567 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5568 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5569 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5570 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5571 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
|
5572 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5573 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
|
5574 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
|
5575 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
|
5576 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
|
5577 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
|
5578 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
|
5579 args[3].v_type = VAR_UNKNOWN; |
7 | 5580 |
13 | 5581 /* Save the cmdline, we don't know what the function may do. */ |
5582 save_ccline = ccline; | |
5583 ccline.cmdbuff = NULL; | |
5584 ccline.cmdprompt = NULL; | |
7 | 5585 current_SID = xp->xp_scriptID; |
13 | 5586 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5587 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5588 |
5589 ccline = save_ccline; | |
7 | 5590 current_SID = save_current_SID; |
1518 | 5591 if (ccline.cmdbuff != NULL) |
5592 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5593 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5594 vim_free(pat); |
407 | 5595 return ret; |
5596 } | |
5597 | |
5598 /* | |
5599 * Expand names with a function defined by the user. | |
5600 */ | |
5601 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5602 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5603 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5604 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5605 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5606 char_u ***file) |
407 | 5607 { |
5608 char_u *retstr; | |
5609 char_u *s; | |
5610 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
|
5611 int keep; |
407 | 5612 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
|
5613 int skip; |
407 | 5614 |
5615 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5616 if (retstr == NULL) | |
7 | 5617 return FAIL; |
5618 | |
5619 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5620 for (s = retstr; *s != NUL; s = e) |
7 | 5621 { |
5622 e = vim_strchr(s, '\n'); | |
5623 if (e == NULL) | |
5624 e = s + STRLEN(s); | |
5625 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
|
5626 *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
|
5627 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5628 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
|
5629 *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
|
5630 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5631 if (!skip) |
7 | 5632 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5633 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
|
5634 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5635 ((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
|
5636 ++ga.ga_len; |
7 | 5637 } |
5638 | |
5639 if (*e != NUL) | |
5640 ++e; | |
5641 } | |
407 | 5642 vim_free(retstr); |
5643 *file = ga.ga_data; | |
5644 *num_file = ga.ga_len; | |
5645 return OK; | |
5646 } | |
5647 | |
5648 /* | |
5649 * Expand names with a list returned by a function defined by the user. | |
5650 */ | |
5651 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5652 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5653 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5654 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5655 char_u ***file) |
407 | 5656 { |
5657 list_T *retlist; | |
5658 listitem_T *li; | |
5659 garray_T ga; | |
5660 | |
5661 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5662 if (retlist == NULL) | |
5663 return FAIL; | |
5664 | |
5665 ga_init2(&ga, (int)sizeof(char *), 3); | |
5666 /* Loop over the items in the list. */ | |
5667 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5668 { | |
1917 | 5669 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5670 continue; /* Skip non-string items and empty strings */ | |
407 | 5671 |
5672 if (ga_grow(&ga, 1) == FAIL) | |
5673 break; | |
5674 | |
5675 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5676 vim_strsave(li->li_tv.vval.v_string); |
407 | 5677 ++ga.ga_len; |
5678 } | |
5679 list_unref(retlist); | |
5680 | |
7 | 5681 *file = ga.ga_data; |
5682 *num_file = ga.ga_len; | |
5683 return OK; | |
5684 } | |
5685 #endif | |
5686 | |
5687 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5688 * 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
|
5689 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5690 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5691 * 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
|
5692 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5693 * 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
|
5694 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5695 * "dirnames" is an array with one or more directory names. |
7 | 5696 */ |
5697 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5698 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5699 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5700 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5701 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5702 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5703 char *dirnames[]) |
7 | 5704 { |
5705 char_u *s; | |
5706 char_u *e; | |
5873 | 5707 char_u *match; |
7 | 5708 garray_T ga; |
2929 | 5709 int i; |
5710 int pat_len; | |
7 | 5711 |
5712 *num_file = 0; | |
5713 *file = NULL; | |
2931 | 5714 pat_len = (int)STRLEN(pat); |
2929 | 5715 ga_init2(&ga, (int)sizeof(char *), 10); |
5716 | |
5717 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5718 { |
2929 | 5719 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5720 if (s == NULL) | |
5721 { | |
5722 ga_clear_strings(&ga); | |
5723 return FAIL; | |
5724 } | |
5725 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5726 globpath(p_rtp, s, &ga, 0); |
2929 | 5727 vim_free(s); |
5873 | 5728 } |
5729 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5730 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5731 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
|
5732 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5733 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
|
5734 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5735 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5736 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5737 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5738 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5739 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
|
5740 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5741 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5742 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5743 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5744 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5745 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5746 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
|
5747 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5748 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
|
5749 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5750 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5751 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5752 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5753 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5754 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
|
5755 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5756 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5757 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5758 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5759 |
5873 | 5760 for (i = 0; i < ga.ga_len; ++i) |
5761 { | |
5762 match = ((char_u **)ga.ga_data)[i]; | |
5763 s = match; | |
5764 e = s + STRLEN(s); | |
5765 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5766 { |
5873 | 5767 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5768 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5769 if (s < match || vim_ispathsep(*s)) |
5770 break; | |
5771 ++s; | |
5772 *e = NUL; | |
5773 mch_memmove(match, s, e - s + 1); | |
7 | 5774 } |
5775 } | |
5873 | 5776 |
2929 | 5777 if (ga.ga_len == 0) |
3628 | 5778 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5779 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5780 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5781 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5782 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5783 |
7 | 5784 *file = ga.ga_data; |
5785 *num_file = ga.ga_len; | |
5786 return OK; | |
5787 } | |
5788 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5789 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5790 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5791 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5792 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5793 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5794 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5795 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5796 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5797 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5798 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5799 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5800 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5801 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5802 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5803 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5804 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5805 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5806 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5807 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5808 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5809 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
|
5810 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5811 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5815 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5816 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5817 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
|
5818 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5819 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5820 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5821 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
|
5822 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5823 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
|
5824 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 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
|
5827 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5828 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5830 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5832 /* 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
|
5833 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5834 remove_duplicates(&ga); |
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 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5838 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 |
7 | 5841 #endif |
5842 | |
5843 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5844 /* | |
5845 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5846 * Adds the matches to "ga". Caller must init "ga". |
7 | 5847 */ |
5873 | 5848 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5849 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5850 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5851 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5852 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5853 int expand_options) |
7 | 5854 { |
5855 expand_T xpc; | |
5856 char_u *buf; | |
5857 int i; | |
5858 int num_p; | |
5859 char_u **p; | |
5860 | |
5861 buf = alloc(MAXPATHL); | |
5862 if (buf == NULL) | |
5873 | 5863 return; |
7 | 5864 |
632 | 5865 ExpandInit(&xpc); |
7 | 5866 xpc.xp_context = EXPAND_FILES; |
632 | 5867 |
7 | 5868 /* Loop over all entries in {path}. */ |
5869 while (*path != NUL) | |
5870 { | |
5871 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5872 copy_option_part(&path, buf, MAXPATHL, ","); | |
5873 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5874 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5875 # 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
|
5876 /* 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
|
5877 * 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
|
5878 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
|
5879 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5880 # else |
7 | 5881 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
|
5882 # endif |
7 | 5883 STRCAT(buf, file); |
1754 | 5884 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5885 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5886 { |
1754 | 5887 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5888 |
5889 if (ga_grow(ga, num_p) == OK) | |
7 | 5890 { |
5891 for (i = 0; i < num_p; ++i) | |
5892 { | |
5873 | 5893 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5894 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5895 ++ga->ga_len; |
7 | 5896 } |
5897 } | |
5873 | 5898 |
7 | 5899 FreeWild(num_p, p); |
5900 } | |
5901 } | |
5902 } | |
5903 | |
5904 vim_free(buf); | |
5905 } | |
5906 | |
5907 #endif | |
5908 | |
5909 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5910 | |
5911 /********************************* | |
5912 * Command line history stuff * | |
5913 *********************************/ | |
5914 | |
5915 /* | |
5916 * Translate a history character to the associated type number. | |
5917 */ | |
5918 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5919 hist_char2type(int c) |
7 | 5920 { |
5921 if (c == ':') | |
5922 return HIST_CMD; | |
5923 if (c == '=') | |
5924 return HIST_EXPR; | |
5925 if (c == '@') | |
5926 return HIST_INPUT; | |
5927 if (c == '>') | |
5928 return HIST_DEBUG; | |
5929 return HIST_SEARCH; /* must be '?' or '/' */ | |
5930 } | |
5931 | |
5932 /* | |
5933 * Table of history names. | |
5934 * These names are used in :history and various hist...() functions. | |
5935 * It is sufficient to give the significant prefix of a history name. | |
5936 */ | |
5937 | |
5938 static char *(history_names[]) = | |
5939 { | |
5940 "cmd", | |
5941 "search", | |
5942 "expr", | |
5943 "input", | |
5944 "debug", | |
5945 NULL | |
5946 }; | |
5947 | |
3503 | 5948 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5949 /* | |
5950 * Function given to ExpandGeneric() to obtain the possible first | |
5951 * arguments of the ":history command. | |
5952 */ | |
5953 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5954 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5955 { |
5956 static char_u compl[2] = { NUL, NUL }; | |
5957 char *short_names = ":=@>?/"; | |
3529 | 5958 int short_names_count = (int)STRLEN(short_names); |
3503 | 5959 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5960 | |
5961 if (idx < short_names_count) | |
5962 { | |
5963 compl[0] = (char_u)short_names[idx]; | |
5964 return compl; | |
5965 } | |
5966 if (idx < short_names_count + history_name_count) | |
5967 return (char_u *)history_names[idx - short_names_count]; | |
5968 if (idx == short_names_count + history_name_count) | |
5969 return (char_u *)"all"; | |
5970 return NULL; | |
5971 } | |
5972 #endif | |
5973 | |
7 | 5974 /* |
5975 * init_history() - Initialize the command line history. | |
5976 * Also used to re-allocate the history when the size changes. | |
5977 */ | |
356 | 5978 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5979 init_history(void) |
7 | 5980 { |
5981 int newlen; /* new length of history table */ | |
5982 histentry_T *temp; | |
5983 int i; | |
5984 int j; | |
5985 int type; | |
5986 | |
5987 /* | |
5988 * If size of history table changed, reallocate it | |
5989 */ | |
5990 newlen = (int)p_hi; | |
5991 if (newlen != hislen) /* history length changed */ | |
5992 { | |
5993 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5994 { | |
5995 if (newlen) | |
5996 { | |
5997 temp = (histentry_T *)lalloc( | |
5998 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5999 if (temp == NULL) /* out of memory! */ | |
6000 { | |
6001 if (type == 0) /* first one: just keep the old length */ | |
6002 { | |
6003 newlen = hislen; | |
6004 break; | |
6005 } | |
6006 /* Already changed one table, now we can only have zero | |
6007 * length for all tables. */ | |
6008 newlen = 0; | |
6009 type = -1; | |
6010 continue; | |
6011 } | |
6012 } | |
6013 else | |
6014 temp = NULL; | |
6015 if (newlen == 0 || temp != NULL) | |
6016 { | |
6017 if (hisidx[type] < 0) /* there are no entries yet */ | |
6018 { | |
6019 for (i = 0; i < newlen; ++i) | |
4258 | 6020 clear_hist_entry(&temp[i]); |
7 | 6021 } |
6022 else if (newlen > hislen) /* array becomes bigger */ | |
6023 { | |
6024 for (i = 0; i <= hisidx[type]; ++i) | |
6025 temp[i] = history[type][i]; | |
6026 j = i; | |
6027 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6028 clear_hist_entry(&temp[i]); |
7 | 6029 for ( ; j < hislen; ++i, ++j) |
6030 temp[i] = history[type][j]; | |
6031 } | |
6032 else /* array becomes smaller or 0 */ | |
6033 { | |
6034 j = hisidx[type]; | |
6035 for (i = newlen - 1; ; --i) | |
6036 { | |
6037 if (i >= 0) /* copy newest entries */ | |
6038 temp[i] = history[type][j]; | |
6039 else /* remove older entries */ | |
6040 vim_free(history[type][j].hisstr); | |
6041 if (--j < 0) | |
6042 j = hislen - 1; | |
6043 if (j == hisidx[type]) | |
6044 break; | |
6045 } | |
6046 hisidx[type] = newlen - 1; | |
6047 } | |
6048 vim_free(history[type]); | |
6049 history[type] = temp; | |
6050 } | |
6051 } | |
6052 hislen = newlen; | |
6053 } | |
6054 } | |
6055 | |
4258 | 6056 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6057 clear_hist_entry(histentry_T *hisptr) |
4258 | 6058 { |
6059 hisptr->hisnum = 0; | |
6060 hisptr->viminfo = FALSE; | |
6061 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6062 hisptr->time_set = 0; |
4258 | 6063 } |
6064 | |
7 | 6065 /* |
6066 * Check if command line 'str' is already in history. | |
6067 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6068 */ | |
6069 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6070 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6071 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6072 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6073 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
|
6074 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6075 int writing) /* ignore entries read from viminfo */ |
7 | 6076 { |
6077 int i; | |
6078 int last_i = -1; | |
2986 | 6079 char_u *p; |
7 | 6080 |
6081 if (hisidx[type] < 0) | |
6082 return FALSE; | |
6083 i = hisidx[type]; | |
6084 do | |
6085 { | |
6086 if (history[type][i].hisstr == NULL) | |
6087 return FALSE; | |
2986 | 6088 |
6089 /* For search history, check that the separator character matches as | |
6090 * well. */ | |
6091 p = history[type][i].hisstr; | |
6092 if (STRCMP(str, p) == 0 | |
4285 | 6093 && !(writing && history[type][i].viminfo) |
2986 | 6094 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6095 { |
6096 if (!move_to_front) | |
6097 return TRUE; | |
6098 last_i = i; | |
6099 break; | |
6100 } | |
6101 if (--i < 0) | |
6102 i = hislen - 1; | |
6103 } while (i != hisidx[type]); | |
6104 | |
6105 if (last_i >= 0) | |
6106 { | |
6107 str = history[type][i].hisstr; | |
6108 while (i != hisidx[type]) | |
6109 { | |
6110 if (++i >= hislen) | |
6111 i = 0; | |
6112 history[type][last_i] = history[type][i]; | |
6113 last_i = i; | |
6114 } | |
4258 | 6115 history[type][i].hisnum = ++hisnum[type]; |
6116 history[type][i].viminfo = FALSE; | |
7 | 6117 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6118 history[type][i].time_set = vim_time(); |
7 | 6119 return TRUE; |
6120 } | |
6121 return FALSE; | |
6122 } | |
6123 | |
6124 /* | |
6125 * Convert history name (from table above) to its HIST_ equivalent. | |
6126 * When "name" is empty, return "cmd" history. | |
6127 * Returns -1 for unknown history name. | |
6128 */ | |
6129 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6130 get_histtype(char_u *name) |
7 | 6131 { |
6132 int i; | |
6133 int len = (int)STRLEN(name); | |
6134 | |
6135 /* No argument: use current history. */ | |
6136 if (len == 0) | |
6137 return hist_char2type(ccline.cmdfirstc); | |
6138 | |
6139 for (i = 0; history_names[i] != NULL; ++i) | |
6140 if (STRNICMP(name, history_names[i], len) == 0) | |
6141 return i; | |
6142 | |
6143 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6144 return hist_char2type(name[0]); | |
6145 | |
6146 return -1; | |
6147 } | |
6148 | |
6149 static int last_maptick = -1; /* last seen maptick */ | |
6150 | |
6151 /* | |
6152 * Add the given string to the given history. If the string is already in the | |
6153 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6154 * values. | |
6155 */ | |
6156 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6157 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6158 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6159 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6160 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
|
6161 int sep) /* separator character used (search hist) */ |
7 | 6162 { |
6163 histentry_T *hisptr; | |
6164 int len; | |
6165 | |
6166 if (hislen == 0) /* no history */ | |
6167 return; | |
6168 | |
5467 | 6169 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6170 return; | |
6171 | |
7 | 6172 /* |
6173 * Searches inside the same mapping overwrite each other, so that only | |
6174 * the last line is kept. Be careful not to remove a line that was moved | |
6175 * down, only lines that were added. | |
6176 */ | |
6177 if (histype == HIST_SEARCH && in_map) | |
6178 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6179 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6180 { |
6181 /* Current line is from the same mapping, remove it */ | |
6182 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6183 vim_free(hisptr->hisstr); | |
4258 | 6184 clear_hist_entry(hisptr); |
7 | 6185 --hisnum[histype]; |
6186 if (--hisidx[HIST_SEARCH] < 0) | |
6187 hisidx[HIST_SEARCH] = hislen - 1; | |
6188 } | |
6189 last_maptick = -1; | |
6190 } | |
4285 | 6191 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6192 { |
6193 if (++hisidx[histype] == hislen) | |
6194 hisidx[histype] = 0; | |
6195 hisptr = &history[histype][hisidx[histype]]; | |
6196 vim_free(hisptr->hisstr); | |
6197 | |
6198 /* Store the separator after the NUL of the string. */ | |
835 | 6199 len = (int)STRLEN(new_entry); |
7 | 6200 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6201 if (hisptr->hisstr != NULL) | |
6202 hisptr->hisstr[len + 1] = sep; | |
6203 | |
6204 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6205 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6206 hisptr->time_set = vim_time(); |
7 | 6207 if (histype == HIST_SEARCH && in_map) |
6208 last_maptick = maptick; | |
6209 } | |
6210 } | |
6211 | |
6212 #if defined(FEAT_EVAL) || defined(PROTO) | |
6213 | |
6214 /* | |
6215 * Get identifier of newest history entry. | |
6216 * "histype" may be one of the HIST_ values. | |
6217 */ | |
6218 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6219 get_history_idx(int histype) |
7 | 6220 { |
6221 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6222 || hisidx[histype] < 0) | |
6223 return -1; | |
6224 | |
6225 return history[histype][hisidx[histype]].hisnum; | |
6226 } | |
6227 | |
531 | 6228 /* |
7 | 6229 * Calculate history index from a number: |
6230 * num > 0: seen as identifying number of a history entry | |
6231 * num < 0: relative position in history wrt newest entry | |
6232 * "histype" may be one of the HIST_ values. | |
6233 */ | |
6234 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6235 calc_hist_idx(int histype, int num) |
7 | 6236 { |
6237 int i; | |
6238 histentry_T *hist; | |
6239 int wrapped = FALSE; | |
6240 | |
6241 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6242 || (i = hisidx[histype]) < 0 || num == 0) | |
6243 return -1; | |
6244 | |
6245 hist = history[histype]; | |
6246 if (num > 0) | |
6247 { | |
6248 while (hist[i].hisnum > num) | |
6249 if (--i < 0) | |
6250 { | |
6251 if (wrapped) | |
6252 break; | |
6253 i += hislen; | |
6254 wrapped = TRUE; | |
6255 } | |
6256 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6257 return i; | |
6258 } | |
6259 else if (-num <= hislen) | |
6260 { | |
6261 i += num + 1; | |
6262 if (i < 0) | |
6263 i += hislen; | |
6264 if (hist[i].hisstr != NULL) | |
6265 return i; | |
6266 } | |
6267 return -1; | |
6268 } | |
6269 | |
6270 /* | |
6271 * Get a history entry by its index. | |
6272 * "histype" may be one of the HIST_ values. | |
6273 */ | |
6274 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6275 get_history_entry(int histype, int idx) |
7 | 6276 { |
6277 idx = calc_hist_idx(histype, idx); | |
6278 if (idx >= 0) | |
6279 return history[histype][idx].hisstr; | |
6280 else | |
6281 return (char_u *)""; | |
6282 } | |
6283 | |
6284 /* | |
6285 * Clear all entries of a history. | |
6286 * "histype" may be one of the HIST_ values. | |
6287 */ | |
6288 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6289 clr_history(int histype) |
7 | 6290 { |
6291 int i; | |
6292 histentry_T *hisptr; | |
6293 | |
6294 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6295 { | |
6296 hisptr = history[histype]; | |
6297 for (i = hislen; i--;) | |
6298 { | |
6299 vim_free(hisptr->hisstr); | |
4258 | 6300 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6301 hisptr++; |
7 | 6302 } |
6303 hisidx[histype] = -1; /* mark history as cleared */ | |
6304 hisnum[histype] = 0; /* reset identifier counter */ | |
6305 return OK; | |
6306 } | |
6307 return FAIL; | |
6308 } | |
6309 | |
6310 /* | |
6311 * Remove all entries matching {str} from a history. | |
6312 * "histype" may be one of the HIST_ values. | |
6313 */ | |
6314 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6315 del_history_entry(int histype, char_u *str) |
7 | 6316 { |
6317 regmatch_T regmatch; | |
6318 histentry_T *hisptr; | |
6319 int idx; | |
6320 int i; | |
6321 int last; | |
6322 int found = FALSE; | |
6323 | |
6324 regmatch.regprog = NULL; | |
6325 regmatch.rm_ic = FALSE; /* always match case */ | |
6326 if (hislen != 0 | |
6327 && histype >= 0 | |
6328 && histype < HIST_COUNT | |
6329 && *str != NUL | |
6330 && (idx = hisidx[histype]) >= 0 | |
6331 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6332 != NULL) | |
6333 { | |
6334 i = last = idx; | |
6335 do | |
6336 { | |
6337 hisptr = &history[histype][i]; | |
6338 if (hisptr->hisstr == NULL) | |
6339 break; | |
6340 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6341 { | |
6342 found = TRUE; | |
6343 vim_free(hisptr->hisstr); | |
4258 | 6344 clear_hist_entry(hisptr); |
7 | 6345 } |
6346 else | |
6347 { | |
6348 if (i != last) | |
6349 { | |
6350 history[histype][last] = *hisptr; | |
4258 | 6351 clear_hist_entry(hisptr); |
7 | 6352 } |
6353 if (--last < 0) | |
6354 last += hislen; | |
6355 } | |
6356 if (--i < 0) | |
6357 i += hislen; | |
6358 } while (i != idx); | |
6359 if (history[histype][idx].hisstr == NULL) | |
6360 hisidx[histype] = -1; | |
6361 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6362 vim_regfree(regmatch.regprog); |
7 | 6363 return found; |
6364 } | |
6365 | |
6366 /* | |
6367 * Remove an indexed entry from a history. | |
6368 * "histype" may be one of the HIST_ values. | |
6369 */ | |
6370 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6371 del_history_idx(int histype, int idx) |
7 | 6372 { |
6373 int i, j; | |
6374 | |
6375 i = calc_hist_idx(histype, idx); | |
6376 if (i < 0) | |
6377 return FALSE; | |
6378 idx = hisidx[histype]; | |
6379 vim_free(history[histype][i].hisstr); | |
6380 | |
6381 /* When deleting the last added search string in a mapping, reset | |
6382 * last_maptick, so that the last added search string isn't deleted again. | |
6383 */ | |
6384 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6385 last_maptick = -1; | |
6386 | |
6387 while (i != idx) | |
6388 { | |
6389 j = (i + 1) % hislen; | |
6390 history[histype][i] = history[histype][j]; | |
6391 i = j; | |
6392 } | |
4258 | 6393 clear_hist_entry(&history[histype][i]); |
7 | 6394 if (--i < 0) |
6395 i += hislen; | |
6396 hisidx[histype] = i; | |
6397 return TRUE; | |
6398 } | |
6399 | |
6400 #endif /* FEAT_EVAL */ | |
6401 | |
6402 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6403 /* | |
6404 * Very specific function to remove the value in ":set key=val" from the | |
6405 * history. | |
6406 */ | |
6407 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6408 remove_key_from_history(void) |
7 | 6409 { |
6410 char_u *p; | |
6411 int i; | |
6412 | |
6413 i = hisidx[HIST_CMD]; | |
6414 if (i < 0) | |
6415 return; | |
6416 p = history[HIST_CMD][i].hisstr; | |
6417 if (p != NULL) | |
6418 for ( ; *p; ++p) | |
6419 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6420 { | |
6421 p = vim_strchr(p + 3, '='); | |
6422 if (p == NULL) | |
6423 break; | |
6424 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6425 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6426 if (p[i] == '\\' && p[i + 1]) |
6427 ++i; | |
1621 | 6428 STRMOVE(p, p + i); |
7 | 6429 --p; |
6430 } | |
6431 } | |
6432 #endif | |
6433 | |
6434 #endif /* FEAT_CMDHIST */ | |
6435 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6436 #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
|
6437 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 * 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
|
6439 * 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
|
6440 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6441 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6446 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6447 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6448 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
|
6449 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6450 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6452 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6453 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6454 #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
|
6455 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6456 * 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
|
6457 * 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
|
6458 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6463 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
|
6464 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 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
|
6468 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 * 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
|
6472 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 * 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
|
6474 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6475 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6478 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 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
|
6480 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 |
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 * 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
|
6488 * 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
|
6489 * 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
|
6490 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6495 struct cmdline_info *p = get_ccline_ptr(); |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6496 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6497 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6498 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6500 /* 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
|
6501 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6503 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6504 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6506 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6507 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6508 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6509 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6510 #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
|
6511 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6512 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6513 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6514 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6515 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6516 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6517 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 get_cmdline_type(void) |
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 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
|
6521 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6522 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6524 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6525 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6526 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6527 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6528 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6529 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6532 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6533 |
7 | 6534 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6535 /* | |
6536 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6537 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6538 * Returns OK if parsed successfully, otherwise FAIL. | |
6539 */ | |
6540 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6541 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6542 { |
6543 int len; | |
6544 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6545 varnumber_T num; |
7 | 6546 |
6547 *str = skipwhite(*str); | |
6548 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6549 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6550 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6551 *str += len; |
6552 *num1 = (int)num; | |
6553 first = TRUE; | |
6554 } | |
6555 *str = skipwhite(*str); | |
6556 if (**str == ',') /* parse "to" part of range */ | |
6557 { | |
6558 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6559 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6560 if (len > 0) |
6561 { | |
6562 *num2 = (int)num; | |
6563 *str = skipwhite(*str + len); | |
6564 } | |
6565 else if (!first) /* no number given at all */ | |
6566 return FAIL; | |
6567 } | |
6568 else if (first) /* only one number given */ | |
6569 *num2 = *num1; | |
6570 return OK; | |
6571 } | |
6572 #endif | |
6573 | |
6574 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6575 /* | |
6576 * :history command - print a history | |
6577 */ | |
6578 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6579 ex_history(exarg_T *eap) |
7 | 6580 { |
6581 histentry_T *hist; | |
6582 int histype1 = HIST_CMD; | |
6583 int histype2 = HIST_CMD; | |
6584 int hisidx1 = 1; | |
6585 int hisidx2 = -1; | |
6586 int idx; | |
6587 int i, j, k; | |
6588 char_u *end; | |
6589 char_u *arg = eap->arg; | |
6590 | |
6591 if (hislen == 0) | |
6592 { | |
6593 MSG(_("'history' option is zero")); | |
6594 return; | |
6595 } | |
6596 | |
6597 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6598 { | |
6599 end = arg; | |
6600 while (ASCII_ISALPHA(*end) | |
6601 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6602 end++; | |
6603 i = *end; | |
6604 *end = NUL; | |
6605 histype1 = get_histtype(arg); | |
6606 if (histype1 == -1) | |
6607 { | |
1853 | 6608 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6609 { |
6610 histype1 = 0; | |
6611 histype2 = HIST_COUNT-1; | |
6612 } | |
6613 else | |
6614 { | |
6615 *end = i; | |
6616 EMSG(_(e_trailing)); | |
6617 return; | |
6618 } | |
6619 } | |
6620 else | |
6621 histype2 = histype1; | |
6622 *end = i; | |
6623 } | |
6624 else | |
6625 end = arg; | |
6626 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6627 { | |
6628 EMSG(_(e_trailing)); | |
6629 return; | |
6630 } | |
6631 | |
6632 for (; !got_int && histype1 <= histype2; ++histype1) | |
6633 { | |
6634 STRCPY(IObuff, "\n # "); | |
6635 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6636 MSG_PUTS_TITLE(IObuff); | |
6637 idx = hisidx[histype1]; | |
6638 hist = history[histype1]; | |
6639 j = hisidx1; | |
6640 k = hisidx2; | |
6641 if (j < 0) | |
6642 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6643 if (k < 0) | |
6644 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6645 if (idx >= 0 && j <= k) | |
6646 for (i = idx + 1; !got_int; ++i) | |
6647 { | |
6648 if (i == hislen) | |
6649 i = 0; | |
6650 if (hist[i].hisstr != NULL | |
6651 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6652 { | |
6653 msg_putchar('\n'); | |
6654 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6655 hist[i].hisnum); | |
6656 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6657 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6658 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6659 else |
6660 STRCAT(IObuff, hist[i].hisstr); | |
6661 msg_outtrans(IObuff); | |
6662 out_flush(); | |
6663 } | |
6664 if (i == idx) | |
6665 break; | |
6666 } | |
6667 } | |
6668 } | |
6669 #endif | |
6670 | |
6671 #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
|
6672 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6673 * 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
|
6674 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6675 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
|
6676 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6677 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
|
6678 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6679 static int viminfo_add_at_front = FALSE; |
6680 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6681 static int hist_type2char(int type, int use_question); |
7 | 6682 |
6683 /* | |
6684 * Translate a history type number to the associated character. | |
6685 */ | |
6686 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6687 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6688 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6689 int use_question) /* use '?' instead of '/' */ |
7 | 6690 { |
6691 if (type == HIST_CMD) | |
6692 return ':'; | |
6693 if (type == HIST_SEARCH) | |
6694 { | |
6695 if (use_question) | |
6696 return '?'; | |
6697 else | |
6698 return '/'; | |
6699 } | |
6700 if (type == HIST_EXPR) | |
6701 return '='; | |
6702 return '@'; | |
6703 } | |
6704 | |
6705 /* | |
6706 * Prepare for reading the history from the viminfo file. | |
6707 * This allocates history arrays to store the read history lines. | |
6708 */ | |
6709 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6710 prepare_viminfo_history(int asklen, int writing) |
7 | 6711 { |
6712 int i; | |
6713 int num; | |
6714 int type; | |
6715 int len; | |
6716 | |
6717 init_history(); | |
4285 | 6718 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6719 if (asklen > hislen) |
6720 asklen = hislen; | |
6721 | |
6722 for (type = 0; type < HIST_COUNT; ++type) | |
6723 { | |
4258 | 6724 /* Count the number of empty spaces in the history list. Entries read |
6725 * from viminfo previously are also considered empty. If there are | |
6726 * more spaces available than we request, then fill them up. */ | |
7 | 6727 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6728 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6729 num++; |
6730 len = asklen; | |
6731 if (num > len) | |
6732 len = num; | |
6733 if (len <= 0) | |
6734 viminfo_history[type] = NULL; | |
6735 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6736 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6737 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6738 if (viminfo_history[type] == NULL) |
6739 len = 0; | |
6740 viminfo_hislen[type] = len; | |
6741 viminfo_hisidx[type] = 0; | |
6742 } | |
6743 } | |
6744 | |
6745 /* | |
6746 * Accept a line from the viminfo, store it in the history array when it's | |
6747 * new. | |
6748 */ | |
6749 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6750 read_viminfo_history(vir_T *virp, int writing) |
7 | 6751 { |
6752 int type; | |
6753 long_u len; | |
6754 char_u *val; | |
6755 char_u *p; | |
6756 | |
6757 type = hist_char2type(virp->vir_line[0]); | |
6758 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6759 { | |
6760 val = viminfo_readstring(virp, 1, TRUE); | |
6761 if (val != NULL && *val != NUL) | |
6762 { | |
3316 | 6763 int sep = (*val == ' ' ? NUL : *val); |
6764 | |
7 | 6765 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6766 viminfo_add_at_front, sep, writing)) |
7 | 6767 { |
6768 /* Need to re-allocate to append the separator byte. */ | |
6769 len = STRLEN(val); | |
6770 p = lalloc(len + 2, TRUE); | |
6771 if (p != NULL) | |
6772 { | |
6773 if (type == HIST_SEARCH) | |
6774 { | |
6775 /* Search entry: Move the separator from the first | |
6776 * column to after the NUL. */ | |
6777 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6778 p[len] = sep; |
7 | 6779 } |
6780 else | |
6781 { | |
6782 /* Not a search entry: No separator in the viminfo | |
6783 * file, add a NUL separator. */ | |
6784 mch_memmove(p, val, (size_t)len + 1); | |
6785 p[len + 1] = NUL; | |
6786 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 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
|
6788 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
|
6789 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
|
6790 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
|
6791 viminfo_hisidx[type]++; |
7 | 6792 } |
6793 } | |
6794 } | |
6795 vim_free(val); | |
6796 } | |
6797 return viminfo_readline(virp); | |
6798 } | |
6799 | |
4285 | 6800 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6801 * 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
|
6802 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6803 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6804 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6805 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6806 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6807 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6813 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
|
6814 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6815 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6816 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6817 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6818 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6819 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6820 || (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
|
6821 || 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
|
6822 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6823 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6824 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 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
|
6828 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6829 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6830 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6831 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6832 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
|
6833 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6834 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6837 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
|
6838 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 /* 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
|
6840 * 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
|
6841 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
|
6842 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6843 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6844 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6845 && (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
|
6846 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6850 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6851 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 /* 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
|
6855 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6856 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6857 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6858 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6859 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6861 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6862 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
|
6863 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6864 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6865 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
|
6866 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6868 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
|
6869 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 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
|
6871 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6872 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6873 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6874 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6875 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6876 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6877 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6878 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6879 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 * 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
|
6881 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6886 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6888 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 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
|
6911 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 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
|
6914 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 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
|
6916 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 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
|
6922 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 #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
|
6929 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 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
|
6934 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 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
|
6939 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
|
6940 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 * 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
|
6946 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 /* 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
|
6958 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 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
|
6960 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
|
6961 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
|
6962 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6965 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6966 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 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
|
6968 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
|
6969 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 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
|
6976 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6978 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6979 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6982 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6983 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6984 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6985 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6986 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6990 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
|
6991 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6992 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6993 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
|
6994 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
|
6995 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6996 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6997 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6999 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7000 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 /* |
4285 | 7003 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7004 */ | |
7 | 7005 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 finish_viminfo_history(vir_T *virp) |
7 | 7007 { |
7008 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7009 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7010 |
7011 for (type = 0; type < HIST_COUNT; ++type) | |
7012 { | |
7013 if (history[type] == NULL) | |
4283 | 7014 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7015 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7017 merge_history(type); |
7 | 7018 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7020 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7021 VIM_CLEAR(viminfo_history[type]); |
4327 | 7022 viminfo_hisidx[type] = 0; |
7 | 7023 } |
7024 } | |
7025 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7026 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7027 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7028 * 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
|
7029 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7030 * 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
|
7031 */ |
7 | 7032 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7033 write_viminfo_history(FILE *fp, int merge) |
7 | 7034 { |
7035 int i; | |
7036 int type; | |
7037 int num_saved; | |
4283 | 7038 int round; |
7 | 7039 |
7040 init_history(); | |
7041 if (hislen == 0) | |
7042 return; | |
7043 for (type = 0; type < HIST_COUNT; ++type) | |
7044 { | |
7045 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7046 if (num_saved == 0) | |
7047 continue; | |
7048 if (num_saved < 0) /* Use default */ | |
7049 num_saved = hislen; | |
7050 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7051 type == HIST_CMD ? _("Command Line") : | |
7052 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7053 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7054 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7055 _("Debug Line")); |
7 | 7056 if (num_saved > hislen) |
7057 num_saved = hislen; | |
4283 | 7058 |
7059 /* | |
7060 * Merge typed and viminfo history: | |
7061 * round 1: history of typed commands. | |
7062 * round 2: history from recently read viminfo. | |
7063 */ | |
7064 for (round = 1; round <= 2; ++round) | |
7065 { | |
4307 | 7066 if (round == 1) |
7067 /* start at newest entry, somewhere in the list */ | |
7068 i = hisidx[type]; | |
7069 else if (viminfo_hisidx[type] > 0) | |
7070 /* start at newest entry, first in the list */ | |
7071 i = 0; | |
7072 else | |
7073 /* empty list */ | |
7074 i = -1; | |
4283 | 7075 if (i >= 0) |
7076 while (num_saved > 0 | |
7077 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7078 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7079 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7080 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7081 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7082 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7083 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7084 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7085 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7086 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7087 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7088 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7089 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7090 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7091 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7092 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7093 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7094 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7095 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7096 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7097 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7098 || !history[type][i].viminfo)) |
7 | 7099 { |
4283 | 7100 --num_saved; |
7101 fputc(hist_type2char(type, TRUE), fp); | |
7102 /* For the search history: put the separator in the | |
7103 * second column; use a space if there isn't one. */ | |
7104 if (type == HIST_SEARCH) | |
7105 { | |
7106 c = p[STRLEN(p) + 1]; | |
7107 putc(c == NUL ? ' ' : c, fp); | |
7108 } | |
7109 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7110 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7111 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7112 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7113 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7114 /* 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
|
7115 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7116 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7117 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7118 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7119 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7120 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
|
7121 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7122 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7123 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7124 } |
7 | 7125 } |
4283 | 7126 if (round == 1) |
7127 { | |
7128 /* Decrement index, loop around and stop when back at | |
7129 * the start. */ | |
7130 if (--i < 0) | |
7131 i = hislen - 1; | |
7132 if (i == hisidx[type]) | |
7133 break; | |
7134 } | |
7135 else | |
7136 { | |
7137 /* Increment index. Stop at the end in the while. */ | |
7138 ++i; | |
7139 } | |
7 | 7140 } |
4283 | 7141 } |
4285 | 7142 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7143 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7144 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
|
7145 VIM_CLEAR(viminfo_history[type]); |
4311 | 7146 viminfo_hisidx[type] = 0; |
7 | 7147 } |
7148 } | |
7149 #endif /* FEAT_VIMINFO */ | |
7150 | |
7151 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7152 /* | |
7153 * Write a character at the current cursor+offset position. | |
7154 * It is directly written into the command buffer block. | |
7155 */ | |
7156 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7157 cmd_pchar(int c, int offset) |
7 | 7158 { |
7159 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7160 { | |
7161 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7162 return; | |
7163 } | |
7164 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7165 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7166 } | |
7167 | |
7168 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7169 cmd_gchar(int offset) |
7 | 7170 { |
7171 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7172 { | |
7173 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7174 return NUL; | |
7175 } | |
7176 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7177 } | |
7178 #endif | |
7179 | |
7180 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7181 /* | |
7182 * Open a window on the current command line and history. Allow editing in | |
7183 * the window. Returns when the window is closed. | |
7184 * Returns: | |
7185 * CR if the command is to be executed | |
7186 * Ctrl_C if it is to be abandoned | |
7187 * K_IGNORE if editing continues | |
7188 */ | |
7189 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
|
7190 open_cmdwin(void) |
7 | 7191 { |
7192 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7193 bufref_T old_curbuf; |
7 | 7194 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7195 bufref_T bufref; |
7 | 7196 win_T *wp; |
7197 int i; | |
7198 linenr_T lnum; | |
7199 int histtype; | |
7200 garray_T winsizes; | |
7201 int save_restart_edit = restart_edit; | |
7202 int save_State = State; | |
7203 int save_exmode = exmode_active; | |
510 | 7204 #ifdef FEAT_RIGHTLEFT |
7205 int save_cmdmsg_rl = cmdmsg_rl; | |
7206 #endif | |
6145 | 7207 #ifdef FEAT_FOLDING |
7208 int save_KeyTyped; | |
7209 #endif | |
7 | 7210 |
7211 /* Can't do this recursively. Can't do it when typing a password. */ | |
7212 if (cmdwin_type != 0 | |
7213 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7214 || cmdline_star > 0 | |
7215 # endif | |
7216 ) | |
7217 { | |
7218 beep_flush(); | |
7219 return K_IGNORE; | |
7220 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7221 set_bufref(&old_curbuf, curbuf); |
7 | 7222 |
7223 /* Save current window sizes. */ | |
7224 win_size_save(&winsizes); | |
7225 | |
7226 /* Don't execute autocommands while creating the window. */ | |
1410 | 7227 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7228 |
683 | 7229 /* don't use a new tab page */ |
7230 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
|
7231 cmdmod.noswapfile = 1; |
683 | 7232 |
7 | 7233 /* Create a window for the command-line buffer. */ |
7234 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7235 { | |
7236 beep_flush(); | |
1410 | 7237 unblock_autocmds(); |
7 | 7238 return K_IGNORE; |
7239 } | |
1831 | 7240 cmdwin_type = get_cmdline_type(); |
7 | 7241 |
7242 /* Create the command-line buffer empty. */ | |
1743 | 7243 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7244 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7245 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7246 curbuf->b_p_ma = TRUE; | |
1865 | 7247 #ifdef FEAT_FOLDING |
7248 curwin->w_p_fen = FALSE; | |
7249 #endif | |
7 | 7250 # ifdef FEAT_RIGHTLEFT |
510 | 7251 curwin->w_p_rl = cmdmsg_rl; |
7252 cmdmsg_rl = FALSE; | |
7 | 7253 # endif |
2583 | 7254 RESET_BINDING(curwin); |
7 | 7255 |
7256 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7257 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7258 /* 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
|
7259 ++curbuf_lock; |
7 | 7260 |
510 | 7261 /* Showing the prompt may have set need_wait_return, reset it. */ |
7262 need_wait_return = FALSE; | |
7263 | |
1831 | 7264 histtype = hist_char2type(cmdwin_type); |
7 | 7265 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7266 { | |
7267 if (p_wc == TAB) | |
7268 { | |
7269 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7270 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7271 } | |
7272 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7273 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7274 --curbuf_lock; |
7 | 7275 |
10 | 7276 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7277 * sets 'textwidth' to 78). */ | |
7278 curbuf->b_p_tw = 0; | |
7279 | |
7 | 7280 /* Fill the buffer with the history. */ |
7281 init_history(); | |
7282 if (hislen > 0) | |
7283 { | |
7284 i = hisidx[histtype]; | |
7285 if (i >= 0) | |
7286 { | |
7287 lnum = 0; | |
7288 do | |
7289 { | |
7290 if (++i == hislen) | |
7291 i = 0; | |
7292 if (history[histtype][i].hisstr != NULL) | |
7293 ml_append(lnum++, history[histtype][i].hisstr, | |
7294 (colnr_T)0, FALSE); | |
7295 } | |
7296 while (i != hisidx[histtype]); | |
7297 } | |
7298 } | |
7299 | |
7300 /* Replace the empty last line with the current command-line and put the | |
7301 * cursor there. */ | |
7302 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7303 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7304 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7305 changed_line_abv_curs(); |
7306 invalidate_botline(); | |
743 | 7307 redraw_later(SOME_VALID); |
7 | 7308 |
7309 /* 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
|
7310 save_cmdline(&save_ccline); |
7 | 7311 |
7312 /* No Ex mode here! */ | |
7313 exmode_active = 0; | |
7314 | |
7315 State = NORMAL; | |
7316 # ifdef FEAT_MOUSE | |
7317 setmouse(); | |
7318 # endif | |
7319 | |
7320 /* 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
|
7321 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7322 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7323 stuffcharReadbuff(K_NOP); | |
7 | 7324 |
7325 i = RedrawingDisabled; | |
7326 RedrawingDisabled = 0; | |
7327 | |
7328 /* | |
7329 * Call the main loop until <CR> or CTRL-C is typed. | |
7330 */ | |
7331 cmdwin_result = 0; | |
168 | 7332 main_loop(TRUE, FALSE); |
7 | 7333 |
7334 RedrawingDisabled = i; | |
7335 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7336 # ifdef FEAT_FOLDING |
6145 | 7337 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7338 # endif |
6145 | 7339 |
7 | 7340 /* 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
|
7341 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7342 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7343 # ifdef FEAT_FOLDING |
6145 | 7344 /* Restore KeyTyped in case it is modified by autocommands */ |
7345 KeyTyped = save_KeyTyped; | |
7 | 7346 # endif |
7347 | |
1214 | 7348 /* 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
|
7349 restore_cmdline(&save_ccline); |
7 | 7350 cmdwin_type = 0; |
7351 | |
7352 exmode_active = save_exmode; | |
7353 | |
1612 | 7354 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7355 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7356 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7357 { |
7358 cmdwin_result = Ctrl_C; | |
7359 EMSG(_("E199: Active window or buffer deleted")); | |
7360 } | |
7361 else | |
7362 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7363 # if defined(FEAT_EVAL) |
7 | 7364 /* autocmds may abort script processing */ |
7365 if (aborting() && cmdwin_result != K_IGNORE) | |
7366 cmdwin_result = Ctrl_C; | |
7367 # endif | |
7368 /* Set the new command line from the cmdline buffer. */ | |
7369 vim_free(ccline.cmdbuff); | |
510 | 7370 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7371 { |
510 | 7372 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7373 | |
7374 if (histtype == HIST_CMD) | |
7375 { | |
7376 /* Execute the command directly. */ | |
7377 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7378 cmdwin_result = CAR; | |
7379 } | |
7380 else | |
7381 { | |
7382 /* First need to cancel what we were doing. */ | |
7383 ccline.cmdbuff = NULL; | |
7384 stuffcharReadbuff(':'); | |
7385 stuffReadbuff((char_u *)p); | |
7386 stuffcharReadbuff(CAR); | |
7387 } | |
7 | 7388 } |
7389 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7390 { | |
7391 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7392 cmdwin_result = CAR; | |
7393 } | |
2839 | 7394 else if (cmdwin_result == Ctrl_C) |
7395 { | |
7396 /* :q or :close, don't execute any command | |
7397 * and don't modify the cmd window. */ | |
7398 ccline.cmdbuff = NULL; | |
7399 } | |
7 | 7400 else |
7401 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7402 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
|
7403 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7404 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
|
7405 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
|
7406 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
|
7407 ccline.cmdpos = 0; |
7 | 7408 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
|
7409 } |
7 | 7410 else |
7411 { | |
7412 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7413 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7414 ccline.cmdpos = curwin->w_cursor.col; | |
7415 if (ccline.cmdpos > ccline.cmdlen) | |
7416 ccline.cmdpos = ccline.cmdlen; | |
7417 if (cmdwin_result == K_IGNORE) | |
7418 { | |
7419 set_cmdspos_cursor(); | |
7420 redrawcmd(); | |
7421 } | |
7422 } | |
7423 | |
7424 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7425 block_autocmds(); |
6876 | 7426 # ifdef FEAT_CONCEAL |
7427 /* Avoid command-line window first character being concealed. */ | |
7428 curwin->w_p_cole = 0; | |
7429 # endif | |
7 | 7430 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7431 set_bufref(&bufref, curbuf); |
7 | 7432 win_goto(old_curwin); |
7433 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7434 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7435 /* 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
|
7436 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7437 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7438 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7439 |
7440 /* Restore window sizes. */ | |
7441 win_size_restore(&winsizes); | |
7442 | |
1410 | 7443 unblock_autocmds(); |
7 | 7444 } |
7445 | |
7446 ga_clear(&winsizes); | |
7447 restart_edit = save_restart_edit; | |
510 | 7448 # ifdef FEAT_RIGHTLEFT |
7449 cmdmsg_rl = save_cmdmsg_rl; | |
7450 # endif | |
7 | 7451 |
7452 State = save_State; | |
7453 # ifdef FEAT_MOUSE | |
7454 setmouse(); | |
7455 # endif | |
7456 | |
7457 return cmdwin_result; | |
7458 } | |
7459 #endif /* FEAT_CMDWIN */ | |
7460 | |
7461 /* | |
7462 * Used for commands that either take a simple command string argument, or: | |
7463 * cmd << endmarker | |
7464 * {script} | |
7465 * endmarker | |
7466 * Returns a pointer to allocated memory with {script} or NULL. | |
7467 */ | |
7468 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7469 script_get(exarg_T *eap, char_u *cmd) |
7 | 7470 { |
7471 char_u *theline; | |
7472 char *end_pattern = NULL; | |
7473 char dot[] = "."; | |
7474 garray_T ga; | |
7475 | |
7476 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7477 return NULL; | |
7478 | |
7479 ga_init2(&ga, 1, 0x400); | |
7480 | |
7481 if (cmd[2] != NUL) | |
7482 end_pattern = (char *)skipwhite(cmd + 2); | |
7483 else | |
7484 end_pattern = dot; | |
7485 | |
7486 for (;;) | |
7487 { | |
7488 theline = eap->getline( | |
7489 #ifdef FEAT_EVAL | |
75 | 7490 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7491 #endif |
7492 NUL, eap->cookie, 0); | |
7493 | |
7494 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7495 { |
7496 vim_free(theline); | |
7 | 7497 break; |
1694 | 7498 } |
7 | 7499 |
7500 ga_concat(&ga, theline); | |
7501 ga_append(&ga, '\n'); | |
7502 vim_free(theline); | |
7503 } | |
21 | 7504 ga_append(&ga, NUL); |
7 | 7505 |
7506 return (char_u *)ga.ga_data; | |
7507 } |