Mercurial > vim
annotate src/ex_getln.c @ 14854:3b72808fbb0d v8.1.0439
patch 8.1.0439: recursive use of getcmdline() still not protected
commit https://github.com/vim/vim/commit/438d176e35c16d56ff3bb7a80300197ce5a30c4f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 30 17:11:48 2018 +0200
patch 8.1.0439: recursive use of getcmdline() still not protected
Problem: Recursive use of getcmdline() still not protected.
Solution: Instead of saving the command buffer when making a call which may
cause recursiveness, save the buffer when actually being called
recursively.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 30 Sep 2018 17:15:08 +0200 |
parents | 45d8aa272dbe |
children | 49b3bdf774ad |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
47 // The current cmdline_info. It is initialized in getcmdline() and after that |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
48 // used by other functions. When invoking getcmdline() recursively it needs |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
49 // to be saved with save_cmdline() and restored with restore_cmdline(). |
1718 | 50 static struct cmdline_info ccline; |
7 | 51 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
52 static int cmd_showtail; /* Only show path tail in lists ? */ |
7 | 53 |
54 #ifdef FEAT_EVAL | |
55 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
56 #endif | |
57 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
58 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
60 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 |
7 | 62 #ifdef FEAT_CMDHIST |
63 typedef struct hist_entry | |
64 { | |
65 int hisnum; /* identifying number */ | |
4258 | 66 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 67 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
68 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 69 } histentry_T; |
70 | |
71 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
72 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
73 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
74 /* identifying (unique) number of newest history entry */ | |
75 static int hislen = 0; /* actual length of history tables */ | |
76 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
77 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
79 static int in_history(int, char_u *, int, int, int); |
7 | 80 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
81 static int calc_hist_idx(int histype, int num); |
7 | 82 # endif |
83 #endif | |
84 | |
85 #ifdef FEAT_RIGHTLEFT | |
86 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
87 #endif | |
88 | |
89 #ifdef FEAT_FKMAP | |
90 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
91 #endif | |
92 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
93 static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void set_cmdspos_cursor(void); |
7 | 97 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
102 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
104 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
105 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 106 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 static void redrawcmd_preedit(void); |
7 | 108 #endif |
109 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
117 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
119 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static int expand_showtail(expand_T *xp); |
7 | 121 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
123 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
124 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 125 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 127 # endif |
7 | 128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
129 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 131 # endif |
132 #endif | |
4265 | 133 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
134 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 135 #endif |
7 | 136 |
137 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
138 static int open_cmdwin(void); |
7 | 139 #endif |
140 | |
3164 | 141 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
142 static int | |
143 #ifdef __BORLANDC__ | |
144 _RTLENTRYF | |
145 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
146 sort_func_compare(const void *s1, const void *s2); |
3164 | 147 #endif |
148 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
156 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
157 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
159 |
7 | 160 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
166 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
172 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
173 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
174 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
181 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
185 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
187 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
188 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
189 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
190 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
238 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
247 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
270 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
271 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 * Sets search_first_line and search_last_line to the address range. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
274 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
276 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
279 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
281 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
283 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
285 char_u *end; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 char_u *dummy; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
288 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
289 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
290 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
333 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
337 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
343 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
347 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
348 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
349 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
350 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
351 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
352 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
353 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
354 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
355 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
356 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
357 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
358 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
359 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
360 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
361 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
362 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
363 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
364 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
365 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
366 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
367 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
368 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
369 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
370 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
371 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
372 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
373 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
374 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
375 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
376 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
377 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
378 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
379 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
380 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
381 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
382 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
383 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 curwin->w_cursor = is_state->search_start; |
14760
fd69edd2c67e
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
391 parse_cmd_address(&ea, &dummy, TRUE); |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
397 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
398 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
399 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
400 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
401 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
402 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
403 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
404 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
405 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
406 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
407 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
408 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
409 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
410 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
411 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
412 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
413 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
414 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
415 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
416 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
427 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
428 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
430 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
436 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
440 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
441 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
442 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
443 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
444 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
445 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
446 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 validate_cursor(); /* needed for TAB */ |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
448 redraw_all_later(SOME_VALID); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
449 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
450 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
451 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
452 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
453 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 * Do 'incsearch' highlighting if desired. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 may_do_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
461 incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
463 int skiplen, patlen; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
464 int found; // do_search() result |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 pos_T end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
469 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
470 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
|
471 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
472 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
473 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
474 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
475 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
|
476 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
477 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
478 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
|
479 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
480 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 // 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
|
483 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
485 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 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
|
487 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 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
|
490 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
491 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
|
492 // 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
|
493 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
|
494 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
495 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
496 // 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
|
497 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
|
498 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
|
499 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
501 // 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
|
502 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
|
503 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
|
504 && 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
|
505 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
506 // 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
|
507 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
|
508 { |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
509 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 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
|
511 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
|
512 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 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
|
516 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 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
|
518 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 ++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
|
520 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 // 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
|
522 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
|
523 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 ccline.cmdbuff[skiplen + patlen] = NUL; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
529 found = do_search(NULL, firstc == ':' ? '/' : firstc, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
530 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
|
531 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
537 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
|
538 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
540 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
|
541 || 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
|
542 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
543 // match outside of address range |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
544 found = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
545 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
|
546 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
547 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 // 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
|
549 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 (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
|
552 got_int = FALSE; // don't abandon the command line |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
553 found = 0; |
14503
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 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
|
556 // 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
|
557 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
|
558 } |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
559 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 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
|
561 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 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
|
563 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 // 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
|
565 // 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
|
566 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
|
567 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
|
568 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
570 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 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
|
573 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 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
|
575 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
|
576 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 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
|
583 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
584 // Disable 'hlsearch' highlighting if the pattern matches everything. |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
585 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
586 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
587 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
588 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
589 ccline.cmdbuff[skiplen + patlen] = NUL; |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
590 if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
591 { |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
592 redraw_all_later(SOME_VALID); |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
593 set_no_hlsearch(TRUE); |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
594 } |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
595 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
596 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
597 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 // 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
|
600 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
|
601 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
|
602 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 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
|
604 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
|
605 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
606 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
607 // end of the pattern, e.g. for ":s/pat/". |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
608 if (ccline.cmdbuff[skiplen + patlen] != NUL) |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
609 curwin->w_cursor = is_state->search_start; |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
610 else if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 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
|
612 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 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
|
616 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 * 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
|
620 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 * 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
|
622 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
623 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 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
|
625 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
|
626 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 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
|
628 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
630 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
|
631 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 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
|
634 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
|
635 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
|
636 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
637 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
638 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
639 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
640 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
641 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
642 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
644 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
645 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
646 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
647 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
649 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
650 |
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 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
|
652 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 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
|
654 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
655 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
|
656 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
657 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
|
658 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
|
659 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
661 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 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
|
663 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 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
|
665 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
|
666 // 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
|
667 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 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
|
670 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 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
|
673 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 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
|
675 ++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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 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
|
682 --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
|
683 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
|
684 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 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
|
687 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
|
688 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
|
689 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
|
690 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 // 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
|
692 // 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
|
693 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
|
694 (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
|
695 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
696 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
|
697 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 // 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
|
699 // 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
|
700 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
|
701 (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
|
702 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
703 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
|
704 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
705 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 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
|
707 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
708 (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
|
709 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
710 (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
|
711 } |
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 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
|
714 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
|
715 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
|
716 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
717 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
718 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
719 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
|
720 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
|
721 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
723 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
724 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
|
725 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
|
726 return FAIL; |
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 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
729 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 * 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
|
731 * 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
|
732 * 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
|
733 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
734 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
735 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
|
736 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
737 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
|
738 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
739 // Parsing range may already set the last search pattern. |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
740 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
741 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
742 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
743 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
744 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
745 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
746 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
747 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
748 // 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
|
749 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
|
750 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
751 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
|
752 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
|
753 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
754 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
755 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
756 // 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
|
757 // 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
|
758 // 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
|
759 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
|
760 *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
|
761 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
762 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
763 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
|
764 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
|
765 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
766 // 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
|
767 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
768 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
769 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
770 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
771 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
772 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
773 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
774 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
775 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
776 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
777 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
778 /* |
7 | 779 * getcmdline() - accept a command line starting with firstc. |
780 * | |
781 * firstc == ':' get ":" command line. | |
782 * firstc == '/' or '?' get search pattern | |
783 * firstc == '=' get expression | |
784 * firstc == '@' get text for input() function | |
785 * firstc == '>' get text for debug mode | |
786 * firstc == NUL get text for :insert command | |
787 * firstc == -1 like NUL, and break on CTRL-C | |
788 * | |
789 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
790 * command line. | |
791 * | |
792 * Careful: getcmdline() can be called recursively! | |
793 * | |
794 * Return pointer to allocated string if there is a commandline, NULL | |
795 * otherwise. | |
796 */ | |
797 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
798 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
799 int firstc, |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
800 long count, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
801 int indent) // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
802 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
803 return getcmdline_int(firstc, count, indent, TRUE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
804 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
805 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
806 static char_u * |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
807 getcmdline_int( |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
808 int firstc, |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
809 long count UNUSED, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
810 int indent, // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
811 int init_ccline) // clear ccline first |
7 | 812 { |
813 int c; | |
814 int i; | |
815 int j; | |
816 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
817 int do_abbr; /* when TRUE check for abbr. */ | |
818 #ifdef FEAT_CMDHIST | |
819 char_u *lookfor = NULL; /* string to match */ | |
820 int hiscnt; /* current history line in use */ | |
821 int histype; /* history type to be used */ | |
822 #endif | |
823 #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
|
824 incsearch_state_T is_state; |
7 | 825 #endif |
826 int did_wild_list = FALSE; /* did wild_list() recently */ | |
827 int wim_index = 0; /* index in wim_flags[] */ | |
828 int res; | |
829 int save_msg_scroll = msg_scroll; | |
830 int save_State = State; /* remember State when called */ | |
831 int some_key_typed = FALSE; /* one of the keys was typed */ | |
832 #ifdef FEAT_MOUSE | |
833 /* mouse drag and release events are ignored, unless they are | |
834 * preceded with a mouse down event */ | |
835 int ignore_drag_release = TRUE; | |
836 #endif | |
837 #ifdef FEAT_EVAL | |
838 int break_ctrl_c = FALSE; | |
839 #endif | |
840 expand_T xpc; | |
841 long *b_im_ptr = NULL; | |
195 | 842 struct cmdline_info save_ccline; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
843 int did_save_ccline = FALSE; |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
844 int cmdline_type; |
7 | 845 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
846 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
847 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
848 // Being called recursively. Since ccline is global, we need to save |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
849 // the current buffer and restore it when returning. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
850 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
851 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
852 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
853 if (init_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
854 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
855 |
7 | 856 #ifdef FEAT_EVAL |
857 if (firstc == -1) | |
858 { | |
859 firstc = NUL; | |
860 break_ctrl_c = TRUE; | |
861 } | |
862 #endif | |
863 #ifdef FEAT_RIGHTLEFT | |
864 /* start without Hebrew mapping for a command line */ | |
865 if (firstc == ':' || firstc == '=' || firstc == '>') | |
866 cmd_hkmap = 0; | |
867 #endif | |
868 | |
869 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
|
870 |
7 | 871 #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
|
872 init_incsearch_state(&is_state); |
7 | 873 #endif |
874 | |
875 /* | |
876 * set some variables for redrawcmd() | |
877 */ | |
878 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 879 ccline.cmdindent = (firstc > 0 ? indent : 0); |
880 | |
881 /* alloc initial ccline.cmdbuff */ | |
882 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 883 if (ccline.cmdbuff == NULL) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
884 goto theend; // out of memory |
7 | 885 ccline.cmdlen = ccline.cmdpos = 0; |
886 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
|
887 sb_text_start_cmdline(); |
7 | 888 |
164 | 889 /* autoindent for :insert and :append */ |
890 if (firstc <= 0) | |
891 { | |
6929 | 892 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 893 ccline.cmdbuff[indent] = NUL; |
894 ccline.cmdpos = indent; | |
895 ccline.cmdspos = indent; | |
896 ccline.cmdlen = indent; | |
897 } | |
898 | |
7 | 899 ExpandInit(&xpc); |
1718 | 900 ccline.xpc = &xpc; |
7 | 901 |
902 #ifdef FEAT_RIGHTLEFT | |
903 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
904 && (firstc == '/' || firstc == '?')) | |
905 cmdmsg_rl = TRUE; | |
906 else | |
907 cmdmsg_rl = FALSE; | |
908 #endif | |
909 | |
910 redir_off = TRUE; /* don't redirect the typed command */ | |
911 if (!cmd_silent) | |
912 { | |
913 i = msg_scrolled; | |
914 msg_scrolled = 0; /* avoid wait_return message */ | |
915 gotocmdline(TRUE); | |
916 msg_scrolled += i; | |
917 redrawcmdprompt(); /* draw prompt or indent */ | |
918 set_cmdspos(); | |
919 } | |
920 xpc.xp_context = EXPAND_NOTHING; | |
921 xpc.xp_backslash = XP_BS_NONE; | |
632 | 922 #ifndef BACKSLASH_IN_FILENAME |
923 xpc.xp_shell = FALSE; | |
924 #endif | |
7 | 925 |
531 | 926 #if defined(FEAT_EVAL) |
927 if (ccline.input_fn) | |
928 { | |
929 xpc.xp_context = ccline.xp_context; | |
930 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 931 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 932 xpc.xp_arg = ccline.xp_arg; |
1322 | 933 # endif |
531 | 934 } |
935 #endif | |
936 | |
7 | 937 /* |
938 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
939 * doing ":@0" when register 0 doesn't contain a CR. | |
940 */ | |
941 msg_scroll = FALSE; | |
942 | |
943 State = CMDLINE; | |
944 | |
945 if (firstc == '/' || firstc == '?' || firstc == '@') | |
946 { | |
947 /* Use ":lmap" mappings for search pattern and input(). */ | |
948 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
949 b_im_ptr = &curbuf->b_p_iminsert; | |
950 else | |
951 b_im_ptr = &curbuf->b_p_imsearch; | |
952 if (*b_im_ptr == B_IMODE_LMAP) | |
953 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
954 #ifdef HAVE_INPUT_METHOD |
7 | 955 im_set_active(*b_im_ptr == B_IMODE_IM); |
956 #endif | |
957 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
958 #ifdef HAVE_INPUT_METHOD |
7 | 959 else if (p_imcmdline) |
960 im_set_active(TRUE); | |
961 #endif | |
962 | |
963 #ifdef FEAT_MOUSE | |
964 setmouse(); | |
965 #endif | |
966 #ifdef CURSOR_SHAPE | |
967 ui_cursor_shape(); /* may show different cursor shape */ | |
968 #endif | |
969 | |
571 | 970 /* When inside an autocommand for writing "exiting" may be set and |
971 * terminal mode set to cooked. Need to set raw mode here then. */ | |
972 settmode(TMODE_RAW); | |
973 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
974 /* 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
|
975 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
|
976 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
|
977 |
7 | 978 #ifdef FEAT_CMDHIST |
979 init_history(); | |
980 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
981 histype = hist_char2type(firstc); | |
982 #endif | |
983 | |
984 #ifdef FEAT_DIGRAPHS | |
1868 | 985 do_digraph(-1); /* init digraph typeahead */ |
7 | 986 #endif |
987 | |
5993 | 988 /* If something above caused an error, reset the flags, we do want to type |
989 * and execute commands. Display may be messed up a bit. */ | |
990 if (did_emsg) | |
991 redrawcmd(); | |
992 did_emsg = FALSE; | |
993 got_int = FALSE; | |
994 | |
7 | 995 /* |
996 * Collect the command string, handling editing keys. | |
997 */ | |
998 for (;;) | |
999 { | |
972 | 1000 redir_off = TRUE; /* Don't redirect the typed command. |
1001 Repeated, because a ":redir" inside | |
1002 completion may switch it on. */ | |
7 | 1003 #ifdef USE_ON_FLY_SCROLL |
1004 dont_scroll = FALSE; /* allow scrolling here */ | |
1005 #endif | |
1006 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
1007 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
1008 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
|
1009 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
|
1010 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
|
1011 |
7 | 1012 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 1013 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
1014 /* 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
|
1015 * anything, such as stop completion. */ |
1472 | 1016 do |
1017 { | |
1018 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
|
1019 } while (c == K_IGNORE || c == K_NOP); |
1472 | 1020 |
7 | 1021 if (KeyTyped) |
1022 { | |
1023 some_key_typed = TRUE; | |
1024 #ifdef FEAT_RIGHTLEFT | |
1025 if (cmd_hkmap) | |
1026 c = hkmap(c); | |
1027 # ifdef FEAT_FKMAP | |
1028 if (cmd_fkmap) | |
1029 c = cmdl_fkmap(c); | |
1030 # endif | |
1031 if (cmdmsg_rl && !KeyStuffed) | |
1032 { | |
1033 /* Invert horizontal movements and operations. Only when | |
1034 * typed by the user directly, not when the result of a | |
1035 * mapping. */ | |
1036 switch (c) | |
1037 { | |
1038 case K_RIGHT: c = K_LEFT; break; | |
1039 case K_S_RIGHT: c = K_S_LEFT; break; | |
1040 case K_C_RIGHT: c = K_C_LEFT; break; | |
1041 case K_LEFT: c = K_RIGHT; break; | |
1042 case K_S_LEFT: c = K_S_RIGHT; break; | |
1043 case K_C_LEFT: c = K_C_RIGHT; break; | |
1044 } | |
1045 } | |
1046 #endif | |
1047 } | |
1048 | |
1049 /* | |
1050 * Ignore got_int when CTRL-C was typed here. | |
1051 * Don't ignore it in :global, we really need to break then, e.g., for | |
1052 * ":g/pat/normal /pat" (without the <CR>). | |
1053 * Don't ignore it for the input() function. | |
1054 */ | |
1055 if ((c == Ctrl_C | |
1056 #ifdef UNIX | |
1057 || c == intr_char | |
1058 #endif | |
1059 ) | |
1060 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1061 && firstc != '@' | |
1062 #endif | |
1063 #ifdef FEAT_EVAL | |
1064 && !break_ctrl_c | |
1065 #endif | |
1066 && !global_busy) | |
1067 got_int = FALSE; | |
1068 | |
1069 #ifdef FEAT_CMDHIST | |
1070 /* free old command line when finished moving around in the history | |
1071 * list */ | |
1072 if (lookfor != NULL | |
180 | 1073 && c != K_S_DOWN && c != K_S_UP |
230 | 1074 && c != K_DOWN && c != K_UP |
7 | 1075 && c != K_PAGEDOWN && c != K_PAGEUP |
1076 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1077 && c != K_LEFT && c != K_RIGHT |
7 | 1078 && (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
|
1079 VIM_CLEAR(lookfor); |
7 | 1080 #endif |
1081 | |
1082 /* | |
1718 | 1083 * When there are matching completions to select <S-Tab> works like |
1084 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1085 */ |
1718 | 1086 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1087 c = Ctrl_P; |
1088 | |
1089 #ifdef FEAT_WILDMENU | |
1090 /* Special translations for 'wildmenu' */ | |
1091 if (did_wild_list && p_wmnu) | |
1092 { | |
230 | 1093 if (c == K_LEFT) |
7 | 1094 c = Ctrl_P; |
230 | 1095 else if (c == K_RIGHT) |
7 | 1096 c = Ctrl_N; |
1097 } | |
1098 /* Hitting CR after "emenu Name.": complete submenu */ | |
1099 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1100 && ccline.cmdpos > 1 | |
1101 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1102 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1103 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1104 c = K_DOWN; | |
1105 #endif | |
1106 | |
1107 /* free expanded names when finished walking through matches */ | |
1108 if (xpc.xp_numfiles != -1 | |
1109 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1110 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1111 && c != Ctrl_L) | |
1112 { | |
1113 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1114 did_wild_list = FALSE; | |
1115 #ifdef FEAT_WILDMENU | |
230 | 1116 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1117 #endif |
1118 xpc.xp_context = EXPAND_NOTHING; | |
1119 wim_index = 0; | |
1120 #ifdef FEAT_WILDMENU | |
1121 if (p_wmnu && wild_menu_showing != 0) | |
1122 { | |
1123 int skt = KeyTyped; | |
532 | 1124 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1125 |
1126 if (ccline.input_fn) | |
1127 RedrawingDisabled = 0; | |
7 | 1128 |
1129 if (wild_menu_showing == WM_SCROLLED) | |
1130 { | |
1131 /* Entered command line, move it up */ | |
1132 cmdline_row--; | |
1133 redrawcmd(); | |
1134 } | |
1135 else if (save_p_ls != -1) | |
1136 { | |
1137 /* restore 'laststatus' and 'winminheight' */ | |
1138 p_ls = save_p_ls; | |
1139 p_wmh = save_p_wmh; | |
1140 last_status(FALSE); | |
1141 update_screen(VALID); /* redraw the screen NOW */ | |
1142 redrawcmd(); | |
1143 save_p_ls = -1; | |
1144 } | |
1145 else | |
1146 { | |
1147 win_redraw_last_status(topframe); | |
1148 redraw_statuslines(); | |
1149 } | |
532 | 1150 KeyTyped = skt; |
1151 wild_menu_showing = 0; | |
531 | 1152 if (ccline.input_fn) |
1153 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1154 } |
1155 #endif | |
1156 } | |
1157 | |
1158 #ifdef FEAT_WILDMENU | |
1159 /* Special translations for 'wildmenu' */ | |
1160 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1161 { | |
1162 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1163 if (c == K_DOWN && ccline.cmdpos > 0 |
1164 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1165 c = p_wc; |
230 | 1166 else if (c == K_UP) |
7 | 1167 { |
1168 /* Hitting <Up>: Remove one submenu name in front of the | |
1169 * cursor */ | |
1170 int found = FALSE; | |
1171 | |
1172 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1173 i = 0; | |
1174 while (--j > 0) | |
1175 { | |
1176 /* check for start of menu name */ | |
1177 if (ccline.cmdbuff[j] == ' ' | |
1178 && ccline.cmdbuff[j - 1] != '\\') | |
1179 { | |
1180 i = j + 1; | |
1181 break; | |
1182 } | |
1183 /* check for start of submenu name */ | |
1184 if (ccline.cmdbuff[j] == '.' | |
1185 && ccline.cmdbuff[j - 1] != '\\') | |
1186 { | |
1187 if (found) | |
1188 { | |
1189 i = j + 1; | |
1190 break; | |
1191 } | |
1192 else | |
1193 found = TRUE; | |
1194 } | |
1195 } | |
1196 if (i > 0) | |
1197 cmdline_del(i); | |
1198 c = p_wc; | |
1199 xpc.xp_context = EXPAND_NOTHING; | |
1200 } | |
1201 } | |
714 | 1202 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1203 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1204 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1205 { |
1206 char_u upseg[5]; | |
1207 | |
1208 upseg[0] = PATHSEP; | |
1209 upseg[1] = '.'; | |
1210 upseg[2] = '.'; | |
1211 upseg[3] = PATHSEP; | |
1212 upseg[4] = NUL; | |
1213 | |
1318 | 1214 if (c == K_DOWN |
1215 && ccline.cmdpos > 0 | |
1216 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1217 && (ccline.cmdpos < 3 | |
1218 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1219 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1220 { | |
1221 /* go down a directory */ | |
1222 c = p_wc; | |
1223 } | |
230 | 1224 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1225 { |
1226 /* If in a direct ancestor, strip off one ../ to go down */ | |
1227 int found = FALSE; | |
1228 | |
1229 j = ccline.cmdpos; | |
1230 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1231 while (--j > i) | |
1232 { | |
39 | 1233 #ifdef FEAT_MBYTE |
1234 if (has_mbyte) | |
1235 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1236 #endif | |
7 | 1237 if (vim_ispathsep(ccline.cmdbuff[j])) |
1238 { | |
1239 found = TRUE; | |
1240 break; | |
1241 } | |
1242 } | |
1243 if (found | |
1244 && ccline.cmdbuff[j - 1] == '.' | |
1245 && ccline.cmdbuff[j - 2] == '.' | |
1246 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1247 { | |
1248 cmdline_del(j - 2); | |
1249 c = p_wc; | |
1250 } | |
1251 } | |
230 | 1252 else if (c == K_UP) |
7 | 1253 { |
1254 /* go up a directory */ | |
1255 int found = FALSE; | |
1256 | |
1257 j = ccline.cmdpos - 1; | |
1258 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1259 while (--j > i) | |
1260 { | |
1261 #ifdef FEAT_MBYTE | |
1262 if (has_mbyte) | |
1263 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1264 #endif | |
1265 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1266 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1267 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1268 ccline.cmdbuff[j + 1]) == NULL |
7 | 1269 #endif |
1270 ) | |
1271 { | |
1272 if (found) | |
1273 { | |
1274 i = j + 1; | |
1275 break; | |
1276 } | |
1277 else | |
1278 found = TRUE; | |
1279 } | |
1280 } | |
1281 | |
1282 if (!found) | |
1283 j = i; | |
1284 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1285 j += 4; | |
1286 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1287 && j == i) | |
1288 j += 3; | |
1289 else | |
1290 j = 0; | |
1291 if (j > 0) | |
1292 { | |
1293 /* TODO this is only for DOS/UNIX systems - need to put in | |
1294 * machine-specific stuff here and in upseg init */ | |
1295 cmdline_del(j); | |
1296 put_on_cmdline(upseg + 1, 3, FALSE); | |
1297 } | |
1298 else if (ccline.cmdpos > i) | |
1299 cmdline_del(i); | |
3204 | 1300 |
1301 /* Now complete in the new directory. Set KeyTyped in case the | |
1302 * Up key came from a mapping. */ | |
7 | 1303 c = p_wc; |
3204 | 1304 KeyTyped = TRUE; |
7 | 1305 } |
1306 } | |
1307 | |
1308 #endif /* FEAT_WILDMENU */ | |
1309 | |
1310 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1311 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1312 if (c == Ctrl_BSL) | |
1313 { | |
1314 ++no_mapping; | |
1315 ++allow_keys; | |
1389 | 1316 c = plain_vgetc(); |
7 | 1317 --no_mapping; |
1318 --allow_keys; | |
3859 | 1319 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1320 * is in a mapping. */ | |
1321 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1322 || (ccline.cmdfirstc == '=' && KeyTyped) |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1323 #ifdef FEAT_EVAL |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1324 || cmdline_star > 0 |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1325 #endif |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1326 )) |
7 | 1327 { |
1328 vungetc(c); | |
1329 c = Ctrl_BSL; | |
1330 } | |
1331 #ifdef FEAT_EVAL | |
1332 else if (c == 'e') | |
1333 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1334 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1335 int len; |
7 | 1336 |
1337 /* | |
1338 * Replace the command line with the result of an expression. | |
625 | 1339 * Need to save and restore the current command line, to be |
1340 * able to enter a new one... | |
7 | 1341 */ |
1342 if (ccline.cmdpos == ccline.cmdlen) | |
1343 new_cmdpos = 99999; /* keep it at the end */ | |
1344 else | |
1345 new_cmdpos = ccline.cmdpos; | |
95 | 1346 |
7 | 1347 c = get_expr_register(); |
1348 if (c == '=') | |
1349 { | |
634 | 1350 /* Need to save and restore ccline. And set "textlock" |
632 | 1351 * to avoid nasty things like going to another buffer when |
1352 * evaluating an expression. */ | |
634 | 1353 ++textlock; |
7 | 1354 p = get_expr_line(); |
634 | 1355 --textlock; |
2617 | 1356 |
1357 if (p != NULL) | |
7 | 1358 { |
2617 | 1359 len = (int)STRLEN(p); |
1360 if (realloc_cmdbuff(len + 1) == OK) | |
1361 { | |
1362 ccline.cmdlen = len; | |
1363 STRCPY(ccline.cmdbuff, p); | |
1364 vim_free(p); | |
1365 | |
1366 /* Restore the cursor or use the position set with | |
1367 * set_cmdline_pos(). */ | |
1368 if (new_cmdpos > ccline.cmdlen) | |
1369 ccline.cmdpos = ccline.cmdlen; | |
1370 else | |
1371 ccline.cmdpos = new_cmdpos; | |
1372 | |
1373 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1374 redrawcmd(); | |
1375 goto cmdline_changed; | |
1376 } | |
7 | 1377 } |
1378 } | |
1379 beep_flush(); | |
2636 | 1380 got_int = FALSE; /* don't abandon the command line */ |
1381 did_emsg = FALSE; | |
1382 emsg_on_display = FALSE; | |
1383 redrawcmd(); | |
1384 goto cmdline_not_changed; | |
7 | 1385 } |
1386 #endif | |
1387 else | |
1388 { | |
1389 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1390 restart_edit = 'a'; | |
1391 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1392 in history */ | |
1393 goto returncmd; /* back to Normal mode */ | |
1394 } | |
1395 } | |
1396 | |
1397 #ifdef FEAT_CMDWIN | |
1398 if (c == cedit_key || c == K_CMDWIN) | |
1399 { | |
6211 | 1400 if (ex_normal_busy == 0 && got_int == FALSE) |
1401 { | |
1402 /* | |
1403 * Open a window to edit the command line (and history). | |
1404 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1405 c = open_cmdwin(); |
6211 | 1406 some_key_typed = TRUE; |
1407 } | |
7 | 1408 } |
1409 # ifdef FEAT_DIGRAPHS | |
1410 else | |
1411 # endif | |
1412 #endif | |
1413 #ifdef FEAT_DIGRAPHS | |
1414 c = do_digraph(c); | |
1415 #endif | |
1416 | |
1417 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1418 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1419 { | |
168 | 1420 /* In Ex mode a backslash escapes a newline. */ |
1421 if (exmode_active | |
1422 && c != ESC | |
1318 | 1423 && ccline.cmdpos == ccline.cmdlen |
168 | 1424 && ccline.cmdpos > 0 |
1425 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1426 { | |
1427 if (c == K_KENTER) | |
1428 c = '\n'; | |
1429 } | |
1430 else | |
7 | 1431 { |
168 | 1432 gotesc = FALSE; /* Might have typed ESC previously, don't |
1433 truncate the cmdline now. */ | |
1434 if (ccheck_abbr(c + ABBR_OFF)) | |
1435 goto cmdline_changed; | |
1436 if (!cmd_silent) | |
1437 { | |
1438 windgoto(msg_row, 0); | |
1439 out_flush(); | |
1440 } | |
1441 break; | |
7 | 1442 } |
1443 } | |
1444 | |
1445 /* | |
1446 * Completion for 'wildchar' or 'wildcharm' key. | |
1447 * - hitting <ESC> twice means: abandon command line. | |
1448 * - wildcard expansion is only done when the 'wildchar' key is really | |
1449 * typed, not when it comes from a macro | |
1450 */ | |
1451 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1452 { | |
1453 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1454 { | |
1455 /* if 'wildmode' contains "list" may still need to list */ | |
1456 if (xpc.xp_numfiles > 1 | |
1457 && !did_wild_list | |
1458 && (wim_flags[wim_index] & WIM_LIST)) | |
1459 { | |
1460 (void)showmatches(&xpc, FALSE); | |
1461 redrawcmd(); | |
1462 did_wild_list = TRUE; | |
1463 } | |
1464 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1465 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1466 firstc != '@'); | |
7 | 1467 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1468 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1469 firstc != '@'); | |
7 | 1470 else |
1471 res = OK; /* don't insert 'wildchar' now */ | |
1472 } | |
1473 else /* typed p_wc first time */ | |
1474 { | |
1475 wim_index = 0; | |
1476 j = ccline.cmdpos; | |
1477 /* if 'wildmode' first contains "longest", get longest | |
1478 * common part */ | |
1479 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1480 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1481 firstc != '@'); | |
7 | 1482 else |
3961 | 1483 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1484 firstc != '@'); | |
7 | 1485 |
1486 /* if interrupted while completing, behave like it failed */ | |
1487 if (got_int) | |
1488 { | |
1489 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1490 got_int = FALSE; /* don't abandon the command line */ | |
1491 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1492 #ifdef FEAT_WILDMENU | |
1493 xpc.xp_context = EXPAND_NOTHING; | |
1494 #endif | |
1495 goto cmdline_changed; | |
1496 } | |
1497 | |
1498 /* when more than one match, and 'wildmode' first contains | |
1499 * "list", or no change and 'wildmode' contains "longest,list", | |
1500 * list all matches */ | |
1501 if (res == OK && xpc.xp_numfiles > 1) | |
1502 { | |
1503 /* a "longest" that didn't do anything is skipped (but not | |
1504 * "list:longest") */ | |
1505 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1506 wim_index = 1; | |
1507 if ((wim_flags[wim_index] & WIM_LIST) | |
1508 #ifdef FEAT_WILDMENU | |
1509 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1510 #endif | |
1511 ) | |
1512 { | |
1513 if (!(wim_flags[0] & WIM_LONGEST)) | |
1514 { | |
1515 #ifdef FEAT_WILDMENU | |
1516 int p_wmnu_save = p_wmnu; | |
1517 p_wmnu = 0; | |
1518 #endif | |
3961 | 1519 /* remove match */ |
1520 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1521 #ifdef FEAT_WILDMENU |
1522 p_wmnu = p_wmnu_save; | |
1523 #endif | |
1524 } | |
1525 #ifdef FEAT_WILDMENU | |
1526 (void)showmatches(&xpc, p_wmnu | |
1527 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1528 #else | |
1529 (void)showmatches(&xpc, FALSE); | |
1530 #endif | |
1531 redrawcmd(); | |
1532 did_wild_list = TRUE; | |
1533 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1534 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1535 firstc != '@'); | |
7 | 1536 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1537 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1538 firstc != '@'); | |
7 | 1539 } |
1540 else | |
6949 | 1541 vim_beep(BO_WILD); |
7 | 1542 } |
1543 #ifdef FEAT_WILDMENU | |
1544 else if (xpc.xp_numfiles == -1) | |
1545 xpc.xp_context = EXPAND_NOTHING; | |
1546 #endif | |
1547 } | |
1548 if (wim_index < 3) | |
1549 ++wim_index; | |
1550 if (c == ESC) | |
1551 gotesc = TRUE; | |
1552 if (res == OK) | |
1553 goto cmdline_changed; | |
1554 } | |
1555 | |
1556 gotesc = FALSE; | |
1557 | |
1558 /* <S-Tab> goes to last match, in a clumsy way */ | |
1559 if (c == K_S_TAB && KeyTyped) | |
1560 { | |
3961 | 1561 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1562 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1563 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1564 goto cmdline_changed; |
1565 } | |
1566 | |
1567 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1568 c = NL; | |
1569 | |
1570 do_abbr = TRUE; /* default: check for abbreviation */ | |
1571 | |
1572 /* | |
1573 * Big switch for a typed command line character. | |
1574 */ | |
1575 switch (c) | |
1576 { | |
1577 case K_BS: | |
1578 case Ctrl_H: | |
1579 case K_DEL: | |
1580 case K_KDEL: | |
1581 case Ctrl_W: | |
1582 #ifdef FEAT_FKMAP | |
1583 if (cmd_fkmap && c == K_BS) | |
1584 c = K_DEL; | |
1585 #endif | |
1586 if (c == K_KDEL) | |
1587 c = K_DEL; | |
1588 | |
1589 /* | |
1590 * delete current character is the same as backspace on next | |
1591 * character, except at end of line | |
1592 */ | |
1593 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1594 ++ccline.cmdpos; | |
1595 #ifdef FEAT_MBYTE | |
1596 if (has_mbyte && c == K_DEL) | |
1597 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1598 ccline.cmdbuff + ccline.cmdpos); | |
1599 #endif | |
1600 if (ccline.cmdpos > 0) | |
1601 { | |
1602 char_u *p; | |
1603 | |
1604 j = ccline.cmdpos; | |
1605 p = ccline.cmdbuff + j; | |
1606 #ifdef FEAT_MBYTE | |
1607 if (has_mbyte) | |
1608 { | |
1609 p = mb_prevptr(ccline.cmdbuff, p); | |
1610 if (c == Ctrl_W) | |
1611 { | |
1612 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1613 p = mb_prevptr(ccline.cmdbuff, p); | |
1614 i = mb_get_class(p); | |
1615 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1616 p = mb_prevptr(ccline.cmdbuff, p); | |
1617 if (mb_get_class(p) != i) | |
474 | 1618 p += (*mb_ptr2len)(p); |
7 | 1619 } |
1620 } | |
1621 else | |
1622 #endif | |
1623 if (c == Ctrl_W) | |
1624 { | |
1625 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1626 --p; | |
1627 i = vim_iswordc(p[-1]); | |
1628 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1629 && vim_iswordc(p[-1]) == i) | |
1630 --p; | |
1631 } | |
1632 else | |
1633 --p; | |
1634 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1635 ccline.cmdlen -= j - ccline.cmdpos; | |
1636 i = ccline.cmdpos; | |
1637 while (i < ccline.cmdlen) | |
1638 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1639 | |
1640 /* Truncate at the end, required for multi-byte chars. */ | |
1641 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1642 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1643 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1644 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1645 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
|
1646 /* 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
|
1647 * 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
|
1648 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
|
1649 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1650 #endif |
7 | 1651 redrawcmd(); |
1652 } | |
1653 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1654 && ccline.cmdprompt == NULL && indent == 0) | |
1655 { | |
1656 /* In ex and debug mode it doesn't make sense to return. */ | |
1657 if (exmode_active | |
1658 #ifdef FEAT_EVAL | |
1659 || ccline.cmdfirstc == '>' | |
1660 #endif | |
1661 ) | |
1662 goto cmdline_not_changed; | |
1663 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1664 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1665 if (!cmd_silent) |
1666 { | |
1667 #ifdef FEAT_RIGHTLEFT | |
1668 if (cmdmsg_rl) | |
1669 msg_col = Columns; | |
1670 else | |
1671 #endif | |
1672 msg_col = 0; | |
1673 msg_putchar(' '); /* delete ':' */ | |
1674 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1675 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1676 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
|
1677 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
|
1678 #endif |
7 | 1679 redraw_cmdline = TRUE; |
1680 goto returncmd; /* back to cmd mode */ | |
1681 } | |
1682 goto cmdline_changed; | |
1683 | |
1684 case K_INS: | |
1685 case K_KINS: | |
1686 #ifdef FEAT_FKMAP | |
1687 /* if Farsi mode set, we are in reverse insert mode - | |
1688 Do not change the mode */ | |
1689 if (cmd_fkmap) | |
1690 beep_flush(); | |
1691 else | |
1692 #endif | |
1693 ccline.overstrike = !ccline.overstrike; | |
1694 #ifdef CURSOR_SHAPE | |
1695 ui_cursor_shape(); /* may show different cursor shape */ | |
1696 #endif | |
1697 goto cmdline_not_changed; | |
1698 | |
1699 case Ctrl_HAT: | |
782 | 1700 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1701 { |
1702 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1703 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1704 #ifdef HAVE_INPUT_METHOD |
7 | 1705 im_set_active(FALSE); /* Disable input method */ |
1706 #endif | |
1707 if (b_im_ptr != NULL) | |
1708 { | |
1709 if (State & LANGMAP) | |
1710 *b_im_ptr = B_IMODE_LMAP; | |
1711 else | |
1712 *b_im_ptr = B_IMODE_NONE; | |
1713 } | |
1714 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1715 #ifdef HAVE_INPUT_METHOD |
7 | 1716 else |
1717 { | |
1718 /* There are no ":lmap" mappings, toggle IM. When | |
1719 * 'imdisable' is set don't try getting the status, it's | |
1720 * always off. */ | |
1721 if ((p_imdisable && b_im_ptr != NULL) | |
1722 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1723 { | |
1724 im_set_active(FALSE); /* Disable input method */ | |
1725 if (b_im_ptr != NULL) | |
1726 *b_im_ptr = B_IMODE_NONE; | |
1727 } | |
1728 else | |
1729 { | |
1730 im_set_active(TRUE); /* Enable input method */ | |
1731 if (b_im_ptr != NULL) | |
1732 *b_im_ptr = B_IMODE_IM; | |
1733 } | |
1734 } | |
1735 #endif | |
1736 if (b_im_ptr != NULL) | |
1737 { | |
1738 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1739 set_iminsert_global(); | |
1740 else | |
1741 set_imsearch_global(); | |
1742 } | |
1743 #ifdef CURSOR_SHAPE | |
1744 ui_cursor_shape(); /* may show different cursor shape */ | |
1745 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1746 #if defined(FEAT_KEYMAP) |
7 | 1747 /* Show/unshow value of 'keymap' in status lines later. */ |
1748 status_redraw_curbuf(); | |
1749 #endif | |
1750 goto cmdline_not_changed; | |
1751 | |
1752 /* case '@': only in very old vi */ | |
1753 case Ctrl_U: | |
1754 /* delete all characters left of the cursor */ | |
1755 j = ccline.cmdpos; | |
1756 ccline.cmdlen -= j; | |
1757 i = ccline.cmdpos = 0; | |
1758 while (i < ccline.cmdlen) | |
1759 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1760 /* Truncate at the end, required for multi-byte chars. */ | |
1761 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1762 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1763 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
|
1764 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
|
1765 #endif |
7 | 1766 redrawcmd(); |
1767 goto cmdline_changed; | |
1768 | |
1769 #ifdef FEAT_CLIPBOARD | |
1770 case Ctrl_Y: | |
1771 /* Copy the modeless selection, if there is one. */ | |
1772 if (clip_star.state != SELECT_CLEARED) | |
1773 { | |
1774 if (clip_star.state == SELECT_DONE) | |
1775 clip_copy_modeless_selection(TRUE); | |
1776 goto cmdline_not_changed; | |
1777 } | |
1778 break; | |
1779 #endif | |
1780 | |
1781 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1782 case Ctrl_C: | |
571 | 1783 /* In exmode it doesn't make sense to return. Except when |
161 | 1784 * ":normal" runs out of characters. */ |
1785 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1786 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1787 goto cmdline_not_changed; |
1788 | |
1789 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1790 putting it in history */ | |
1791 goto returncmd; /* back to cmd mode */ | |
1792 | |
1793 case Ctrl_R: /* insert register */ | |
1794 #ifdef USE_ON_FLY_SCROLL | |
1795 dont_scroll = TRUE; /* disallow scrolling here */ | |
1796 #endif | |
1797 putcmdline('"', TRUE); | |
1798 ++no_mapping; | |
1389 | 1799 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1800 if (i == Ctrl_O) |
1801 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1802 if (i == Ctrl_R) | |
1389 | 1803 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
|
1804 extra_char = NUL; |
7 | 1805 --no_mapping; |
1806 #ifdef FEAT_EVAL | |
1807 /* | |
1808 * Insert the result of an expression. | |
1809 * Need to save the current command line, to be able to enter | |
1810 * a new one... | |
1811 */ | |
1812 new_cmdpos = -1; | |
1813 if (c == '=') | |
1814 { | |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1815 if (ccline.cmdfirstc == '=' // can't do this recursively |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1816 || cmdline_star > 0) // or when typing a password |
7 | 1817 { |
1818 beep_flush(); | |
1819 c = ESC; | |
1820 } | |
1821 else | |
1822 c = get_expr_register(); | |
1823 } | |
1824 #endif | |
1825 if (c != ESC) /* use ESC to cancel inserting register */ | |
1826 { | |
1015 | 1827 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1828 |
613 | 1829 #ifdef FEAT_EVAL |
606 | 1830 /* When there was a serious error abort getting the |
1831 * command line. */ | |
1832 if (aborting()) | |
1833 { | |
1834 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1835 putting it in history */ | |
1836 goto returncmd; /* back to cmd mode */ | |
1837 } | |
613 | 1838 #endif |
7 | 1839 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1840 #ifdef FEAT_EVAL | |
1841 if (new_cmdpos >= 0) | |
1842 { | |
1843 /* set_cmdline_pos() was used */ | |
1844 if (new_cmdpos > ccline.cmdlen) | |
1845 ccline.cmdpos = ccline.cmdlen; | |
1846 else | |
1847 ccline.cmdpos = new_cmdpos; | |
1848 } | |
1849 #endif | |
1850 } | |
1851 redrawcmd(); | |
1852 goto cmdline_changed; | |
1853 | |
1854 case Ctrl_D: | |
1855 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1856 break; /* Use ^D as normal char instead */ | |
1857 | |
1858 redrawcmd(); | |
1859 continue; /* don't do incremental search now */ | |
1860 | |
1861 case K_RIGHT: | |
1862 case K_S_RIGHT: | |
1863 case K_C_RIGHT: | |
1864 do | |
1865 { | |
1866 if (ccline.cmdpos >= ccline.cmdlen) | |
1867 break; | |
1868 i = cmdline_charsize(ccline.cmdpos); | |
1869 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1870 break; | |
1871 ccline.cmdspos += i; | |
1872 #ifdef FEAT_MBYTE | |
1873 if (has_mbyte) | |
474 | 1874 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1875 + ccline.cmdpos); |
1876 else | |
1877 #endif | |
1878 ++ccline.cmdpos; | |
1879 } | |
180 | 1880 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1881 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1882 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1883 #ifdef FEAT_MBYTE | |
1884 if (has_mbyte) | |
1885 set_cmdspos_cursor(); | |
1886 #endif | |
1887 goto cmdline_not_changed; | |
1888 | |
1889 case K_LEFT: | |
1890 case K_S_LEFT: | |
1891 case K_C_LEFT: | |
1456 | 1892 if (ccline.cmdpos == 0) |
1893 goto cmdline_not_changed; | |
7 | 1894 do |
1895 { | |
1896 --ccline.cmdpos; | |
1897 #ifdef FEAT_MBYTE | |
1898 if (has_mbyte) /* move to first byte of char */ | |
1899 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1900 ccline.cmdbuff + ccline.cmdpos); | |
1901 #endif | |
1902 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1903 } | |
1456 | 1904 while (ccline.cmdpos > 0 |
1905 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1906 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1907 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1908 #ifdef FEAT_MBYTE | |
1909 if (has_mbyte) | |
1910 set_cmdspos_cursor(); | |
1911 #endif | |
1912 goto cmdline_not_changed; | |
1913 | |
1914 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
|
1915 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1916 goto cmdline_not_changed; |
7 | 1917 |
625 | 1918 #ifdef FEAT_GUI_W32 |
1919 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1920 * cancelled. */ | |
1921 case K_F4: | |
1922 if (mod_mask == MOD_MASK_ALT) | |
1923 { | |
1924 redrawcmd(); /* somehow the cmdline is cleared */ | |
1925 goto cmdline_not_changed; | |
1926 } | |
1927 break; | |
1928 #endif | |
1929 | |
7 | 1930 #ifdef FEAT_MOUSE |
1931 case K_MIDDLEDRAG: | |
1932 case K_MIDDLERELEASE: | |
1933 goto cmdline_not_changed; /* Ignore mouse */ | |
1934 | |
1935 case K_MIDDLEMOUSE: | |
1936 # ifdef FEAT_GUI | |
1937 /* When GUI is active, also paste when 'mouse' is empty */ | |
1938 if (!gui.in_use) | |
1939 # endif | |
1940 if (!mouse_has(MOUSE_COMMAND)) | |
1941 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1942 # ifdef FEAT_CLIPBOARD |
7 | 1943 if (clip_star.available) |
1015 | 1944 cmdline_paste('*', TRUE, TRUE); |
7 | 1945 else |
692 | 1946 # endif |
1015 | 1947 cmdline_paste(0, TRUE, TRUE); |
7 | 1948 redrawcmd(); |
1949 goto cmdline_changed; | |
1950 | |
692 | 1951 # ifdef FEAT_DND |
7 | 1952 case K_DROP: |
1015 | 1953 cmdline_paste('~', TRUE, FALSE); |
7 | 1954 redrawcmd(); |
1955 goto cmdline_changed; | |
692 | 1956 # endif |
7 | 1957 |
1958 case K_LEFTDRAG: | |
1959 case K_LEFTRELEASE: | |
1960 case K_RIGHTDRAG: | |
1961 case K_RIGHTRELEASE: | |
1962 /* Ignore drag and release events when the button-down wasn't | |
1963 * seen before. */ | |
1964 if (ignore_drag_release) | |
1965 goto cmdline_not_changed; | |
1966 /* FALLTHROUGH */ | |
1967 case K_LEFTMOUSE: | |
1968 case K_RIGHTMOUSE: | |
1969 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1970 ignore_drag_release = TRUE; | |
1971 else | |
1972 ignore_drag_release = FALSE; | |
1973 # ifdef FEAT_GUI | |
1974 /* When GUI is active, also move when 'mouse' is empty */ | |
1975 if (!gui.in_use) | |
1976 # endif | |
1977 if (!mouse_has(MOUSE_COMMAND)) | |
1978 goto cmdline_not_changed; /* Ignore mouse */ | |
1979 # ifdef FEAT_CLIPBOARD | |
1980 if (mouse_row < cmdline_row && clip_star.available) | |
1981 { | |
1982 int button, is_click, is_drag; | |
1983 | |
1984 /* | |
1985 * Handle modeless selection. | |
1986 */ | |
1987 button = get_mouse_button(KEY2TERMCAP1(c), | |
1988 &is_click, &is_drag); | |
1989 if (mouse_model_popup() && button == MOUSE_LEFT | |
1990 && (mod_mask & MOD_MASK_SHIFT)) | |
1991 { | |
1992 /* Translate shift-left to right button. */ | |
1993 button = MOUSE_RIGHT; | |
1994 mod_mask &= ~MOD_MASK_SHIFT; | |
1995 } | |
1996 clip_modeless(button, is_click, is_drag); | |
1997 goto cmdline_not_changed; | |
1998 } | |
1999 # endif | |
2000 | |
2001 set_cmdspos(); | |
2002 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
2003 ++ccline.cmdpos) | |
2004 { | |
2005 i = cmdline_charsize(ccline.cmdpos); | |
2006 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
2007 && mouse_col < ccline.cmdspos % Columns + i) | |
2008 break; | |
692 | 2009 # ifdef FEAT_MBYTE |
7 | 2010 if (has_mbyte) |
2011 { | |
2012 /* Count ">" for double-wide char that doesn't fit. */ | |
2013 correct_cmdspos(ccline.cmdpos, i); | |
474 | 2014 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 2015 + ccline.cmdpos) - 1; |
2016 } | |
692 | 2017 # endif |
7 | 2018 ccline.cmdspos += i; |
2019 } | |
2020 goto cmdline_not_changed; | |
2021 | |
2022 /* Mouse scroll wheel: ignored here */ | |
2023 case K_MOUSEDOWN: | |
2024 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2025 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2026 case K_MOUSERIGHT: |
7 | 2027 /* Alternate buttons ignored here */ |
2028 case K_X1MOUSE: | |
2029 case K_X1DRAG: | |
2030 case K_X1RELEASE: | |
2031 case K_X2MOUSE: | |
2032 case K_X2DRAG: | |
2033 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2034 case K_MOUSEMOVE: |
7 | 2035 goto cmdline_not_changed; |
2036 | |
2037 #endif /* FEAT_MOUSE */ | |
2038 | |
2039 #ifdef FEAT_GUI | |
2040 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2041 case K_LEFTRELEASE_NM: | |
2042 goto cmdline_not_changed; | |
2043 | |
2044 case K_VER_SCROLLBAR: | |
540 | 2045 if (msg_scrolled == 0) |
7 | 2046 { |
2047 gui_do_scroll(); | |
2048 redrawcmd(); | |
2049 } | |
2050 goto cmdline_not_changed; | |
2051 | |
2052 case K_HOR_SCROLLBAR: | |
540 | 2053 if (msg_scrolled == 0) |
7 | 2054 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2055 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2056 redrawcmd(); |
2057 } | |
2058 goto cmdline_not_changed; | |
2059 #endif | |
692 | 2060 #ifdef FEAT_GUI_TABLINE |
2061 case K_TABLINE: | |
2062 case K_TABMENU: | |
2063 /* Don't want to change any tabs here. Make sure the same tab | |
2064 * is still selected. */ | |
2065 if (gui_use_tabline()) | |
2066 gui_mch_set_curtab(tabpage_index(curtab)); | |
2067 goto cmdline_not_changed; | |
2068 #endif | |
2069 | |
7 | 2070 case K_SELECT: /* end of Select mode mapping - ignore */ |
2071 goto cmdline_not_changed; | |
2072 | |
2073 case Ctrl_B: /* begin of command line */ | |
2074 case K_HOME: | |
2075 case K_KHOME: | |
2076 case K_S_HOME: | |
2077 case K_C_HOME: | |
2078 ccline.cmdpos = 0; | |
2079 set_cmdspos(); | |
2080 goto cmdline_not_changed; | |
2081 | |
2082 case Ctrl_E: /* end of command line */ | |
2083 case K_END: | |
2084 case K_KEND: | |
2085 case K_S_END: | |
2086 case K_C_END: | |
2087 ccline.cmdpos = ccline.cmdlen; | |
2088 set_cmdspos_cursor(); | |
2089 goto cmdline_not_changed; | |
2090 | |
2091 case Ctrl_A: /* all matches */ | |
3961 | 2092 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2093 break; |
2094 goto cmdline_changed; | |
2095 | |
772 | 2096 case Ctrl_L: |
2097 #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
|
2098 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2099 goto cmdline_not_changed; |
2100 #endif | |
2101 | |
2102 /* completion: longest common part */ | |
3961 | 2103 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2104 break; |
2105 goto cmdline_changed; | |
2106 | |
2107 case Ctrl_N: /* next match */ | |
2108 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2109 if (xpc.xp_numfiles > 0) |
7 | 2110 { |
3961 | 2111 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2112 0, firstc != '@') == FAIL) | |
7 | 2113 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2114 goto cmdline_not_changed; |
7 | 2115 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2116 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2117 /* FALLTHROUGH */ |
7 | 2118 case K_UP: |
2119 case K_DOWN: | |
2120 case K_S_UP: | |
2121 case K_S_DOWN: | |
2122 case K_PAGEUP: | |
2123 case K_KPAGEUP: | |
2124 case K_PAGEDOWN: | |
2125 case K_KPAGEDOWN: | |
2126 if (hislen == 0 || firstc == NUL) /* no history */ | |
2127 goto cmdline_not_changed; | |
2128 | |
2129 i = hiscnt; | |
2130 | |
2131 /* save current command string so it can be restored later */ | |
2132 if (lookfor == NULL) | |
2133 { | |
2134 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2135 goto cmdline_not_changed; | |
2136 lookfor[ccline.cmdpos] = NUL; | |
2137 } | |
2138 | |
2139 j = (int)STRLEN(lookfor); | |
2140 for (;;) | |
2141 { | |
2142 /* one step backwards */ | |
230 | 2143 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2144 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2145 { |
2146 if (hiscnt == hislen) /* first time */ | |
2147 hiscnt = hisidx[histype]; | |
2148 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2149 hiscnt = hislen - 1; | |
2150 else if (hiscnt != hisidx[histype] + 1) | |
2151 --hiscnt; | |
2152 else /* at top of list */ | |
2153 { | |
2154 hiscnt = i; | |
2155 break; | |
2156 } | |
2157 } | |
2158 else /* one step forwards */ | |
2159 { | |
2160 /* on last entry, clear the line */ | |
2161 if (hiscnt == hisidx[histype]) | |
2162 { | |
2163 hiscnt = hislen; | |
2164 break; | |
2165 } | |
2166 | |
2167 /* not on a history line, nothing to do */ | |
2168 if (hiscnt == hislen) | |
2169 break; | |
2170 if (hiscnt == hislen - 1) /* wrap around */ | |
2171 hiscnt = 0; | |
2172 else | |
2173 ++hiscnt; | |
2174 } | |
2175 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2176 { | |
2177 hiscnt = i; | |
2178 break; | |
2179 } | |
230 | 2180 if ((c != K_UP && c != K_DOWN) |
180 | 2181 || hiscnt == i |
7 | 2182 || STRNCMP(history[histype][hiscnt].hisstr, |
2183 lookfor, (size_t)j) == 0) | |
2184 break; | |
2185 } | |
2186 | |
2187 if (hiscnt != i) /* jumped to other entry */ | |
2188 { | |
2189 char_u *p; | |
2190 int len; | |
2191 int old_firstc; | |
2192 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2193 VIM_CLEAR(ccline.cmdbuff); |
1718 | 2194 xpc.xp_context = EXPAND_NOTHING; |
7 | 2195 if (hiscnt == hislen) |
2196 p = lookfor; /* back to the old one */ | |
2197 else | |
2198 p = history[histype][hiscnt].hisstr; | |
2199 | |
2200 if (histype == HIST_SEARCH | |
2201 && p != lookfor | |
2202 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2203 { | |
2204 /* Correct for the separator character used when | |
2205 * adding the history entry vs the one used now. | |
2206 * First loop: count length. | |
2207 * Second loop: copy the characters. */ | |
2208 for (i = 0; i <= 1; ++i) | |
2209 { | |
2210 len = 0; | |
2211 for (j = 0; p[j] != NUL; ++j) | |
2212 { | |
2213 /* Replace old sep with new sep, unless it is | |
2214 * escaped. */ | |
2215 if (p[j] == old_firstc | |
2216 && (j == 0 || p[j - 1] != '\\')) | |
2217 { | |
2218 if (i > 0) | |
2219 ccline.cmdbuff[len] = firstc; | |
2220 } | |
2221 else | |
2222 { | |
2223 /* Escape new sep, unless it is already | |
2224 * escaped. */ | |
2225 if (p[j] == firstc | |
2226 && (j == 0 || p[j - 1] != '\\')) | |
2227 { | |
2228 if (i > 0) | |
2229 ccline.cmdbuff[len] = '\\'; | |
2230 ++len; | |
2231 } | |
2232 if (i > 0) | |
2233 ccline.cmdbuff[len] = p[j]; | |
2234 } | |
2235 ++len; | |
2236 } | |
2237 if (i == 0) | |
2238 { | |
2239 alloc_cmdbuff(len); | |
2240 if (ccline.cmdbuff == NULL) | |
2241 goto returncmd; | |
2242 } | |
2243 } | |
2244 ccline.cmdbuff[len] = NUL; | |
2245 } | |
2246 else | |
2247 { | |
2248 alloc_cmdbuff((int)STRLEN(p)); | |
2249 if (ccline.cmdbuff == NULL) | |
2250 goto returncmd; | |
2251 STRCPY(ccline.cmdbuff, p); | |
2252 } | |
2253 | |
2254 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2255 redrawcmd(); | |
2256 goto cmdline_changed; | |
2257 } | |
2258 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2259 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2260 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2261 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2262 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2263 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2264 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
|
2265 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
|
2266 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
|
2267 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2268 break; |
7 | 2269 #endif |
2270 | |
2271 case Ctrl_V: | |
2272 case Ctrl_Q: | |
2273 #ifdef FEAT_MOUSE | |
2274 ignore_drag_release = TRUE; | |
2275 #endif | |
2276 putcmdline('^', TRUE); | |
2277 c = get_literal(); /* get next (two) character(s) */ | |
2278 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
|
2279 extra_char = NUL; |
7 | 2280 #ifdef FEAT_MBYTE |
2281 /* may need to remove ^ when composing char was typed */ | |
2282 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2283 { | |
2284 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2285 msg_putchar(' '); | |
2286 cursorcmd(); | |
2287 } | |
2288 #endif | |
2289 break; | |
2290 | |
2291 #ifdef FEAT_DIGRAPHS | |
2292 case Ctrl_K: | |
2293 #ifdef FEAT_MOUSE | |
2294 ignore_drag_release = TRUE; | |
2295 #endif | |
2296 putcmdline('?', TRUE); | |
2297 #ifdef USE_ON_FLY_SCROLL | |
2298 dont_scroll = TRUE; /* disallow scrolling here */ | |
2299 #endif | |
2300 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
|
2301 extra_char = NUL; |
7 | 2302 if (c != NUL) |
2303 break; | |
2304 | |
2305 redrawcmd(); | |
2306 goto cmdline_not_changed; | |
2307 #endif /* FEAT_DIGRAPHS */ | |
2308 | |
2309 #ifdef FEAT_RIGHTLEFT | |
2310 case Ctrl__: /* CTRL-_: switch language mode */ | |
2311 if (!p_ari) | |
2312 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2313 # ifdef FEAT_FKMAP |
7 | 2314 if (p_altkeymap) |
2315 { | |
2316 cmd_fkmap = !cmd_fkmap; | |
2317 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2318 ccline.overstrike = FALSE; | |
2319 } | |
2320 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2321 # endif |
7 | 2322 cmd_hkmap = !cmd_hkmap; |
2323 goto cmdline_not_changed; | |
2324 #endif | |
2325 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2326 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
|
2327 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
|
2328 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
|
2329 |
7 | 2330 default: |
2331 #ifdef UNIX | |
2332 if (c == intr_char) | |
2333 { | |
2334 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2335 putting it in history */ | |
2336 goto returncmd; /* back to Normal mode */ | |
2337 } | |
2338 #endif | |
2339 /* | |
2340 * Normal character with no special meaning. Just set mod_mask | |
2341 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2342 * the string <S-Space>. This should only happen after ^V. | |
2343 */ | |
2344 if (!IS_SPECIAL(c)) | |
2345 mod_mask = 0x0; | |
2346 break; | |
2347 } | |
2348 /* | |
2349 * End of switch on command line character. | |
2350 * We come here if we have a normal character. | |
2351 */ | |
2352 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2353 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2354 #ifdef FEAT_MBYTE |
2355 /* Add ABBR_OFF for characters above 0x100, this is | |
2356 * what check_abbr() expects. */ | |
2357 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2358 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2359 c) || c == Ctrl_RSB)) |
7 | 2360 goto cmdline_changed; |
2361 | |
2362 /* | |
2363 * put the character in the command line | |
2364 */ | |
2365 if (IS_SPECIAL(c) || mod_mask != 0) | |
2366 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2367 else | |
2368 { | |
2369 #ifdef FEAT_MBYTE | |
2370 if (has_mbyte) | |
2371 { | |
2372 j = (*mb_char2bytes)(c, IObuff); | |
2373 IObuff[j] = NUL; /* exclude composing chars */ | |
2374 put_on_cmdline(IObuff, j, TRUE); | |
2375 } | |
2376 else | |
2377 #endif | |
2378 { | |
2379 IObuff[0] = c; | |
2380 put_on_cmdline(IObuff, 1, TRUE); | |
2381 } | |
2382 } | |
2383 goto cmdline_changed; | |
2384 | |
2385 /* | |
2386 * This part implements incremental searches for "/" and "?" | |
2387 * Jump to cmdline_not_changed when a character has been read but the command | |
2388 * line did not change. Then we only search and redraw if something changed in | |
2389 * the past. | |
2390 * Jump to cmdline_changed when the command line did change. | |
2391 * (Sorry for the goto's, I know it is ugly). | |
2392 */ | |
2393 cmdline_not_changed: | |
2394 #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
|
2395 if (!is_state.incsearch_postponed) |
7 | 2396 continue; |
2397 #endif | |
2398 | |
2399 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
|
2400 /* 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
|
2401 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
|
2402 |
7 | 2403 #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
|
2404 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2405 #endif |
2406 | |
2407 #ifdef FEAT_RIGHTLEFT | |
2408 if (cmdmsg_rl | |
2409 # ifdef FEAT_ARABIC | |
534 | 2410 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2411 # endif |
2412 ) | |
2413 /* Always redraw the whole command line to fix shaping and | |
3374 | 2414 * right-left typing. Not efficient, but it works. |
2415 * Do it only when there are no characters left to read | |
2416 * to avoid useless intermediate redraws. */ | |
2417 if (vpeekc() == NUL) | |
2418 redrawcmd(); | |
7 | 2419 #endif |
2420 } | |
2421 | |
2422 returncmd: | |
2423 | |
2424 #ifdef FEAT_RIGHTLEFT | |
2425 cmdmsg_rl = FALSE; | |
2426 #endif | |
2427 | |
2428 #ifdef FEAT_FKMAP | |
2429 cmd_fkmap = 0; | |
2430 #endif | |
2431 | |
2432 ExpandCleanup(&xpc); | |
1718 | 2433 ccline.xpc = NULL; |
7 | 2434 |
2435 #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
|
2436 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2437 #endif |
2438 | |
2439 if (ccline.cmdbuff != NULL) | |
2440 { | |
2441 /* | |
2442 * Put line in history buffer (":" and "=" only when it was typed). | |
2443 */ | |
2444 #ifdef FEAT_CMDHIST | |
2445 if (ccline.cmdlen && firstc != NUL | |
2446 && (some_key_typed || histype == HIST_SEARCH)) | |
2447 { | |
2448 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2449 histype == HIST_SEARCH ? firstc : NUL); | |
2450 if (firstc == ':') | |
2451 { | |
2452 vim_free(new_last_cmdline); | |
2453 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2454 } | |
2455 } | |
2456 #endif | |
2457 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2458 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
|
2459 abandon_cmdline(); |
7 | 2460 } |
2461 | |
2462 /* | |
2463 * If the screen was shifted up, redraw the whole screen (later). | |
2464 * If the line is too long, clear it, so ruler and shown command do | |
2465 * not get printed in the middle of it. | |
2466 */ | |
2467 msg_check(); | |
2468 msg_scroll = save_msg_scroll; | |
2469 redir_off = FALSE; | |
2470 | |
2471 /* When the command line was typed, no need for a wait-return prompt. */ | |
2472 if (some_key_typed) | |
2473 need_wait_return = FALSE; | |
2474 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2475 /* 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
|
2476 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
|
2477 |
7 | 2478 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2479 #ifdef HAVE_INPUT_METHOD |
7 | 2480 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2481 im_save_status(b_im_ptr); | |
2482 im_set_active(FALSE); | |
2483 #endif | |
2484 #ifdef FEAT_MOUSE | |
2485 setmouse(); | |
2486 #endif | |
2487 #ifdef CURSOR_SHAPE | |
2488 ui_cursor_shape(); /* may show different cursor shape */ | |
2489 #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
|
2490 sb_text_end_cmdline(); |
7 | 2491 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2492 theend: |
95 | 2493 { |
2494 char_u *p = ccline.cmdbuff; | |
2495 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2496 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2497 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2498 else |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2499 ccline.cmdbuff = NULL; |
95 | 2500 return p; |
2501 } | |
7 | 2502 } |
2503 | |
2504 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2505 /* | |
2506 * Get a command line with a prompt. | |
2507 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2508 * f_input() when evaluating an expression from CTRL-R =). | |
2509 * Returns the command line in allocated memory, or NULL. | |
2510 */ | |
2511 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2512 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2513 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2514 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2515 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2516 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2517 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2518 { |
2519 char_u *s; | |
2520 struct cmdline_info save_ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2521 int did_save_ccline = FALSE; |
7 | 2522 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
|
2523 int msg_silent_save = msg_silent; |
7 | 2524 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2525 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2526 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2527 // Save the values of the current cmdline and restore them below. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2528 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2529 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2530 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2531 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2532 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
7 | 2533 ccline.cmdprompt = prompt; |
2534 ccline.cmdattr = attr; | |
531 | 2535 # ifdef FEAT_EVAL |
2536 ccline.xp_context = xp_context; | |
2537 ccline.xp_arg = xp_arg; | |
2538 ccline.input_fn = (firstc == '@'); | |
2539 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2540 msg_silent = 0; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2541 s = getcmdline_int(firstc, 1L, 0, FALSE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2542 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2543 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2544 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2545 |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2546 msg_silent = msg_silent_save; |
3020 | 2547 /* Restore msg_col, the prompt from input() may have changed it. |
2548 * But only if called recursively and the commandline is therefore being | |
2549 * restored to an old one; if not, the input() prompt stays on the screen, | |
2550 * so we need its modified msg_col left intact. */ | |
2551 if (ccline.cmdbuff != NULL) | |
2552 msg_col = msg_col_save; | |
7 | 2553 |
2554 return s; | |
2555 } | |
2556 #endif | |
2557 | |
632 | 2558 /* |
634 | 2559 * Return TRUE when the text must not be changed and we can't switch to |
2560 * another window or buffer. Used when editing the command line, evaluating | |
2561 * 'balloonexpr', etc. | |
632 | 2562 */ |
2563 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2564 text_locked(void) |
632 | 2565 { |
2566 #ifdef FEAT_CMDWIN | |
2567 if (cmdwin_type != 0) | |
2568 return TRUE; | |
2569 #endif | |
634 | 2570 return textlock != 0; |
632 | 2571 } |
2572 | |
2573 /* | |
2574 * Give an error message for a command that isn't allowed while the cmdline | |
2575 * window is open or editing the cmdline in another way. | |
2576 */ | |
2577 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2578 text_locked_msg(void) |
632 | 2579 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2580 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2581 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2582 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2583 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2584 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2585 { |
632 | 2586 #ifdef FEAT_CMDWIN |
2587 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2588 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2589 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2590 return e_secure; |
632 | 2591 } |
2592 | |
819 | 2593 /* |
1834 | 2594 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2595 * and give an error message. | |
819 | 2596 */ |
2597 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2598 curbuf_locked(void) |
819 | 2599 { |
2600 if (curbuf_lock > 0) | |
2601 { | |
2602 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2603 return TRUE; | |
2604 } | |
1834 | 2605 return allbuf_locked(); |
2606 } | |
2607 | |
2608 /* | |
2609 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2610 * message. | |
2611 */ | |
2612 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2613 allbuf_locked(void) |
1834 | 2614 { |
2615 if (allbuf_lock > 0) | |
2616 { | |
2617 EMSG(_("E811: Not allowed to change buffer information now")); | |
2618 return TRUE; | |
2619 } | |
819 | 2620 return FALSE; |
2621 } | |
2622 | |
7 | 2623 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2624 cmdline_charsize(int idx) |
7 | 2625 { |
2626 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2627 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2628 return 1; | |
2629 #endif | |
2630 return ptr2cells(ccline.cmdbuff + idx); | |
2631 } | |
2632 | |
2633 /* | |
2634 * Compute the offset of the cursor on the command line for the prompt and | |
2635 * indent. | |
2636 */ | |
2637 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2638 set_cmdspos(void) |
7 | 2639 { |
531 | 2640 if (ccline.cmdfirstc != NUL) |
7 | 2641 ccline.cmdspos = 1 + ccline.cmdindent; |
2642 else | |
2643 ccline.cmdspos = 0 + ccline.cmdindent; | |
2644 } | |
2645 | |
2646 /* | |
2647 * Compute the screen position for the cursor on the command line. | |
2648 */ | |
2649 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2650 set_cmdspos_cursor(void) |
7 | 2651 { |
2652 int i, m, c; | |
2653 | |
2654 set_cmdspos(); | |
2655 if (KeyTyped) | |
534 | 2656 { |
7 | 2657 m = Columns * Rows; |
534 | 2658 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2659 m = MAXCOL; | |
2660 } | |
7 | 2661 else |
2662 m = MAXCOL; | |
2663 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2664 { | |
2665 c = cmdline_charsize(i); | |
2666 #ifdef FEAT_MBYTE | |
2667 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2668 if (has_mbyte) | |
2669 correct_cmdspos(i, c); | |
2670 #endif | |
1612 | 2671 /* If the cmdline doesn't fit, show cursor on last visible char. |
2672 * Don't move the cursor itself, so we can still append. */ | |
7 | 2673 if ((ccline.cmdspos += c) >= m) |
2674 { | |
2675 ccline.cmdspos -= c; | |
2676 break; | |
2677 } | |
2678 #ifdef FEAT_MBYTE | |
2679 if (has_mbyte) | |
474 | 2680 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2681 #endif |
2682 } | |
2683 } | |
2684 | |
2685 #ifdef FEAT_MBYTE | |
2686 /* | |
2687 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2688 * character that doesn't fit, so that a ">" must be displayed. | |
2689 */ | |
2690 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2691 correct_cmdspos(int idx, int cells) |
7 | 2692 { |
474 | 2693 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2694 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2695 && ccline.cmdspos % Columns + cells > Columns) | |
2696 ccline.cmdspos++; | |
2697 } | |
2698 #endif | |
2699 | |
2700 /* | |
2701 * Get an Ex command line for the ":" command. | |
2702 */ | |
2703 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2704 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2705 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2706 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2707 int indent) /* indent for inside conditionals */ |
7 | 2708 { |
2709 /* When executing a register, remove ':' that's in front of each line. */ | |
2710 if (exec_from_reg && vpeekc() == ':') | |
2711 (void)vgetc(); | |
2712 return getcmdline(c, 1L, indent); | |
2713 } | |
2714 | |
2715 /* | |
2716 * Get an Ex command line for Ex mode. | |
2717 * In Ex mode we only use the OS supplied line editing features and no | |
2718 * mappings or abbreviations. | |
168 | 2719 * Returns a string in allocated memory or NULL. |
7 | 2720 */ |
2721 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2722 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2723 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2724 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2725 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2726 int indent) /* indent for inside conditionals */ |
7 | 2727 { |
168 | 2728 garray_T line_ga; |
2729 char_u *pend; | |
2730 int startcol = 0; | |
1329 | 2731 int c1 = 0; |
168 | 2732 int escaped = FALSE; /* CTRL-V typed */ |
2733 int vcol = 0; | |
2734 char_u *p; | |
1329 | 2735 int prev_char; |
5966 | 2736 int len; |
7 | 2737 |
2738 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2739 * confuses the system function that computes tabstops. */ | |
2740 cursor_on(); | |
2741 | |
2742 /* always start in column 0; write a newline if necessary */ | |
2743 compute_cmdrow(); | |
168 | 2744 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2745 msg_putchar('\n'); |
168 | 2746 if (promptc == ':') |
7 | 2747 { |
164 | 2748 /* indent that is only displayed, not in the line itself */ |
168 | 2749 if (p_prompt) |
2750 msg_putchar(':'); | |
7 | 2751 while (indent-- > 0) |
2752 msg_putchar(' '); | |
2753 startcol = msg_col; | |
2754 } | |
2755 | |
2756 ga_init2(&line_ga, 1, 30); | |
2757 | |
164 | 2758 /* autoindent for :insert and :append is in the line itself */ |
168 | 2759 if (promptc <= 0) |
164 | 2760 { |
2761 vcol = indent; | |
2762 while (indent >= 8) | |
2763 { | |
2764 ga_append(&line_ga, TAB); | |
2765 msg_puts((char_u *)" "); | |
2766 indent -= 8; | |
2767 } | |
2768 while (indent-- > 0) | |
2769 { | |
2770 ga_append(&line_ga, ' '); | |
2771 msg_putchar(' '); | |
2772 } | |
2773 } | |
168 | 2774 ++no_mapping; |
2775 ++allow_keys; | |
164 | 2776 |
7 | 2777 /* |
2778 * Get the line, one character at a time. | |
2779 */ | |
2780 got_int = FALSE; | |
168 | 2781 while (!got_int) |
7 | 2782 { |
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
|
2783 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
|
2784 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
|
2785 |
7 | 2786 if (ga_grow(&line_ga, 40) == FAIL) |
2787 break; | |
2788 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2789 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2790 * 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
|
2791 */ |
1329 | 2792 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
|
2793 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2794 /* 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
|
2795 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
|
2796 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
|
2797 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2798 c1 = vgetc(); |
7 | 2799 |
2800 /* | |
168 | 2801 * Handle line editing. |
2802 * Previously this was left to the system, putting the terminal in | |
2803 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2804 */ |
168 | 2805 if (got_int) |
2806 { | |
2807 msg_putchar('\n'); | |
2808 break; | |
2809 } | |
2810 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2811 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
|
2812 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2813 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
|
2814 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
|
2815 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2816 |
168 | 2817 if (!escaped) |
7 | 2818 { |
168 | 2819 /* CR typed means "enter", which is NL */ |
2820 if (c1 == '\r') | |
2821 c1 = '\n'; | |
2822 | |
2823 if (c1 == BS || c1 == K_BS | |
2824 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2825 { |
168 | 2826 if (line_ga.ga_len > 0) |
2827 { | |
5966 | 2828 #ifdef FEAT_MBYTE |
2829 if (has_mbyte) | |
2830 { | |
2831 p = (char_u *)line_ga.ga_data; | |
2832 p[line_ga.ga_len] = NUL; | |
2833 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2834 line_ga.ga_len -= len; | |
2835 } | |
2836 else | |
2837 #endif | |
2838 --line_ga.ga_len; | |
168 | 2839 goto redraw; |
2840 } | |
2841 continue; | |
7 | 2842 } |
2843 | |
168 | 2844 if (c1 == Ctrl_U) |
7 | 2845 { |
168 | 2846 msg_col = startcol; |
2847 msg_clr_eos(); | |
2848 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
|
2849 goto redraw; |
168 | 2850 } |
2851 | |
2852 if (c1 == Ctrl_T) | |
2853 { | |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2854 sw = get_sw_value(curbuf); |
168 | 2855 p = (char_u *)line_ga.ga_data; |
2856 p[line_ga.ga_len] = NUL; | |
5995 | 2857 indent = get_indent_str(p, 8, FALSE); |
3740 | 2858 indent += sw - indent % sw; |
168 | 2859 add_indent: |
5995 | 2860 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2861 { |
7009 | 2862 (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
|
2863 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
|
2864 s = skipwhite(p); |
168 | 2865 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2866 *s = ' '; | |
2867 ++line_ga.ga_len; | |
7 | 2868 } |
168 | 2869 redraw: |
2870 /* redraw the line */ | |
2871 msg_col = startcol; | |
2872 vcol = 0; | |
5966 | 2873 p = (char_u *)line_ga.ga_data; |
2874 p[line_ga.ga_len] = NUL; | |
2875 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2876 { |
168 | 2877 if (*p == TAB) |
7 | 2878 { |
168 | 2879 do |
7 | 2880 { |
168 | 2881 msg_putchar(' '); |
2882 } while (++vcol % 8); | |
5966 | 2883 ++p; |
7 | 2884 } |
168 | 2885 else |
164 | 2886 { |
5966 | 2887 len = MB_PTR2LEN(p); |
2888 msg_outtrans_len(p, len); | |
2889 vcol += ptr2cells(p); | |
2890 p += len; | |
7 | 2891 } |
2892 } | |
168 | 2893 msg_clr_eos(); |
1329 | 2894 windgoto(msg_row, msg_col); |
168 | 2895 continue; |
2896 } | |
2897 | |
2898 if (c1 == Ctrl_D) | |
2899 { | |
2900 /* Delete one shiftwidth. */ | |
2901 p = (char_u *)line_ga.ga_data; | |
2902 if (prev_char == '0' || prev_char == '^') | |
7 | 2903 { |
168 | 2904 if (prev_char == '^') |
2905 ex_keep_indent = TRUE; | |
2906 indent = 0; | |
2907 p[--line_ga.ga_len] = NUL; | |
7 | 2908 } |
2909 else | |
2910 { | |
168 | 2911 p[line_ga.ga_len] = NUL; |
5995 | 2912 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
|
2913 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
|
2914 { |
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
|
2915 --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
|
2916 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
|
2917 } |
168 | 2918 } |
5995 | 2919 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2920 { |
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
|
2921 s = skipwhite(p); |
168 | 2922 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2923 --line_ga.ga_len; | |
7 | 2924 } |
168 | 2925 goto add_indent; |
2926 } | |
2927 | |
2928 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2929 { | |
2930 escaped = TRUE; | |
2931 continue; | |
7 | 2932 } |
168 | 2933 |
2934 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2935 if (IS_SPECIAL(c1)) | |
2936 continue; | |
7 | 2937 } |
168 | 2938 |
2939 if (IS_SPECIAL(c1)) | |
2940 c1 = '?'; | |
5966 | 2941 #ifdef FEAT_MBYTE |
2942 if (has_mbyte) | |
2943 len = (*mb_char2bytes)(c1, | |
2944 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2945 else | |
2946 #endif | |
2947 { | |
2948 len = 1; | |
2949 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2950 } | |
168 | 2951 if (c1 == '\n') |
2952 msg_putchar('\n'); | |
2953 else if (c1 == TAB) | |
2954 { | |
2955 /* Don't use chartabsize(), 'ts' can be different */ | |
2956 do | |
2957 { | |
2958 msg_putchar(' '); | |
2959 } while (++vcol % 8); | |
2960 } | |
7 | 2961 else |
2962 { | |
168 | 2963 msg_outtrans_len( |
5966 | 2964 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2965 vcol += char2cells(c1); |
7 | 2966 } |
5966 | 2967 line_ga.ga_len += len; |
168 | 2968 escaped = FALSE; |
2969 | |
2970 windgoto(msg_row, msg_col); | |
164 | 2971 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2972 |
2590 | 2973 /* We are done when a NL is entered, but not when it comes after an |
2974 * odd number of backslashes, that results in a NUL. */ | |
2975 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2976 { |
2590 | 2977 int bcount = 0; |
2978 | |
2979 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2980 ++bcount; | |
2981 | |
2982 if (bcount > 0) | |
2983 { | |
2984 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2985 * "\NL", etc. */ | |
2986 line_ga.ga_len -= (bcount + 1) / 2; | |
2987 pend -= (bcount + 1) / 2; | |
2988 pend[-1] = '\n'; | |
2989 } | |
2990 | |
2991 if ((bcount & 1) == 0) | |
2992 { | |
2993 --line_ga.ga_len; | |
2994 --pend; | |
2995 *pend = NUL; | |
2996 break; | |
2997 } | |
7 | 2998 } |
2999 } | |
3000 | |
168 | 3001 --no_mapping; |
3002 --allow_keys; | |
3003 | |
7 | 3004 /* make following messages go to the next line */ |
3005 msg_didout = FALSE; | |
3006 msg_col = 0; | |
3007 if (msg_row < Rows - 1) | |
3008 ++msg_row; | |
3009 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
3010 | |
3011 if (got_int) | |
3012 ga_clear(&line_ga); | |
3013 | |
3014 return (char_u *)line_ga.ga_data; | |
3015 } | |
3016 | |
502 | 3017 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
3018 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 3019 /* |
3020 * Return TRUE if ccline.overstrike is on. | |
3021 */ | |
3022 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3023 cmdline_overstrike(void) |
7 | 3024 { |
3025 return ccline.overstrike; | |
3026 } | |
3027 | |
3028 /* | |
3029 * Return TRUE if the cursor is at the end of the cmdline. | |
3030 */ | |
3031 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3032 cmdline_at_end(void) |
7 | 3033 { |
3034 return (ccline.cmdpos >= ccline.cmdlen); | |
3035 } | |
3036 #endif | |
3037 | |
574 | 3038 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 3039 /* |
3040 * Return the virtual column number at the current cursor position. | |
3041 * This is used by the IM code to obtain the start of the preedit string. | |
3042 */ | |
3043 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3044 cmdline_getvcol_cursor(void) |
7 | 3045 { |
3046 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3047 return MAXCOL; | |
3048 | |
3049 # ifdef FEAT_MBYTE | |
3050 if (has_mbyte) | |
3051 { | |
3052 colnr_T col; | |
3053 int i = 0; | |
3054 | |
3055 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3056 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3057 |
3058 return col; | |
3059 } | |
3060 else | |
3061 # endif | |
3062 return ccline.cmdpos; | |
3063 } | |
3064 #endif | |
3065 | |
3066 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3067 /* | |
3068 * If part of the command line is an IM preedit string, redraw it with | |
3069 * IM feedback attributes. The cursor position is restored after drawing. | |
3070 */ | |
3071 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3072 redrawcmd_preedit(void) |
7 | 3073 { |
3074 if ((State & CMDLINE) | |
3075 && xic != NULL | |
976 | 3076 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3077 && !p_imdisable |
3078 && im_is_preediting()) | |
3079 { | |
3080 int cmdpos = 0; | |
3081 int cmdspos; | |
3082 int old_row; | |
3083 int old_col; | |
3084 colnr_T col; | |
3085 | |
3086 old_row = msg_row; | |
3087 old_col = msg_col; | |
531 | 3088 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3089 |
3090 # ifdef FEAT_MBYTE | |
3091 if (has_mbyte) | |
3092 { | |
3093 for (col = 0; col < preedit_start_col | |
3094 && cmdpos < ccline.cmdlen; ++col) | |
3095 { | |
3096 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3097 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3098 } |
3099 } | |
3100 else | |
3101 # endif | |
3102 { | |
3103 cmdspos += preedit_start_col; | |
3104 cmdpos += preedit_start_col; | |
3105 } | |
3106 | |
3107 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3108 msg_col = cmdspos % (int)Columns; | |
3109 if (msg_row >= Rows) | |
3110 msg_row = Rows - 1; | |
3111 | |
3112 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3113 { | |
3114 int char_len; | |
3115 int char_attr; | |
3116 | |
3117 char_attr = im_get_feedback_attr(col); | |
3118 if (char_attr < 0) | |
3119 break; /* end of preedit string */ | |
3120 | |
3121 # ifdef FEAT_MBYTE | |
3122 if (has_mbyte) | |
474 | 3123 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3124 else |
3125 # endif | |
3126 char_len = 1; | |
3127 | |
3128 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3129 cmdpos += char_len; | |
3130 } | |
3131 | |
3132 msg_row = old_row; | |
3133 msg_col = old_col; | |
3134 } | |
3135 } | |
3136 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3137 | |
3138 /* | |
3139 * Allocate a new command line buffer. | |
3140 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3141 */ | |
3142 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3143 alloc_cmdbuff(int len) |
7 | 3144 { |
3145 /* | |
3146 * give some extra space to avoid having to allocate all the time | |
3147 */ | |
3148 if (len < 80) | |
3149 len = 100; | |
3150 else | |
3151 len += 20; | |
3152 | |
3153 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3154 ccline.cmdbufflen = len; | |
3155 } | |
3156 | |
3157 /* | |
3158 * Re-allocate the command line to length len + something extra. | |
3159 * return FAIL for failure, OK otherwise | |
3160 */ | |
3161 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3162 realloc_cmdbuff(int len) |
7 | 3163 { |
3164 char_u *p; | |
3165 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3166 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3167 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
|
3168 |
7 | 3169 p = ccline.cmdbuff; |
3170 alloc_cmdbuff(len); /* will get some more */ | |
3171 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3172 { | |
3173 ccline.cmdbuff = p; /* keep the old one */ | |
3174 return FAIL; | |
3175 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3176 /* 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
|
3177 * 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
|
3178 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
|
3179 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3180 vim_free(p); |
1718 | 3181 |
3182 if (ccline.xpc != NULL | |
3183 && ccline.xpc->xp_pattern != NULL | |
3184 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3185 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3186 { | |
1754 | 3187 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3188 |
3189 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3190 * to point into the newly allocated memory. */ | |
3191 if (i >= 0 && i <= ccline.cmdlen) | |
3192 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3193 } | |
3194 | |
7 | 3195 return OK; |
3196 } | |
3197 | |
359 | 3198 #if defined(FEAT_ARABIC) || defined(PROTO) |
3199 static char_u *arshape_buf = NULL; | |
3200 | |
3201 # if defined(EXITFREE) || defined(PROTO) | |
3202 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3203 free_cmdline_buf(void) |
359 | 3204 { |
3205 vim_free(arshape_buf); | |
3206 } | |
3207 # endif | |
3208 #endif | |
3209 | |
7 | 3210 /* |
3211 * Draw part of the cmdline at the current cursor position. But draw stars | |
3212 * when cmdline_star is TRUE. | |
3213 */ | |
3214 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3215 draw_cmdline(int start, int len) |
7 | 3216 { |
3217 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3218 int i; | |
3219 | |
3220 if (cmdline_star > 0) | |
3221 for (i = 0; i < len; ++i) | |
3222 { | |
3223 msg_putchar('*'); | |
3224 # ifdef FEAT_MBYTE | |
3225 if (has_mbyte) | |
474 | 3226 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3227 # endif |
3228 } | |
3229 else | |
3230 #endif | |
3231 #ifdef FEAT_ARABIC | |
3232 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3233 { | |
3234 static int buflen = 0; | |
3235 char_u *p; | |
3236 int j; | |
3237 int newlen = 0; | |
3238 int mb_l; | |
719 | 3239 int pc, pc1 = 0; |
7 | 3240 int prev_c = 0; |
3241 int prev_c1 = 0; | |
714 | 3242 int u8c; |
3243 int u8cc[MAX_MCO]; | |
7 | 3244 int nc = 0; |
3245 | |
3246 /* | |
3247 * Do arabic shaping into a temporary buffer. This is very | |
3248 * inefficient! | |
3249 */ | |
507 | 3250 if (len * 2 + 2 > buflen) |
7 | 3251 { |
3252 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3253 * alloc()/free() calls. */ | |
359 | 3254 vim_free(arshape_buf); |
507 | 3255 buflen = len * 2 + 2; |
359 | 3256 arshape_buf = alloc(buflen); |
3257 if (arshape_buf == NULL) | |
7 | 3258 return; /* out of memory */ |
3259 } | |
3260 | |
507 | 3261 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3262 { | |
3263 /* Prepend a space to draw the leading composing char on. */ | |
3264 arshape_buf[0] = ' '; | |
3265 newlen = 1; | |
3266 } | |
3267 | |
7 | 3268 for (j = start; j < start + len; j += mb_l) |
3269 { | |
3270 p = ccline.cmdbuff + j; | |
714 | 3271 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3272 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3273 if (ARABIC_CHAR(u8c)) |
3274 { | |
3275 /* Do Arabic shaping. */ | |
3276 if (cmdmsg_rl) | |
3277 { | |
3278 /* displaying from right to left */ | |
3279 pc = prev_c; | |
3280 pc1 = prev_c1; | |
714 | 3281 prev_c1 = u8cc[0]; |
7 | 3282 if (j + mb_l >= start + len) |
3283 nc = NUL; | |
3284 else | |
3285 nc = utf_ptr2char(p + mb_l); | |
3286 } | |
3287 else | |
3288 { | |
3289 /* displaying from left to right */ | |
3290 if (j + mb_l >= start + len) | |
3291 pc = NUL; | |
3292 else | |
714 | 3293 { |
3294 int pcc[MAX_MCO]; | |
3295 | |
3296 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3297 start + len - j - mb_l); |
714 | 3298 pc1 = pcc[0]; |
3299 } | |
7 | 3300 nc = prev_c; |
3301 } | |
3302 prev_c = u8c; | |
3303 | |
714 | 3304 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3305 |
359 | 3306 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3307 if (u8cc[0] != 0) |
7 | 3308 { |
714 | 3309 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3310 if (u8cc[1] != 0) | |
3311 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3312 arshape_buf + newlen); |
7 | 3313 } |
3314 } | |
3315 else | |
3316 { | |
3317 prev_c = u8c; | |
359 | 3318 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3319 newlen += mb_l; |
3320 } | |
3321 } | |
3322 | |
359 | 3323 msg_outtrans_len(arshape_buf, newlen); |
7 | 3324 } |
3325 else | |
3326 #endif | |
3327 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3328 } | |
3329 | |
3330 /* | |
3331 * Put a character on the command line. Shifts the following text to the | |
3332 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3333 * "c" must be printable (fit in one display cell)! | |
3334 */ | |
3335 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3336 putcmdline(int c, int shift) |
7 | 3337 { |
3338 if (cmd_silent) | |
3339 return; | |
3340 msg_no_more = TRUE; | |
3341 msg_putchar(c); | |
3342 if (shift) | |
3343 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3344 msg_no_more = FALSE; | |
3345 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3346 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3347 extra_char_shift = shift; |
7 | 3348 } |
3349 | |
3350 /* | |
3351 * Undo a putcmdline(c, FALSE). | |
3352 */ | |
3353 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3354 unputcmdline(void) |
7 | 3355 { |
3356 if (cmd_silent) | |
3357 return; | |
3358 msg_no_more = TRUE; | |
3359 if (ccline.cmdlen == ccline.cmdpos) | |
3360 msg_putchar(' '); | |
3558 | 3361 #ifdef FEAT_MBYTE |
3362 else if (has_mbyte) | |
3363 draw_cmdline(ccline.cmdpos, | |
3364 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3365 #endif | |
7 | 3366 else |
3367 draw_cmdline(ccline.cmdpos, 1); | |
3368 msg_no_more = FALSE; | |
3369 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3370 extra_char = NUL; |
7 | 3371 } |
3372 | |
3373 /* | |
3374 * Put the given string, of the given length, onto the command line. | |
3375 * If len is -1, then STRLEN() is used to calculate the length. | |
3376 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3377 * part will be redrawn, otherwise it will not. If this function is called | |
3378 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3379 * called afterwards. | |
3380 */ | |
3381 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3382 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3383 { |
3384 int retval; | |
3385 int i; | |
3386 int m; | |
3387 int c; | |
3388 | |
3389 if (len < 0) | |
3390 len = (int)STRLEN(str); | |
3391 | |
3392 /* Check if ccline.cmdbuff needs to be longer */ | |
3393 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
|
3394 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3395 else |
3396 retval = OK; | |
3397 if (retval == OK) | |
3398 { | |
3399 if (!ccline.overstrike) | |
3400 { | |
3401 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3402 ccline.cmdbuff + ccline.cmdpos, | |
3403 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3404 ccline.cmdlen += len; | |
3405 } | |
3406 else | |
3407 { | |
3408 #ifdef FEAT_MBYTE | |
3409 if (has_mbyte) | |
3410 { | |
3411 /* Count nr of characters in the new string. */ | |
3412 m = 0; | |
474 | 3413 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3414 ++m; |
3415 /* Count nr of bytes in cmdline that are overwritten by these | |
3416 * characters. */ | |
3417 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3418 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3419 --m; |
3420 if (i < ccline.cmdlen) | |
3421 { | |
3422 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3423 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3424 ccline.cmdlen += ccline.cmdpos + len - i; | |
3425 } | |
3426 else | |
3427 ccline.cmdlen = ccline.cmdpos + len; | |
3428 } | |
3429 else | |
3430 #endif | |
3431 if (ccline.cmdpos + len > ccline.cmdlen) | |
3432 ccline.cmdlen = ccline.cmdpos + len; | |
3433 } | |
3434 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3435 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3436 | |
3437 #ifdef FEAT_MBYTE | |
3438 if (enc_utf8) | |
3439 { | |
3440 /* When the inserted text starts with a composing character, | |
3441 * backup to the character before it. There could be two of them. | |
3442 */ | |
3443 i = 0; | |
3444 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3445 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3446 { | |
3447 i = (*mb_head_off)(ccline.cmdbuff, | |
3448 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3449 ccline.cmdpos -= i; | |
3450 len += i; | |
3451 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3452 } | |
3453 # ifdef FEAT_ARABIC | |
3454 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3455 { | |
3456 /* Check the previous character for Arabic combining pair. */ | |
3457 i = (*mb_head_off)(ccline.cmdbuff, | |
3458 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3459 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3460 + ccline.cmdpos - i), c)) | |
3461 { | |
3462 ccline.cmdpos -= i; | |
3463 len += i; | |
3464 } | |
3465 else | |
3466 i = 0; | |
3467 } | |
3468 # endif | |
3469 if (i != 0) | |
3470 { | |
3471 /* Also backup the cursor position. */ | |
3472 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3473 ccline.cmdspos -= i; | |
3474 msg_col -= i; | |
3475 if (msg_col < 0) | |
3476 { | |
3477 msg_col += Columns; | |
3478 --msg_row; | |
3479 } | |
3480 } | |
3481 } | |
3482 #endif | |
3483 | |
3484 if (redraw && !cmd_silent) | |
3485 { | |
3486 msg_no_more = TRUE; | |
3487 i = cmdline_row; | |
3114 | 3488 cursorcmd(); |
7 | 3489 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3490 /* Avoid clearing the rest of the line too often. */ | |
3491 if (cmdline_row != i || ccline.overstrike) | |
3492 msg_clr_eos(); | |
3493 msg_no_more = FALSE; | |
3494 } | |
3495 #ifdef FEAT_FKMAP | |
3496 /* | |
3497 * If we are in Farsi command mode, the character input must be in | |
3498 * Insert mode. So do not advance the cmdpos. | |
3499 */ | |
3500 if (!cmd_fkmap) | |
3501 #endif | |
3502 { | |
3503 if (KeyTyped) | |
534 | 3504 { |
7 | 3505 m = Columns * Rows; |
534 | 3506 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3507 m = MAXCOL; | |
3508 } | |
7 | 3509 else |
3510 m = MAXCOL; | |
3511 for (i = 0; i < len; ++i) | |
3512 { | |
3513 c = cmdline_charsize(ccline.cmdpos); | |
3514 #ifdef FEAT_MBYTE | |
3515 /* count ">" for a double-wide char that doesn't fit. */ | |
3516 if (has_mbyte) | |
3517 correct_cmdspos(ccline.cmdpos, c); | |
3518 #endif | |
1612 | 3519 /* Stop cursor at the end of the screen, but do increment the |
3520 * insert position, so that entering a very long command | |
3521 * works, even though you can't see it. */ | |
3522 if (ccline.cmdspos + c < m) | |
3523 ccline.cmdspos += c; | |
7 | 3524 #ifdef FEAT_MBYTE |
3525 if (has_mbyte) | |
3526 { | |
474 | 3527 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3528 if (c > len - i - 1) |
3529 c = len - i - 1; | |
3530 ccline.cmdpos += c; | |
3531 i += c; | |
3532 } | |
3533 #endif | |
3534 ++ccline.cmdpos; | |
3535 } | |
3536 } | |
3537 } | |
3538 if (redraw) | |
3539 msg_check(); | |
3540 return retval; | |
3541 } | |
3542 | |
95 | 3543 static struct cmdline_info prev_ccline; |
3544 static int prev_ccline_used = FALSE; | |
3545 | |
3546 /* | |
3547 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3548 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3549 * available globally in prev_ccline. | |
3550 */ | |
3551 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3552 save_cmdline(struct cmdline_info *ccp) |
95 | 3553 { |
3554 if (!prev_ccline_used) | |
3555 { | |
3556 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3557 prev_ccline_used = TRUE; | |
3558 } | |
3559 *ccp = prev_ccline; | |
3560 prev_ccline = ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3561 ccline.cmdbuff = NULL; // signal that ccline is not in use |
95 | 3562 } |
3563 | |
3564 /* | |
1214 | 3565 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3566 */ |
3567 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3568 restore_cmdline(struct cmdline_info *ccp) |
95 | 3569 { |
3570 ccline = prev_ccline; | |
3571 prev_ccline = *ccp; | |
3572 } | |
3573 | |
15 | 3574 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3575 * 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
|
3576 * Used by CTRL-R command in command-line mode. |
15 | 3577 * insert_reg() can't be used here, because special characters from the |
3578 * register contents will be interpreted as commands. | |
3579 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3580 * Return FAIL for failure, OK otherwise. |
15 | 3581 */ |
3582 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3583 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3584 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3585 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
|
3586 int remcr) /* remove trailing CR */ |
15 | 3587 { |
3588 long i; | |
3589 char_u *arg; | |
772 | 3590 char_u *p; |
15 | 3591 int allocated; |
3592 | |
3593 /* check for valid regname; also accept special characters for CTRL-R in | |
3594 * the command line */ | |
3595 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
|
3596 && 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
|
3597 && !valid_yank_reg(regname, FALSE)) |
15 | 3598 return FAIL; |
3599 | |
3600 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3601 * CTRL-C to break the loop. */ | |
3602 line_breakcheck(); | |
3603 if (got_int) | |
3604 return FAIL; | |
3605 | |
3606 #ifdef FEAT_CLIPBOARD | |
3607 regname = may_get_selection(regname); | |
3608 #endif | |
3609 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3610 // Need to set "textlock" to avoid nasty things like going to another |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3611 // buffer when evaluating an expression. |
634 | 3612 ++textlock; |
15 | 3613 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3614 --textlock; |
15 | 3615 |
3616 if (i) | |
3617 { | |
3618 /* Got the value of a special register in "arg". */ | |
3619 if (arg == NULL) | |
3620 return FAIL; | |
772 | 3621 |
3622 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3623 * part of the word. */ | |
3624 p = arg; | |
3625 if (p_is && regname == Ctrl_W) | |
3626 { | |
3627 char_u *w; | |
3628 int len; | |
3629 | |
3630 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3631 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3632 { |
3633 #ifdef FEAT_MBYTE | |
3634 if (has_mbyte) | |
3635 { | |
3636 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3637 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3638 break; | |
3639 w -= len; | |
3640 } | |
3641 else | |
3642 #endif | |
3643 { | |
3644 if (!vim_iswordc(w[-1])) | |
3645 break; | |
3646 --w; | |
3647 } | |
3648 } | |
2937 | 3649 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3650 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3651 p += len; | |
3652 } | |
3653 | |
3654 cmdline_paste_str(p, literally); | |
15 | 3655 if (allocated) |
3656 vim_free(arg); | |
3657 return OK; | |
3658 } | |
3659 | |
1015 | 3660 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3661 } |
3662 | |
3663 /* | |
3664 * Put a string on the command line. | |
3665 * When "literally" is TRUE, insert literally. | |
3666 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3667 * line. | |
3668 */ | |
3669 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3670 cmdline_paste_str(char_u *s, int literally) |
15 | 3671 { |
3672 int c, cv; | |
3673 | |
3674 if (literally) | |
3675 put_on_cmdline(s, -1, TRUE); | |
3676 else | |
3677 while (*s != NUL) | |
3678 { | |
3679 cv = *s; | |
3680 if (cv == Ctrl_V && s[1]) | |
3681 ++s; | |
3682 #ifdef FEAT_MBYTE | |
3683 if (has_mbyte) | |
1606 | 3684 c = mb_cptr2char_adv(&s); |
15 | 3685 else |
3686 #endif | |
3687 c = *s++; | |
3628 | 3688 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3689 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3690 #ifdef UNIX |
3691 || c == intr_char | |
3692 #endif | |
3693 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3694 stuffcharReadbuff(Ctrl_V); | |
3695 stuffcharReadbuff(c); | |
3696 } | |
3697 } | |
3698 | |
7 | 3699 #ifdef FEAT_WILDMENU |
3700 /* | |
3701 * Delete characters on the command line, from "from" to the current | |
3702 * position. | |
3703 */ | |
3704 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3705 cmdline_del(int from) |
7 | 3706 { |
3707 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3708 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3709 ccline.cmdlen -= ccline.cmdpos - from; | |
3710 ccline.cmdpos = from; | |
3711 } | |
3712 #endif | |
3713 | |
3714 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3715 * 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
|
3716 * 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
|
3717 * overwritten. |
7 | 3718 */ |
3719 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3720 redrawcmdline(void) |
7 | 3721 { |
11416
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3722 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
|
3723 } |
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
|
3724 |
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
|
3725 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
|
3726 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
|
3727 { |
7 | 3728 if (cmd_silent) |
3729 return; | |
3730 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
|
3731 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
|
3732 compute_cmdrow(); |
7 | 3733 redrawcmd(); |
3734 cursorcmd(); | |
3735 } | |
3736 | |
3737 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3738 redrawcmdprompt(void) |
7 | 3739 { |
3740 int i; | |
3741 | |
3742 if (cmd_silent) | |
3743 return; | |
531 | 3744 if (ccline.cmdfirstc != NUL) |
7 | 3745 msg_putchar(ccline.cmdfirstc); |
3746 if (ccline.cmdprompt != NULL) | |
3747 { | |
3748 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3749 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3750 /* do the reverse of set_cmdspos() */ | |
531 | 3751 if (ccline.cmdfirstc != NUL) |
7 | 3752 --ccline.cmdindent; |
3753 } | |
3754 else | |
3755 for (i = ccline.cmdindent; i > 0; --i) | |
3756 msg_putchar(' '); | |
3757 } | |
3758 | |
3759 /* | |
3760 * Redraw what is currently on the command line. | |
3761 */ | |
3762 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3763 redrawcmd(void) |
7 | 3764 { |
3765 if (cmd_silent) | |
3766 return; | |
3767 | |
683 | 3768 /* when 'incsearch' is set there may be no command line while redrawing */ |
3769 if (ccline.cmdbuff == NULL) | |
3770 { | |
3771 windgoto(cmdline_row, 0); | |
3772 msg_clr_eos(); | |
3773 return; | |
3774 } | |
3775 | |
7 | 3776 msg_start(); |
3777 redrawcmdprompt(); | |
3778 | |
3779 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3780 msg_no_more = TRUE; | |
3781 draw_cmdline(0, ccline.cmdlen); | |
3782 msg_clr_eos(); | |
3783 msg_no_more = FALSE; | |
3784 | |
3785 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
|
3786 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
|
3787 putcmdline(extra_char, extra_char_shift); |
7 | 3788 |
3789 /* | |
3790 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3791 * in cmdline mode we can reset them now. | |
3792 */ | |
3793 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3794 | |
3795 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3796 * in cmdline mode */ | |
3797 skip_redraw = FALSE; | |
3798 } | |
3799 | |
3800 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3801 compute_cmdrow(void) |
7 | 3802 { |
540 | 3803 if (exmode_active || msg_scrolled != 0) |
7 | 3804 cmdline_row = Rows - 1; |
3805 else | |
3806 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
|
3807 + lastwin->w_status_height; |
7 | 3808 } |
3809 | |
3810 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3811 cursorcmd(void) |
7 | 3812 { |
3813 if (cmd_silent) | |
3814 return; | |
3815 | |
3816 #ifdef FEAT_RIGHTLEFT | |
3817 if (cmdmsg_rl) | |
3818 { | |
3819 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3820 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3821 if (msg_row <= 0) | |
3822 msg_row = Rows - 1; | |
3823 } | |
3824 else | |
3825 #endif | |
3826 { | |
3827 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3828 msg_col = ccline.cmdspos % (int)Columns; | |
3829 if (msg_row >= Rows) | |
3830 msg_row = Rows - 1; | |
3831 } | |
3832 | |
3833 windgoto(msg_row, msg_col); | |
3834 #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
|
3835 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
|
3836 redrawcmd_preedit(); |
7 | 3837 #endif |
3838 #ifdef MCH_CURSOR_SHAPE | |
3839 mch_update_cursor(); | |
3840 #endif | |
3841 } | |
3842 | |
3843 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3844 gotocmdline(int clr) |
7 | 3845 { |
3846 msg_start(); | |
3847 #ifdef FEAT_RIGHTLEFT | |
3848 if (cmdmsg_rl) | |
3849 msg_col = Columns - 1; | |
3850 else | |
3851 #endif | |
3852 msg_col = 0; /* always start in column 0 */ | |
3853 if (clr) /* clear the bottom line(s) */ | |
3854 msg_clr_eos(); /* will reset clear_cmdline */ | |
3855 windgoto(cmdline_row, 0); | |
3856 } | |
3857 | |
3858 /* | |
3859 * Check the word in front of the cursor for an abbreviation. | |
3860 * Called when the non-id character "c" has been entered. | |
3861 * When an abbreviation is recognized it is removed from the text with | |
3862 * backspaces and the replacement string is inserted, followed by "c". | |
3863 */ | |
3864 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3865 ccheck_abbr(int c) |
7 | 3866 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3867 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3868 |
7 | 3869 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3870 return FALSE; | |
3871 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3872 /* 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
|
3873 * 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
|
3874 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
|
3875 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3876 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
|
3877 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3878 && 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
|
3879 && 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
|
3880 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3881 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3882 /* 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
|
3883 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3884 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3885 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3886 } |
3887 | |
3164 | 3888 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3889 static int | |
3890 #ifdef __BORLANDC__ | |
3891 _RTLENTRYF | |
3892 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3893 sort_func_compare(const void *s1, const void *s2) |
3164 | 3894 { |
3895 char_u *p1 = *(char_u **)s1; | |
3896 char_u *p2 = *(char_u **)s2; | |
3897 | |
3898 if (*p1 != '<' && *p2 == '<') return -1; | |
3899 if (*p1 == '<' && *p2 != '<') return 1; | |
3900 return STRCMP(p1, p2); | |
3901 } | |
3902 #endif | |
3903 | |
7 | 3904 /* |
3905 * Return FAIL if this is not an appropriate context in which to do | |
3906 * completion of anything, return OK if it is (even if there are no matches). | |
3907 * For the caller, this means that the character is just passed through like a | |
3908 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3909 */ | |
3910 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3911 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3912 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3913 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3914 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3915 int escape) /* if TRUE, escape the returned matches */ |
7 | 3916 { |
3917 int i, j; | |
3918 char_u *p1; | |
3919 char_u *p2; | |
3920 int difflen; | |
3921 int v; | |
3922 | |
3923 if (xp->xp_numfiles == -1) | |
3924 { | |
3925 set_expand_context(xp); | |
3926 cmd_showtail = expand_showtail(xp); | |
3927 } | |
3928 | |
3929 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3930 { | |
3931 beep_flush(); | |
3932 return OK; /* Something illegal on command line */ | |
3933 } | |
3934 if (xp->xp_context == EXPAND_NOTHING) | |
3935 { | |
3936 /* Caller can use the character as a normal char instead */ | |
3937 return FAIL; | |
3938 } | |
3939 | |
3940 MSG_PUTS("..."); /* show that we are busy */ | |
3941 out_flush(); | |
3942 | |
3943 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3944 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3945 |
3946 if (type == WILD_NEXT || type == WILD_PREV) | |
3947 { | |
3948 /* | |
3949 * Get next/previous match for a previous expanded pattern. | |
3950 */ | |
3951 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3952 } | |
3953 else | |
3954 { | |
3955 /* | |
3956 * Translate string into pattern and expand it. | |
3957 */ | |
1965 | 3958 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3959 xp->xp_context)) == NULL) | |
7 | 3960 p2 = NULL; |
3961 else | |
3962 { | |
2652 | 3963 int use_options = options | |
3961 | 3964 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3965 if (escape) | |
3966 use_options |= WILD_ESCAPE; | |
2652 | 3967 |
3968 if (p_wic) | |
3969 use_options += WILD_ICASE; | |
1965 | 3970 p2 = ExpandOne(xp, p1, |
3971 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3972 use_options, type); |
7 | 3973 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3974 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3975 if (p2 != NULL && type == WILD_LONGEST) |
3976 { | |
1965 | 3977 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3978 if (ccline.cmdbuff[i + j] == '*' |
3979 || ccline.cmdbuff[i + j] == '?') | |
3980 break; | |
3981 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
|
3982 VIM_CLEAR(p2); |
7 | 3983 } |
3984 } | |
3985 } | |
3986 | |
3987 if (p2 != NULL && !got_int) | |
3988 { | |
1965 | 3989 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
|
3990 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3991 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3992 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3993 xp->xp_pattern = ccline.cmdbuff + i; |
3994 } | |
3995 else | |
3996 v = OK; | |
3997 if (v == OK) | |
3998 { | |
323 | 3999 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
4000 &ccline.cmdbuff[ccline.cmdpos], | |
4001 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
4002 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 4003 ccline.cmdlen += difflen; |
4004 ccline.cmdpos += difflen; | |
4005 } | |
4006 } | |
4007 vim_free(p2); | |
4008 | |
4009 redrawcmd(); | |
33 | 4010 cursorcmd(); |
7 | 4011 |
4012 /* When expanding a ":map" command and no matches are found, assume that | |
4013 * the key is supposed to be inserted literally */ | |
4014 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
4015 return FAIL; | |
4016 | |
4017 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
4018 beep_flush(); | |
4019 else if (xp->xp_numfiles == 1) | |
4020 /* free expanded pattern */ | |
4021 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
4022 | |
4023 return OK; | |
4024 } | |
4025 | |
4026 /* | |
4027 * Do wildcard expansion on the string 'str'. | |
4028 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 4029 * Return a pointer to allocated memory containing the new string. |
7 | 4030 * Return NULL for failure. |
4031 * | |
1412 | 4032 * "orig" is the originally expanded string, copied to allocated memory. It |
4033 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
4034 * WILD_PREV "orig" should be NULL. | |
4035 * | |
838 | 4036 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
4037 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 4038 * |
4039 * mode = WILD_FREE: just free previously expanded matches | |
4040 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
4041 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
4042 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
4043 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
4044 * mode = WILD_ALL: return all matches concatenated | |
4045 * mode = WILD_LONGEST: return longest matched part | |
3398 | 4046 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 4047 * |
4048 * options = WILD_LIST_NOTFOUND: list entries without a match | |
4049 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
4050 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
4051 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
4052 * options = WILD_ADD_SLASH: add a slash after directory names | |
4053 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4054 * options = WILD_SILENT: don't print warning messages | |
4055 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4056 * options = WILD_ICASE: ignore case for files |
7 | 4057 * |
4058 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4059 */ | |
4060 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4061 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4062 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4063 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4064 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
|
4065 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4066 int mode) |
7 | 4067 { |
4068 char_u *ss = NULL; | |
4069 static int findex; | |
4070 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4071 int orig_saved = FALSE; |
7 | 4072 int i; |
4073 long_u len; | |
4074 int non_suf_match; /* number without matching suffix */ | |
4075 | |
4076 /* | |
4077 * first handle the case of using an old match | |
4078 */ | |
4079 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4080 { | |
4081 if (xp->xp_numfiles > 0) | |
4082 { | |
4083 if (mode == WILD_PREV) | |
4084 { | |
4085 if (findex == -1) | |
4086 findex = xp->xp_numfiles; | |
4087 --findex; | |
4088 } | |
4089 else /* mode == WILD_NEXT */ | |
4090 ++findex; | |
4091 | |
4092 /* | |
4093 * When wrapping around, return the original string, set findex to | |
4094 * -1. | |
4095 */ | |
4096 if (findex < 0) | |
4097 { | |
4098 if (orig_save == NULL) | |
4099 findex = xp->xp_numfiles - 1; | |
4100 else | |
4101 findex = -1; | |
4102 } | |
4103 if (findex >= xp->xp_numfiles) | |
4104 { | |
4105 if (orig_save == NULL) | |
4106 findex = 0; | |
4107 else | |
4108 findex = -1; | |
4109 } | |
4110 #ifdef FEAT_WILDMENU | |
4111 if (p_wmnu) | |
4112 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4113 findex, cmd_showtail); | |
4114 #endif | |
4115 if (findex == -1) | |
4116 return vim_strsave(orig_save); | |
4117 return vim_strsave(xp->xp_files[findex]); | |
4118 } | |
4119 else | |
4120 return NULL; | |
4121 } | |
4122 | |
1412 | 4123 /* free old names */ |
7 | 4124 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4125 { | |
4126 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4127 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
|
4128 VIM_CLEAR(orig_save); |
7 | 4129 } |
4130 findex = 0; | |
4131 | |
4132 if (mode == WILD_FREE) /* only release file name */ | |
4133 return NULL; | |
4134 | |
4135 if (xp->xp_numfiles == -1) | |
4136 { | |
4137 vim_free(orig_save); | |
4138 orig_save = orig; | |
1432 | 4139 orig_saved = TRUE; |
7 | 4140 |
4141 /* | |
4142 * Do the expansion. | |
4143 */ | |
4144 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4145 options) == FAIL) | |
4146 { | |
4147 #ifdef FNAME_ILLEGAL | |
4148 /* Illegal file name has been silently skipped. But when there | |
4149 * are wildcards, the real problem is that there was no match, | |
4150 * causing the pattern to be added, which has illegal characters. | |
4151 */ | |
4152 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4153 EMSG2(_(e_nomatch2), str); | |
4154 #endif | |
4155 } | |
4156 else if (xp->xp_numfiles == 0) | |
4157 { | |
4158 if (!(options & WILD_SILENT)) | |
4159 EMSG2(_(e_nomatch2), str); | |
4160 } | |
4161 else | |
4162 { | |
4163 /* Escape the matches for use on the command line. */ | |
4164 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4165 | |
4166 /* | |
4167 * Check for matching suffixes in file names. | |
4168 */ | |
3398 | 4169 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4170 && mode != WILD_LONGEST) | |
7 | 4171 { |
4172 if (xp->xp_numfiles) | |
4173 non_suf_match = xp->xp_numfiles; | |
4174 else | |
4175 non_suf_match = 1; | |
4176 if ((xp->xp_context == EXPAND_FILES | |
4177 || xp->xp_context == EXPAND_DIRECTORIES) | |
4178 && xp->xp_numfiles > 1) | |
4179 { | |
4180 /* | |
4181 * More than one match; check suffix. | |
4182 * The files will have been sorted on matching suffix in | |
4183 * expand_wildcards, only need to check the first two. | |
4184 */ | |
4185 non_suf_match = 0; | |
4186 for (i = 0; i < 2; ++i) | |
4187 if (match_suffix(xp->xp_files[i])) | |
4188 ++non_suf_match; | |
4189 } | |
4190 if (non_suf_match != 1) | |
4191 { | |
4192 /* Can we ever get here unless it's while expanding | |
4193 * interactively? If not, we can get rid of this all | |
4194 * together. Don't really want to wait for this message | |
4195 * (and possibly have to hit return to continue!). | |
4196 */ | |
4197 if (!(options & WILD_SILENT)) | |
4198 EMSG(_(e_toomany)); | |
4199 else if (!(options & WILD_NO_BEEP)) | |
4200 beep_flush(); | |
4201 } | |
4202 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4203 ss = vim_strsave(xp->xp_files[0]); | |
4204 } | |
4205 } | |
4206 } | |
4207 | |
4208 /* Find longest common part */ | |
4209 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4210 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4211 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4212 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4213 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4214 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4215 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4216 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4217 if (has_mbyte) |
7 | 4218 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4219 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
|
4220 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
|
4221 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4222 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4223 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4224 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
|
4225 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
|
4226 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4227 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4228 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4229 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
|
4230 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4231 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4232 ci = xp->xp_files[i][len]; |
4242 | 4233 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4234 || xp->xp_context == EXPAND_FILES |
714 | 4235 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4236 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4237 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4238 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4239 break; |
4240 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4241 else if (c0 != ci) |
7 | 4242 break; |
4243 } | |
4244 if (i < xp->xp_numfiles) | |
4245 { | |
4246 if (!(options & WILD_NO_BEEP)) | |
6949 | 4247 vim_beep(BO_WILD); |
7 | 4248 break; |
4249 } | |
4250 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4251 |
7 | 4252 ss = alloc((unsigned)len + 1); |
4253 if (ss) | |
419 | 4254 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4255 findex = -1; /* next p_wc gets first one */ |
4256 } | |
4257 | |
4258 /* Concatenate all matching names */ | |
4259 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4260 { | |
4261 len = 0; | |
4262 for (i = 0; i < xp->xp_numfiles; ++i) | |
4263 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4264 ss = lalloc(len, TRUE); | |
4265 if (ss != NULL) | |
4266 { | |
4267 *ss = NUL; | |
4268 for (i = 0; i < xp->xp_numfiles; ++i) | |
4269 { | |
4270 STRCAT(ss, xp->xp_files[i]); | |
4271 if (i != xp->xp_numfiles - 1) | |
4272 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4273 } | |
4274 } | |
4275 } | |
4276 | |
4277 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4278 ExpandCleanup(xp); | |
4279 | |
1412 | 4280 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4281 if (!orig_saved) |
1412 | 4282 vim_free(orig); |
4283 | |
7 | 4284 return ss; |
4285 } | |
4286 | |
4287 /* | |
4288 * Prepare an expand structure for use. | |
4289 */ | |
4290 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4291 ExpandInit(expand_T *xp) |
7 | 4292 { |
1718 | 4293 xp->xp_pattern = NULL; |
1965 | 4294 xp->xp_pattern_len = 0; |
7 | 4295 xp->xp_backslash = XP_BS_NONE; |
632 | 4296 #ifndef BACKSLASH_IN_FILENAME |
4297 xp->xp_shell = FALSE; | |
4298 #endif | |
7 | 4299 xp->xp_numfiles = -1; |
4300 xp->xp_files = NULL; | |
632 | 4301 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4302 xp->xp_arg = NULL; | |
4303 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4304 xp->xp_line = NULL; |
7 | 4305 } |
4306 | |
4307 /* | |
4308 * Cleanup an expand structure after use. | |
4309 */ | |
4310 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4311 ExpandCleanup(expand_T *xp) |
7 | 4312 { |
4313 if (xp->xp_numfiles >= 0) | |
4314 { | |
4315 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4316 xp->xp_numfiles = -1; | |
4317 } | |
4318 } | |
4319 | |
4320 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4321 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4322 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4323 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4324 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4325 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4326 int options) |
7 | 4327 { |
4328 int i; | |
4329 char_u *p; | |
4330 | |
4331 /* | |
4332 * May change home directory back to "~" | |
4333 */ | |
4334 if (options & WILD_HOME_REPLACE) | |
4335 tilde_replace(str, numfiles, files); | |
4336 | |
4337 if (options & WILD_ESCAPE) | |
4338 { | |
4339 if (xp->xp_context == EXPAND_FILES | |
2778 | 4340 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4341 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4342 || xp->xp_context == EXPAND_BUFFERS |
4343 || xp->xp_context == EXPAND_DIRECTORIES) | |
4344 { | |
4345 /* | |
4346 * Insert a backslash into a file name before a space, \, %, # | |
4347 * and wildmatch characters, except '~'. | |
4348 */ | |
4349 for (i = 0; i < numfiles; ++i) | |
4350 { | |
4351 /* for ":set path=" we need to escape spaces twice */ | |
4352 if (xp->xp_backslash == XP_BS_THREE) | |
4353 { | |
4354 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4355 if (p != NULL) | |
4356 { | |
4357 vim_free(files[i]); | |
4358 files[i] = p; | |
719 | 4359 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4360 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4361 if (p != NULL) | |
4362 { | |
4363 vim_free(files[i]); | |
4364 files[i] = p; | |
4365 } | |
4366 #endif | |
4367 } | |
4368 } | |
1589 | 4369 #ifdef BACKSLASH_IN_FILENAME |
4370 p = vim_strsave_fnameescape(files[i], FALSE); | |
4371 #else | |
1586 | 4372 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4373 #endif |
7 | 4374 if (p != NULL) |
4375 { | |
4376 vim_free(files[i]); | |
4377 files[i] = p; | |
4378 } | |
4379 | |
4380 /* If 'str' starts with "\~", replace "~" at start of | |
4381 * files[i] with "\~". */ | |
4382 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4383 escape_fname(&files[i]); |
7 | 4384 } |
4385 xp->xp_backslash = XP_BS_NONE; | |
435 | 4386 |
4387 /* If the first file starts with a '+' escape it. Otherwise it | |
4388 * could be seen as "+cmd". */ | |
4389 if (*files[0] == '+') | |
4390 escape_fname(&files[0]); | |
7 | 4391 } |
4392 else if (xp->xp_context == EXPAND_TAGS) | |
4393 { | |
4394 /* | |
4395 * Insert a backslash before characters in a tag name that | |
4396 * would terminate the ":tag" command. | |
4397 */ | |
4398 for (i = 0; i < numfiles; ++i) | |
4399 { | |
4400 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4401 if (p != NULL) | |
4402 { | |
4403 vim_free(files[i]); | |
4404 files[i] = p; | |
4405 } | |
4406 } | |
4407 } | |
4408 } | |
4409 } | |
4410 | |
4411 /* | |
1586 | 4412 * Escape special characters in "fname" for when used as a file name argument |
4413 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4414 * Returns the result in allocated memory. | |
4415 */ | |
4416 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4417 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4418 { |
1685 | 4419 char_u *p; |
1586 | 4420 #ifdef BACKSLASH_IN_FILENAME |
4421 char_u buf[20]; | |
4422 int j = 0; | |
4423 | |
5481 | 4424 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4425 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4426 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4427 buf[j++] = *p; |
4428 buf[j] = NUL; | |
1700 | 4429 p = vim_strsave_escaped(fname, buf); |
1586 | 4430 #else |
1685 | 4431 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4432 if (shell && csh_like_shell() && p != NULL) | |
4433 { | |
4434 char_u *s; | |
4435 | |
4436 /* For csh and similar shells need to put two backslashes before '!'. | |
4437 * One is taken by Vim, one by the shell. */ | |
4438 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4439 vim_free(p); | |
4440 p = s; | |
4441 } | |
1700 | 4442 #endif |
4443 | |
4444 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4445 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4446 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4447 escape_fname(&p); |
4448 | |
1685 | 4449 return p; |
1586 | 4450 } |
4451 | |
4452 /* | |
435 | 4453 * Put a backslash before the file name in "pp", which is in allocated memory. |
4454 */ | |
4455 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4456 escape_fname(char_u **pp) |
435 | 4457 { |
4458 char_u *p; | |
4459 | |
4460 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4461 if (p != NULL) | |
4462 { | |
4463 p[0] = '\\'; | |
4464 STRCPY(p + 1, *pp); | |
4465 vim_free(*pp); | |
4466 *pp = p; | |
4467 } | |
4468 } | |
4469 | |
4470 /* | |
7 | 4471 * For each file name in files[num_files]: |
4472 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4473 */ | |
4474 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4475 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4476 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4477 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4478 char_u **files) |
7 | 4479 { |
4480 int i; | |
4481 char_u *p; | |
4482 | |
4483 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4484 { | |
4485 for (i = 0; i < num_files; ++i) | |
4486 { | |
4487 p = home_replace_save(NULL, files[i]); | |
4488 if (p != NULL) | |
4489 { | |
4490 vim_free(files[i]); | |
4491 files[i] = p; | |
4492 } | |
4493 } | |
4494 } | |
4495 } | |
4496 | |
4497 /* | |
4498 * Show all matches for completion on the command line. | |
4499 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4500 * be inserted like a normal character. | |
4501 */ | |
4502 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4503 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4504 { |
4505 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4506 int num_files; | |
4507 char_u **files_found; | |
4508 int i, j, k; | |
4509 int maxlen; | |
4510 int lines; | |
4511 int columns; | |
4512 char_u *p; | |
4513 int lastlen; | |
4514 int attr; | |
4515 int showtail; | |
4516 | |
4517 if (xp->xp_numfiles == -1) | |
4518 { | |
4519 set_expand_context(xp); | |
4520 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4521 &num_files, &files_found); | |
4522 showtail = expand_showtail(xp); | |
4523 if (i != EXPAND_OK) | |
4524 return i; | |
4525 | |
4526 } | |
4527 else | |
4528 { | |
4529 num_files = xp->xp_numfiles; | |
4530 files_found = xp->xp_files; | |
4531 showtail = cmd_showtail; | |
4532 } | |
4533 | |
4534 #ifdef FEAT_WILDMENU | |
4535 if (!wildmenu) | |
4536 { | |
4537 #endif | |
4538 msg_didany = FALSE; /* lines_left will be set */ | |
4539 msg_start(); /* prepare for paging */ | |
4540 msg_putchar('\n'); | |
4541 out_flush(); | |
4542 cmdline_row = msg_row; | |
4543 msg_didany = FALSE; /* lines_left will be set again */ | |
4544 msg_start(); /* prepare for paging */ | |
4545 #ifdef FEAT_WILDMENU | |
4546 } | |
4547 #endif | |
4548 | |
4549 if (got_int) | |
4550 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4551 #ifdef FEAT_WILDMENU | |
4552 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
|
4553 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4554 #endif |
4555 else | |
4556 { | |
4557 /* find the length of the longest file name */ | |
4558 maxlen = 0; | |
4559 for (i = 0; i < num_files; ++i) | |
4560 { | |
4561 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4562 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4563 || xp->xp_context == EXPAND_BUFFERS)) |
4564 { | |
4565 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4566 j = vim_strsize(NameBuff); | |
4567 } | |
4568 else | |
4569 j = vim_strsize(L_SHOWFILE(i)); | |
4570 if (j > maxlen) | |
4571 maxlen = j; | |
4572 } | |
4573 | |
4574 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4575 lines = num_files; | |
4576 else | |
4577 { | |
4578 /* compute the number of columns and lines for the listing */ | |
4579 maxlen += 2; /* two spaces between file names */ | |
4580 columns = ((int)Columns + 2) / maxlen; | |
4581 if (columns < 1) | |
4582 columns = 1; | |
4583 lines = (num_files + columns - 1) / columns; | |
4584 } | |
4585 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4586 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4587 |
4588 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4589 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4590 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4591 msg_clr_eos(); |
4592 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
|
4593 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4594 } |
4595 | |
4596 /* list the files line by line */ | |
4597 for (i = 0; i < lines; ++i) | |
4598 { | |
4599 lastlen = 999; | |
4600 for (k = i; k < num_files; k += lines) | |
4601 { | |
4602 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4603 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4604 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4605 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4606 msg_advance(maxlen + 1); | |
4607 msg_puts(p); | |
4608 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
|
4609 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4610 break; |
4611 } | |
4612 for (j = maxlen - lastlen; --j >= 0; ) | |
4613 msg_putchar(' '); | |
4614 if (xp->xp_context == EXPAND_FILES | |
714 | 4615 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4616 || xp->xp_context == EXPAND_BUFFERS) |
4617 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4618 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4619 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4620 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4621 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4622 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4623 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4624 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4625 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4626 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4627 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
|
4628 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4629 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4630 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4631 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4632 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4633 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4634 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4635 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4636 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4637 j = mch_isdir(files_found[k]); |
7 | 4638 if (showtail) |
4639 p = L_SHOWFILE(k); | |
4640 else | |
4641 { | |
4642 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4643 TRUE); | |
4644 p = NameBuff; | |
4645 } | |
4646 } | |
4647 else | |
4648 { | |
4649 j = FALSE; | |
4650 p = L_SHOWFILE(k); | |
4651 } | |
4652 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4653 } | |
4654 if (msg_col > 0) /* when not wrapped around */ | |
4655 { | |
4656 msg_clr_eos(); | |
4657 msg_putchar('\n'); | |
4658 } | |
4659 out_flush(); /* show one line at a time */ | |
4660 if (got_int) | |
4661 { | |
4662 got_int = FALSE; | |
4663 break; | |
4664 } | |
4665 } | |
4666 | |
4667 /* | |
4668 * we redraw the command below the lines that we have just listed | |
4669 * This is a bit tricky, but it saves a lot of screen updating. | |
4670 */ | |
4671 cmdline_row = msg_row; /* will put it back later */ | |
4672 } | |
4673 | |
4674 if (xp->xp_numfiles == -1) | |
4675 FreeWild(num_files, files_found); | |
4676 | |
4677 return EXPAND_OK; | |
4678 } | |
4679 | |
4680 /* | |
4681 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4682 * Find tail of file name path, but ignore trailing "/". | |
4683 */ | |
4684 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4685 sm_gettail(char_u *s) |
7 | 4686 { |
4687 char_u *p; | |
4688 char_u *t = s; | |
4689 int had_sep = FALSE; | |
4690 | |
4691 for (p = s; *p != NUL; ) | |
4692 { | |
4693 if (vim_ispathsep(*p) | |
4694 #ifdef BACKSLASH_IN_FILENAME | |
4695 && !rem_backslash(p) | |
4696 #endif | |
4697 ) | |
4698 had_sep = TRUE; | |
4699 else if (had_sep) | |
4700 { | |
4701 t = p; | |
4702 had_sep = FALSE; | |
4703 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4704 MB_PTR_ADV(p); |
7 | 4705 } |
4706 return t; | |
4707 } | |
4708 | |
4709 /* | |
4710 * Return TRUE if we only need to show the tail of completion matches. | |
4711 * When not completing file names or there is a wildcard in the path FALSE is | |
4712 * returned. | |
4713 */ | |
4714 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4715 expand_showtail(expand_T *xp) |
7 | 4716 { |
4717 char_u *s; | |
4718 char_u *end; | |
4719 | |
4720 /* When not completing file names a "/" may mean something different. */ | |
714 | 4721 if (xp->xp_context != EXPAND_FILES |
4722 && xp->xp_context != EXPAND_SHELLCMD | |
4723 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4724 return FALSE; |
4725 | |
4726 end = gettail(xp->xp_pattern); | |
4727 if (end == xp->xp_pattern) /* there is no path separator */ | |
4728 return FALSE; | |
4729 | |
4730 for (s = xp->xp_pattern; s < end; s++) | |
4731 { | |
4732 /* Skip escaped wildcards. Only when the backslash is not a path | |
4733 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4734 if (rem_backslash(s)) | |
4735 ++s; | |
4736 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4737 return FALSE; | |
4738 } | |
4739 return TRUE; | |
4740 } | |
4741 | |
4742 /* | |
4743 * Prepare a string for expansion. | |
4744 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4745 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4746 * When expanding other names: The string will be used with regcomp(). Copy |
4747 * the name into allocated memory and prepend "^". | |
4748 */ | |
4749 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4750 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4751 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4752 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4753 int context) /* EXPAND_FILES etc. */ |
7 | 4754 { |
4755 char_u *retval; | |
4756 int i, j; | |
4757 int new_len; | |
4758 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4759 int ends_in_star; |
7 | 4760 |
714 | 4761 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4762 && context != EXPAND_FILES_IN_PATH |
714 | 4763 && context != EXPAND_SHELLCMD |
4764 && context != EXPAND_DIRECTORIES) | |
7 | 4765 { |
4766 /* | |
4767 * Matching will be done internally (on something other than files). | |
4768 * So we convert the file-matching-type wildcards into our kind for | |
4769 * use with vim_regcomp(). First work out how long it will be: | |
4770 */ | |
4771 | |
4772 /* For help tags the translation is done in find_help_tags(). | |
4773 * For a tag pattern starting with "/" no translation is needed. */ | |
4774 if (context == EXPAND_HELP | |
4775 || context == EXPAND_COLORS | |
4776 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4777 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4778 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4779 || 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
|
4780 || ((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
|
4781 || 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
|
4782 && fname[0] == '/')) |
7 | 4783 retval = vim_strnsave(fname, len); |
4784 else | |
4785 { | |
4786 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4787 for (i = 0; i < len; i++) | |
4788 { | |
4789 if (fname[i] == '*' || fname[i] == '~') | |
4790 new_len++; /* '*' needs to be replaced by ".*" | |
4791 '~' needs to be replaced by "\~" */ | |
4792 | |
4793 /* Buffer names are like file names. "." should be literal */ | |
4794 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4795 new_len++; /* "." becomes "\." */ | |
4796 | |
4797 /* Custom expansion takes care of special things, match | |
4798 * backslashes literally (perhaps also for other types?) */ | |
634 | 4799 if ((context == EXPAND_USER_DEFINED |
4800 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4801 new_len++; /* '\' becomes "\\" */ |
4802 } | |
4803 retval = alloc(new_len); | |
4804 if (retval != NULL) | |
4805 { | |
4806 retval[0] = '^'; | |
4807 j = 1; | |
4808 for (i = 0; i < len; i++, j++) | |
4809 { | |
4810 /* Skip backslash. But why? At least keep it for custom | |
4811 * expansion. */ | |
4812 if (context != EXPAND_USER_DEFINED | |
407 | 4813 && context != EXPAND_USER_LIST |
4814 && fname[i] == '\\' | |
4815 && ++i == len) | |
7 | 4816 break; |
4817 | |
4818 switch (fname[i]) | |
4819 { | |
4820 case '*': retval[j++] = '.'; | |
4821 break; | |
4822 case '~': retval[j++] = '\\'; | |
4823 break; | |
4824 case '?': retval[j] = '.'; | |
4825 continue; | |
4826 case '.': if (context == EXPAND_BUFFERS) | |
4827 retval[j++] = '\\'; | |
4828 break; | |
407 | 4829 case '\\': if (context == EXPAND_USER_DEFINED |
4830 || context == EXPAND_USER_LIST) | |
7 | 4831 retval[j++] = '\\'; |
4832 break; | |
4833 } | |
4834 retval[j] = fname[i]; | |
4835 } | |
4836 retval[j] = NUL; | |
4837 } | |
4838 } | |
4839 } | |
4840 else | |
4841 { | |
4842 retval = alloc(len + 4); | |
4843 if (retval != NULL) | |
4844 { | |
419 | 4845 vim_strncpy(retval, fname, len); |
7 | 4846 |
4847 /* | |
831 | 4848 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4849 * * would become **, which walks the whole tree. | |
7 | 4850 * ~ would be at the start of the file name, but not the tail. |
4851 * $ could be anywhere in the tail. | |
4852 * ` could be anywhere in the file name. | |
1484 | 4853 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4854 */ |
4855 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4856 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
|
4857 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4858 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4859 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4860 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4861 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4862 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4863 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4864 #endif |
7 | 4865 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4866 && !ends_in_star |
7 | 4867 && vim_strchr(tail, '$') == NULL |
4868 && vim_strchr(retval, '`') == NULL) | |
4869 retval[len++] = '*'; | |
1484 | 4870 else if (len > 0 && retval[len - 1] == '$') |
4871 --len; | |
7 | 4872 retval[len] = NUL; |
4873 } | |
4874 } | |
4875 return retval; | |
4876 } | |
4877 | |
4878 /* | |
4879 * Must parse the command line so far to work out what context we are in. | |
4880 * Completion can then be done based on that context. | |
4881 * This routine sets the variables: | |
4882 * xp->xp_pattern The start of the pattern to be expanded within | |
4883 * the command line (ends at the cursor). | |
4884 * xp->xp_context The type of thing to expand. Will be one of: | |
4885 * | |
4886 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4887 * the command line, like an unknown command. Caller | |
4888 * should beep. | |
4889 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4890 * a normal char, rather than for completion. eg | |
4891 * :s/^I/ | |
4892 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4893 * it. | |
4894 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4895 * EXPAND_FILES After command with XFILE set, or after setting | |
4896 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4897 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4898 * when we know only directories are of interest. eg | |
4899 * :set dir=^I | |
714 | 4900 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4901 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4902 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4903 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4904 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4905 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4906 * EXPAND_EVENTS Complete event names | |
4907 * EXPAND_SYNTAX Complete :syntax command arguments | |
4908 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4909 * EXPAND_AUGROUP Complete autocommand group names | |
4910 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4911 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4912 * eg :unmap a^I , :cunab x^I | |
4913 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4914 * eg :call sub^I | |
4915 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4916 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4917 * names in expressions, eg :while s^I | |
4918 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4919 * EXPAND_USER Complete user names |
7 | 4920 */ |
4921 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4922 set_expand_context(expand_T *xp) |
7 | 4923 { |
168 | 4924 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4925 if (ccline.cmdfirstc != ':' |
4926 #ifdef FEAT_EVAL | |
168 | 4927 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4928 && !ccline.input_fn |
7 | 4929 #endif |
4930 ) | |
4931 { | |
4932 xp->xp_context = EXPAND_NOTHING; | |
4933 return; | |
4934 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4935 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4936 } |
4937 | |
4938 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4939 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4940 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4941 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
|
4942 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
|
4943 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4944 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4945 { |
4946 int old_char = NUL; | |
4947 char_u *nextcomm; | |
4948 | |
4949 /* | |
4950 * Avoid a UMR warning from Purify, only save the character if it has been | |
4951 * written before. | |
4952 */ | |
4953 if (col < len) | |
4954 old_char = str[col]; | |
4955 str[col] = NUL; | |
4956 nextcomm = str; | |
168 | 4957 |
4958 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4959 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4960 { |
4961 # ifdef FEAT_CMDL_COMPL | |
168 | 4962 /* pass CMD_SIZE because there is no real command */ |
4963 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4964 # endif |
4965 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4966 else if (use_ccline && ccline.input_fn) |
531 | 4967 { |
4968 xp->xp_context = ccline.xp_context; | |
4969 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4970 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4971 xp->xp_arg = ccline.xp_arg; |
1322 | 4972 # endif |
531 | 4973 } |
168 | 4974 else |
4975 #endif | |
4976 while (nextcomm != NULL) | |
4977 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4978 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4979 /* 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
|
4980 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4981 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4982 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4983 |
7 | 4984 str[col] = old_char; |
4985 } | |
4986 | |
4987 /* | |
4988 * Expand the command line "str" from context "xp". | |
4989 * "xp" must have been set by set_cmd_context(). | |
4990 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4991 * starts. | |
4992 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4993 * cursor. | |
4994 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4995 * key that triggered expansion literally. | |
4996 * Returns EXPAND_OK otherwise. | |
4997 */ | |
4998 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4999 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5000 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5001 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
|
5002 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5003 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5004 char_u ***matches) /* return: array of pointers to matches */ |
7 | 5005 { |
5006 char_u *file_str = NULL; | |
2652 | 5007 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 5008 |
5009 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
5010 { | |
5011 beep_flush(); | |
5012 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
5013 } | |
5014 if (xp->xp_context == EXPAND_NOTHING) | |
5015 { | |
5016 /* Caller can use the character as a normal char instead */ | |
5017 return EXPAND_NOTHING; | |
5018 } | |
5019 | |
5020 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 5021 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
5022 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 5023 if (file_str == NULL) |
5024 return EXPAND_UNSUCCESSFUL; | |
5025 | |
2652 | 5026 if (p_wic) |
5027 options += WILD_ICASE; | |
5028 | |
7 | 5029 /* find all files that match the description */ |
2652 | 5030 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 5031 { |
5032 *matchcount = 0; | |
5033 *matches = NULL; | |
5034 } | |
5035 vim_free(file_str); | |
5036 | |
5037 return EXPAND_OK; | |
5038 } | |
5039 | |
5040 #ifdef FEAT_MULTI_LANG | |
5041 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5042 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5043 * 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
|
5044 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 5045 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
5046 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 5047 |
5048 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5049 cleanup_help_tags(int num_file, char_u **file) |
7 | 5050 { |
5051 int i, j; | |
5052 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5053 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5054 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5055 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5056 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
|
5057 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5058 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5059 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5060 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5061 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5062 *p = NUL; |
7 | 5063 |
5064 for (i = 0; i < num_file; ++i) | |
5065 { | |
5066 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
|
5067 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5068 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5069 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5070 { |
5071 /* Sorting on priority means the same item in another language may | |
5072 * be anywhere. Search all items for a match up to the "@en". */ | |
5073 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
|
5074 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
|
5075 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5076 break; |
5077 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5078 /* item only exists with @en, remove it */ |
7 | 5079 file[i][len] = NUL; |
5080 } | |
5081 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5082 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5083 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5084 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
|
5085 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5086 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5087 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5088 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5089 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
|
5090 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5091 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5092 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5093 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5094 } |
7 | 5095 } |
5096 #endif | |
5097 | |
5098 /* | |
5099 * Do the expansion based on xp->xp_context and "pat". | |
5100 */ | |
5101 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5102 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5103 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5104 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5105 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5106 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5107 int options) /* EW_ flags */ |
7 | 5108 { |
5109 #ifdef FEAT_CMDL_COMPL | |
5110 regmatch_T regmatch; | |
5111 #endif | |
5112 int ret; | |
5113 int flags; | |
5114 | |
5115 flags = EW_DIR; /* include directories */ | |
5116 if (options & WILD_LIST_NOTFOUND) | |
5117 flags |= EW_NOTFOUND; | |
5118 if (options & WILD_ADD_SLASH) | |
5119 flags |= EW_ADDSLASH; | |
5120 if (options & WILD_KEEP_ALL) | |
5121 flags |= EW_KEEPALL; | |
5122 if (options & WILD_SILENT) | |
5123 flags |= EW_SILENT; | |
6659 | 5124 if (options & WILD_ALLLINKS) |
5125 flags |= EW_ALLLINKS; | |
7 | 5126 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5127 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5128 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5129 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5130 { |
5131 /* | |
5132 * Expand file or directory names. | |
5133 */ | |
5134 int free_pat = FALSE; | |
5135 int i; | |
5136 | |
5137 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5138 * space */ | |
5139 if (xp->xp_backslash != XP_BS_NONE) | |
5140 { | |
5141 free_pat = TRUE; | |
5142 pat = vim_strsave(pat); | |
5143 for (i = 0; pat[i]; ++i) | |
5144 if (pat[i] == '\\') | |
5145 { | |
5146 if (xp->xp_backslash == XP_BS_THREE | |
5147 && pat[i + 1] == '\\' | |
5148 && pat[i + 2] == '\\' | |
5149 && pat[i + 3] == ' ') | |
1621 | 5150 STRMOVE(pat + i, pat + i + 3); |
7 | 5151 if (xp->xp_backslash == XP_BS_ONE |
5152 && pat[i + 1] == ' ') | |
1621 | 5153 STRMOVE(pat + i, pat + i + 1); |
7 | 5154 } |
5155 } | |
5156 | |
5157 if (xp->xp_context == EXPAND_FILES) | |
5158 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5159 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
|
5160 flags |= (EW_FILE | EW_PATH); |
7 | 5161 else |
5162 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5163 if (options & WILD_ICASE) |
5164 flags |= EW_ICASE; | |
5165 | |
2016 | 5166 /* Expand wildcards, supporting %:h and the like. */ |
5167 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5168 if (free_pat) |
5169 vim_free(pat); | |
5170 return ret; | |
5171 } | |
5172 | |
5173 *file = (char_u **)""; | |
5174 *num_file = 0; | |
5175 if (xp->xp_context == EXPAND_HELP) | |
5176 { | |
1696 | 5177 /* With an empty argument we would get all the help tags, which is |
5178 * very slow. Get matches for "help" instead. */ | |
5179 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5180 num_file, file, FALSE) == OK) | |
7 | 5181 { |
5182 #ifdef FEAT_MULTI_LANG | |
5183 cleanup_help_tags(*num_file, *file); | |
5184 #endif | |
5185 return OK; | |
5186 } | |
5187 return FAIL; | |
5188 } | |
5189 | |
5190 #ifndef FEAT_CMDL_COMPL | |
5191 return FAIL; | |
5192 #else | |
716 | 5193 if (xp->xp_context == EXPAND_SHELLCMD) |
5194 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5195 if (xp->xp_context == EXPAND_OLD_SETTING) |
5196 return ExpandOldSetting(num_file, file); | |
5197 if (xp->xp_context == EXPAND_BUFFERS) | |
5198 return ExpandBufnames(pat, num_file, file, options); | |
5199 if (xp->xp_context == EXPAND_TAGS | |
5200 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5201 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5202 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5203 { |
5204 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5205 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
|
5206 directories); |
2929 | 5207 } |
7 | 5208 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5209 { |
3106 | 5210 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5211 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5212 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5213 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5214 { |
5215 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5216 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5217 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5218 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5219 { |
5220 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
|
5221 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5222 } |
407 | 5223 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5224 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5225 return ExpandUserList(xp, num_file, file); |
407 | 5226 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5227 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5228 return ExpandPackAddDir(pat, num_file, file); |
7 | 5229 |
5230 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5231 if (regmatch.regprog == NULL) | |
5232 return FAIL; | |
5233 | |
5234 /* set ignore-case according to p_ic, p_scs and pat */ | |
5235 regmatch.rm_ic = ignorecase(pat); | |
5236 | |
5237 if (xp->xp_context == EXPAND_SETTINGS | |
5238 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5239 ret = ExpandSettings(xp, ®match, num_file, file); | |
5240 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5241 ret = ExpandMappings(®match, num_file, file); | |
5242 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5243 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5244 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5245 # endif | |
5246 else | |
5247 { | |
5248 static struct expgen | |
5249 { | |
5250 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5251 char_u *((*func)(expand_T *, int)); |
7 | 5252 int ic; |
2849 | 5253 int escaped; |
7 | 5254 } tab[] = |
5255 { | |
2849 | 5256 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5257 {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
|
5258 {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
|
5259 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5260 #ifdef FEAT_CMDHIST |
5261 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5262 #endif | |
7 | 5263 #ifdef FEAT_USR_CMDS |
2849 | 5264 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5265 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5266 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5267 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5268 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5269 #endif |
5270 #ifdef FEAT_EVAL | |
2849 | 5271 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5272 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5273 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5274 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5275 #endif |
5276 #ifdef FEAT_MENU | |
2849 | 5277 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5278 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5279 #endif |
5280 #ifdef FEAT_SYN_HL | |
2849 | 5281 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5282 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5283 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5284 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5285 #endif |
2849 | 5286 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5287 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5288 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5289 #ifdef FEAT_CSCOPE |
2849 | 5290 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5291 #endif |
1868 | 5292 #ifdef FEAT_SIGNS |
2849 | 5293 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5294 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5295 #ifdef FEAT_PROFILE |
2849 | 5296 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5297 #endif |
7 | 5298 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5299 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5300 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5301 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5302 #endif | |
5303 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5304 {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
|
5305 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5306 }; |
5307 int i; | |
5308 | |
5309 /* | |
5310 * Find a context in the table and call the ExpandGeneric() with the | |
5311 * right function to do the expansion. | |
5312 */ | |
5313 ret = FAIL; | |
1880 | 5314 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5315 if (xp->xp_context == tab[i].context) |
5316 { | |
5317 if (tab[i].ic) | |
5318 regmatch.rm_ic = TRUE; | |
2849 | 5319 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5320 tab[i].func, tab[i].escaped); |
7 | 5321 break; |
5322 } | |
5323 } | |
5324 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5325 vim_regfree(regmatch.regprog); |
7 | 5326 |
5327 return ret; | |
5328 #endif /* FEAT_CMDL_COMPL */ | |
5329 } | |
5330 | |
5331 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5332 /* | |
5333 * Expand a list of names. | |
5334 * | |
5335 * Generic function for command line completion. It calls a function to | |
5336 * obtain strings, one by one. The strings are matched against a regexp | |
5337 * program. Matching strings are copied into an array, which is returned. | |
5338 * | |
5339 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5340 */ | |
5341 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5342 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5343 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5344 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5345 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5346 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5347 char_u *((*func)(expand_T *, int)), |
7 | 5348 /* 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
|
5349 int escaped) |
7 | 5350 { |
5351 int i; | |
5352 int count = 0; | |
480 | 5353 int round; |
7 | 5354 char_u *str; |
5355 | |
5356 /* do this loop twice: | |
480 | 5357 * round == 0: count the number of matching names |
5358 * round == 1: copy the matching names into allocated memory | |
7 | 5359 */ |
480 | 5360 for (round = 0; round <= 1; ++round) |
7 | 5361 { |
5362 for (i = 0; ; ++i) | |
5363 { | |
5364 str = (*func)(xp, i); | |
5365 if (str == NULL) /* end of list */ | |
5366 break; | |
5367 if (*str == NUL) /* skip empty strings */ | |
5368 continue; | |
5369 | |
5370 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5371 { | |
480 | 5372 if (round) |
7 | 5373 { |
2849 | 5374 if (escaped) |
5375 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5376 else | |
5377 str = vim_strsave(str); | |
7 | 5378 (*file)[count] = str; |
5379 #ifdef FEAT_MENU | |
5380 if (func == get_menu_names && str != NULL) | |
5381 { | |
5382 /* test for separator added by get_menu_names() */ | |
5383 str += STRLEN(str) - 1; | |
5384 if (*str == '\001') | |
5385 *str = '.'; | |
5386 } | |
5387 #endif | |
5388 } | |
5389 ++count; | |
5390 } | |
5391 } | |
480 | 5392 if (round == 0) |
7 | 5393 { |
5394 if (count == 0) | |
5395 return OK; | |
5396 *num_file = count; | |
5397 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5398 if (*file == NULL) | |
5399 { | |
5400 *file = (char_u **)""; | |
5401 return FAIL; | |
5402 } | |
5403 count = 0; | |
5404 } | |
5405 } | |
480 | 5406 |
828 | 5407 /* Sort the results. Keep menu's in the specified order. */ |
5408 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5409 { |
5410 if (xp->xp_context == EXPAND_EXPRESSION | |
5411 || xp->xp_context == EXPAND_FUNCTIONS | |
5412 || xp->xp_context == EXPAND_USER_FUNC) | |
5413 /* <SNR> functions should be sorted to the end. */ | |
5414 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5415 sort_func_compare); | |
5416 else | |
5417 sort_strings(*file, *num_file); | |
5418 } | |
480 | 5419 |
1322 | 5420 #ifdef FEAT_CMDL_COMPL |
5421 /* Reset the variables used for special highlight names expansion, so that | |
5422 * they don't show up when getting normal highlight names by ID. */ | |
5423 reset_expand_highlight(); | |
5424 #endif | |
5425 | |
7 | 5426 return OK; |
5427 } | |
5428 | |
716 | 5429 /* |
5430 * Complete a shell command. | |
5431 * Returns FAIL or OK; | |
5432 */ | |
5433 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5434 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5435 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
|
5436 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
|
5437 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
|
5438 int flagsarg) /* EW_ flags */ |
716 | 5439 { |
5440 char_u *pat; | |
5441 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5442 char_u *path = NULL; |
716 | 5443 int mustfree = FALSE; |
5444 garray_T ga; | |
5445 char_u *buf = alloc(MAXPATHL); | |
5446 size_t l; | |
5447 char_u *s, *e; | |
5448 int flags = flagsarg; | |
5449 int ret; | |
6695 | 5450 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5451 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5452 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5453 hash_T hash; |
716 | 5454 |
5455 if (buf == NULL) | |
5456 return FAIL; | |
5457 | |
5458 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5459 * space */ | |
5460 pat = vim_strsave(filepat); | |
5461 for (i = 0; pat[i]; ++i) | |
5462 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5463 STRMOVE(pat + i, pat + i + 1); |
716 | 5464 |
6695 | 5465 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5466 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5467 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
|
5468 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5469 path = (char_u *)"."; |
5470 else | |
2630 | 5471 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5472 /* 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
|
5473 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5474 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5475 if (path == NULL) |
5476 path = (char_u *)""; | |
5477 } | |
716 | 5478 |
5479 /* | |
5480 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5481 * collect them in "ga". When "." is not in $PATH also expand for the |
5482 * current directory, to find "subdir/cmd". | |
716 | 5483 */ |
5484 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
|
5485 hash_init(&found_ht); |
6695 | 5486 for (s = path; ; s = e) |
716 | 5487 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5488 #if defined(MSWIN) |
716 | 5489 e = vim_strchr(s, ';'); |
5490 #else | |
5491 e = vim_strchr(s, ':'); | |
5492 #endif | |
5493 if (e == NULL) | |
5494 e = s + STRLEN(s); | |
5495 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5496 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
|
5497 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5498 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
|
5499 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5500 // 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
|
5501 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
|
5502 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5503 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5504 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
|
5505 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5506 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
|
5507 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
|
5508 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5509 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5510 // 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
|
5511 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
|
5512 |
716 | 5513 l = e - s; |
5514 if (l > MAXPATHL - 5) | |
5515 break; | |
5516 vim_strncpy(buf, s, l); | |
5517 add_pathsep(buf); | |
5518 l = STRLEN(buf); | |
5519 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5520 | |
5521 /* Expand matches in one directory of $PATH. */ | |
5522 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5523 if (ret == OK) | |
5524 { | |
5525 if (ga_grow(&ga, *num_file) == FAIL) | |
5526 FreeWild(*num_file, *file); | |
5527 else | |
5528 { | |
5529 for (i = 0; i < *num_file; ++i) | |
5530 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5531 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5532 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5533 if (STRLEN(name) > l) |
716 | 5534 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5535 // 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
|
5536 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5537 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
|
5538 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5539 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5540 // 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
|
5541 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5542 ((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
|
5543 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
|
5544 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5545 } |
716 | 5546 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5547 vim_free(name); |
716 | 5548 } |
5549 vim_free(*file); | |
5550 } | |
5551 } | |
5552 if (*e != NUL) | |
5553 ++e; | |
5554 } | |
5555 *file = ga.ga_data; | |
5556 *num_file = ga.ga_len; | |
5557 | |
5558 vim_free(buf); | |
5559 vim_free(pat); | |
5560 if (mustfree) | |
5561 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5562 hash_clear(&found_ht); |
716 | 5563 return OK; |
5564 } | |
5565 | |
5566 | |
7 | 5567 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5568 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5569 * 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
|
5570 * return the result (either a string or a List). |
7 | 5571 */ |
407 | 5572 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5573 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
|
5574 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
|
5575 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5576 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5577 char_u ***file) |
7 | 5578 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5579 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
|
5580 typval_T args[4]; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5581 sctx_T save_current_sctx = current_sctx; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5582 char_u *pat = NULL; |
407 | 5583 void *ret; |
7 | 5584 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5585 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5586 return NULL; |
7 | 5587 *num_file = 0; |
5588 *file = NULL; | |
5589 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5590 if (ccline.cmdbuff != NULL) |
1518 | 5591 { |
5592 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5593 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5594 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5595 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5596 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
|
5597 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5598 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
|
5599 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
|
5600 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
|
5601 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
|
5602 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
|
5603 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
|
5604 args[3].v_type = VAR_UNKNOWN; |
7 | 5605 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5606 current_sctx = xp->xp_script_ctx; |
13 | 5607 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5608 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5609 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5610 current_sctx = save_current_sctx; |
1518 | 5611 if (ccline.cmdbuff != NULL) |
5612 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5613 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5614 vim_free(pat); |
407 | 5615 return ret; |
5616 } | |
5617 | |
5618 /* | |
5619 * Expand names with a function defined by the user. | |
5620 */ | |
5621 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5622 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5623 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5624 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5625 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5626 char_u ***file) |
407 | 5627 { |
5628 char_u *retstr; | |
5629 char_u *s; | |
5630 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
|
5631 int keep; |
407 | 5632 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
|
5633 int skip; |
407 | 5634 |
5635 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5636 if (retstr == NULL) | |
7 | 5637 return FAIL; |
5638 | |
5639 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5640 for (s = retstr; *s != NUL; s = e) |
7 | 5641 { |
5642 e = vim_strchr(s, '\n'); | |
5643 if (e == NULL) | |
5644 e = s + STRLEN(s); | |
5645 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
|
5646 *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
|
5647 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5648 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
|
5649 *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
|
5650 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5651 if (!skip) |
7 | 5652 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5653 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
|
5654 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5655 ((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
|
5656 ++ga.ga_len; |
7 | 5657 } |
5658 | |
5659 if (*e != NUL) | |
5660 ++e; | |
5661 } | |
407 | 5662 vim_free(retstr); |
5663 *file = ga.ga_data; | |
5664 *num_file = ga.ga_len; | |
5665 return OK; | |
5666 } | |
5667 | |
5668 /* | |
5669 * Expand names with a list returned by a function defined by the user. | |
5670 */ | |
5671 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5672 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5673 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5674 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5675 char_u ***file) |
407 | 5676 { |
5677 list_T *retlist; | |
5678 listitem_T *li; | |
5679 garray_T ga; | |
5680 | |
5681 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5682 if (retlist == NULL) | |
5683 return FAIL; | |
5684 | |
5685 ga_init2(&ga, (int)sizeof(char *), 3); | |
5686 /* Loop over the items in the list. */ | |
5687 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5688 { | |
1917 | 5689 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5690 continue; /* Skip non-string items and empty strings */ | |
407 | 5691 |
5692 if (ga_grow(&ga, 1) == FAIL) | |
5693 break; | |
5694 | |
5695 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5696 vim_strsave(li->li_tv.vval.v_string); |
407 | 5697 ++ga.ga_len; |
5698 } | |
5699 list_unref(retlist); | |
5700 | |
7 | 5701 *file = ga.ga_data; |
5702 *num_file = ga.ga_len; | |
5703 return OK; | |
5704 } | |
5705 #endif | |
5706 | |
5707 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5708 * 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
|
5709 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5711 * 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
|
5712 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5713 * 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
|
5714 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5715 * "dirnames" is an array with one or more directory names. |
7 | 5716 */ |
5717 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5718 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5719 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5720 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5721 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5722 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5723 char *dirnames[]) |
7 | 5724 { |
5725 char_u *s; | |
5726 char_u *e; | |
5873 | 5727 char_u *match; |
7 | 5728 garray_T ga; |
2929 | 5729 int i; |
5730 int pat_len; | |
7 | 5731 |
5732 *num_file = 0; | |
5733 *file = NULL; | |
2931 | 5734 pat_len = (int)STRLEN(pat); |
2929 | 5735 ga_init2(&ga, (int)sizeof(char *), 10); |
5736 | |
5737 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5738 { |
2929 | 5739 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5740 if (s == NULL) | |
5741 { | |
5742 ga_clear_strings(&ga); | |
5743 return FAIL; | |
5744 } | |
5745 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5746 globpath(p_rtp, s, &ga, 0); |
2929 | 5747 vim_free(s); |
5873 | 5748 } |
5749 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5750 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5751 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
|
5752 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5753 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
|
5754 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5755 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5756 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5757 return FAIL; |
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 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
|
5760 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5761 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5762 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5763 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5764 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5765 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5766 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
|
5767 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5768 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
|
5769 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5770 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5771 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5772 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5773 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5774 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
|
5775 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5776 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5777 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5778 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5779 |
5873 | 5780 for (i = 0; i < ga.ga_len; ++i) |
5781 { | |
5782 match = ((char_u **)ga.ga_data)[i]; | |
5783 s = match; | |
5784 e = s + STRLEN(s); | |
5785 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5786 { |
5873 | 5787 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5788 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5789 if (s < match || vim_ispathsep(*s)) |
5790 break; | |
5791 ++s; | |
5792 *e = NUL; | |
5793 mch_memmove(match, s, e - s + 1); | |
7 | 5794 } |
5795 } | |
5873 | 5796 |
2929 | 5797 if (ga.ga_len == 0) |
3628 | 5798 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5799 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5800 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5801 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5802 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5803 |
7 | 5804 *file = ga.ga_data; |
5805 *num_file = ga.ga_len; | |
5806 return OK; | |
5807 } | |
5808 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5809 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5810 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5811 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5812 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5813 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5814 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5815 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5816 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5817 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5818 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5819 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5820 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5821 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5822 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5823 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5824 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5825 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5826 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5827 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5828 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5829 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
|
5830 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5831 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5832 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5833 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5834 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5835 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5836 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5837 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
|
5838 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5839 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5840 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5841 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
|
5842 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5843 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
|
5844 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5845 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5846 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
|
5847 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5848 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5849 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5850 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5851 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5852 /* 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
|
5853 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5854 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5855 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5856 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5857 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5858 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5859 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5860 |
7 | 5861 #endif |
5862 | |
5863 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5864 /* | |
5865 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5866 * Adds the matches to "ga". Caller must init "ga". |
7 | 5867 */ |
5873 | 5868 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5869 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5870 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5871 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5872 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5873 int expand_options) |
7 | 5874 { |
5875 expand_T xpc; | |
5876 char_u *buf; | |
5877 int i; | |
5878 int num_p; | |
5879 char_u **p; | |
5880 | |
5881 buf = alloc(MAXPATHL); | |
5882 if (buf == NULL) | |
5873 | 5883 return; |
7 | 5884 |
632 | 5885 ExpandInit(&xpc); |
7 | 5886 xpc.xp_context = EXPAND_FILES; |
632 | 5887 |
7 | 5888 /* Loop over all entries in {path}. */ |
5889 while (*path != NUL) | |
5890 { | |
5891 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5892 copy_option_part(&path, buf, MAXPATHL, ","); | |
5893 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5894 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5895 # 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
|
5896 /* 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
|
5897 * 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
|
5898 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
|
5899 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5900 # else |
7 | 5901 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
|
5902 # endif |
7 | 5903 STRCAT(buf, file); |
1754 | 5904 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5905 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5906 { |
1754 | 5907 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5908 |
5909 if (ga_grow(ga, num_p) == OK) | |
7 | 5910 { |
5911 for (i = 0; i < num_p; ++i) | |
5912 { | |
5873 | 5913 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5914 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5915 ++ga->ga_len; |
7 | 5916 } |
5917 } | |
5873 | 5918 |
7 | 5919 FreeWild(num_p, p); |
5920 } | |
5921 } | |
5922 } | |
5923 | |
5924 vim_free(buf); | |
5925 } | |
5926 | |
5927 #endif | |
5928 | |
5929 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5930 | |
5931 /********************************* | |
5932 * Command line history stuff * | |
5933 *********************************/ | |
5934 | |
5935 /* | |
5936 * Translate a history character to the associated type number. | |
5937 */ | |
5938 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5939 hist_char2type(int c) |
7 | 5940 { |
5941 if (c == ':') | |
5942 return HIST_CMD; | |
5943 if (c == '=') | |
5944 return HIST_EXPR; | |
5945 if (c == '@') | |
5946 return HIST_INPUT; | |
5947 if (c == '>') | |
5948 return HIST_DEBUG; | |
5949 return HIST_SEARCH; /* must be '?' or '/' */ | |
5950 } | |
5951 | |
5952 /* | |
5953 * Table of history names. | |
5954 * These names are used in :history and various hist...() functions. | |
5955 * It is sufficient to give the significant prefix of a history name. | |
5956 */ | |
5957 | |
5958 static char *(history_names[]) = | |
5959 { | |
5960 "cmd", | |
5961 "search", | |
5962 "expr", | |
5963 "input", | |
5964 "debug", | |
5965 NULL | |
5966 }; | |
5967 | |
3503 | 5968 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5969 /* | |
5970 * Function given to ExpandGeneric() to obtain the possible first | |
5971 * arguments of the ":history command. | |
5972 */ | |
5973 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5974 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5975 { |
5976 static char_u compl[2] = { NUL, NUL }; | |
5977 char *short_names = ":=@>?/"; | |
3529 | 5978 int short_names_count = (int)STRLEN(short_names); |
3503 | 5979 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5980 | |
5981 if (idx < short_names_count) | |
5982 { | |
5983 compl[0] = (char_u)short_names[idx]; | |
5984 return compl; | |
5985 } | |
5986 if (idx < short_names_count + history_name_count) | |
5987 return (char_u *)history_names[idx - short_names_count]; | |
5988 if (idx == short_names_count + history_name_count) | |
5989 return (char_u *)"all"; | |
5990 return NULL; | |
5991 } | |
5992 #endif | |
5993 | |
7 | 5994 /* |
5995 * init_history() - Initialize the command line history. | |
5996 * Also used to re-allocate the history when the size changes. | |
5997 */ | |
356 | 5998 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5999 init_history(void) |
7 | 6000 { |
6001 int newlen; /* new length of history table */ | |
6002 histentry_T *temp; | |
6003 int i; | |
6004 int j; | |
6005 int type; | |
6006 | |
6007 /* | |
6008 * If size of history table changed, reallocate it | |
6009 */ | |
6010 newlen = (int)p_hi; | |
6011 if (newlen != hislen) /* history length changed */ | |
6012 { | |
6013 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
6014 { | |
6015 if (newlen) | |
6016 { | |
6017 temp = (histentry_T *)lalloc( | |
6018 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
6019 if (temp == NULL) /* out of memory! */ | |
6020 { | |
6021 if (type == 0) /* first one: just keep the old length */ | |
6022 { | |
6023 newlen = hislen; | |
6024 break; | |
6025 } | |
6026 /* Already changed one table, now we can only have zero | |
6027 * length for all tables. */ | |
6028 newlen = 0; | |
6029 type = -1; | |
6030 continue; | |
6031 } | |
6032 } | |
6033 else | |
6034 temp = NULL; | |
6035 if (newlen == 0 || temp != NULL) | |
6036 { | |
6037 if (hisidx[type] < 0) /* there are no entries yet */ | |
6038 { | |
6039 for (i = 0; i < newlen; ++i) | |
4258 | 6040 clear_hist_entry(&temp[i]); |
7 | 6041 } |
6042 else if (newlen > hislen) /* array becomes bigger */ | |
6043 { | |
6044 for (i = 0; i <= hisidx[type]; ++i) | |
6045 temp[i] = history[type][i]; | |
6046 j = i; | |
6047 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 6048 clear_hist_entry(&temp[i]); |
7 | 6049 for ( ; j < hislen; ++i, ++j) |
6050 temp[i] = history[type][j]; | |
6051 } | |
6052 else /* array becomes smaller or 0 */ | |
6053 { | |
6054 j = hisidx[type]; | |
6055 for (i = newlen - 1; ; --i) | |
6056 { | |
6057 if (i >= 0) /* copy newest entries */ | |
6058 temp[i] = history[type][j]; | |
6059 else /* remove older entries */ | |
6060 vim_free(history[type][j].hisstr); | |
6061 if (--j < 0) | |
6062 j = hislen - 1; | |
6063 if (j == hisidx[type]) | |
6064 break; | |
6065 } | |
6066 hisidx[type] = newlen - 1; | |
6067 } | |
6068 vim_free(history[type]); | |
6069 history[type] = temp; | |
6070 } | |
6071 } | |
6072 hislen = newlen; | |
6073 } | |
6074 } | |
6075 | |
4258 | 6076 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6077 clear_hist_entry(histentry_T *hisptr) |
4258 | 6078 { |
6079 hisptr->hisnum = 0; | |
6080 hisptr->viminfo = FALSE; | |
6081 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6082 hisptr->time_set = 0; |
4258 | 6083 } |
6084 | |
7 | 6085 /* |
6086 * Check if command line 'str' is already in history. | |
6087 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6088 */ | |
6089 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6090 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6091 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6092 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6093 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
|
6094 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6095 int writing) /* ignore entries read from viminfo */ |
7 | 6096 { |
6097 int i; | |
6098 int last_i = -1; | |
2986 | 6099 char_u *p; |
7 | 6100 |
6101 if (hisidx[type] < 0) | |
6102 return FALSE; | |
6103 i = hisidx[type]; | |
6104 do | |
6105 { | |
6106 if (history[type][i].hisstr == NULL) | |
6107 return FALSE; | |
2986 | 6108 |
6109 /* For search history, check that the separator character matches as | |
6110 * well. */ | |
6111 p = history[type][i].hisstr; | |
6112 if (STRCMP(str, p) == 0 | |
4285 | 6113 && !(writing && history[type][i].viminfo) |
2986 | 6114 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6115 { |
6116 if (!move_to_front) | |
6117 return TRUE; | |
6118 last_i = i; | |
6119 break; | |
6120 } | |
6121 if (--i < 0) | |
6122 i = hislen - 1; | |
6123 } while (i != hisidx[type]); | |
6124 | |
6125 if (last_i >= 0) | |
6126 { | |
6127 str = history[type][i].hisstr; | |
6128 while (i != hisidx[type]) | |
6129 { | |
6130 if (++i >= hislen) | |
6131 i = 0; | |
6132 history[type][last_i] = history[type][i]; | |
6133 last_i = i; | |
6134 } | |
4258 | 6135 history[type][i].hisnum = ++hisnum[type]; |
6136 history[type][i].viminfo = FALSE; | |
7 | 6137 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6138 history[type][i].time_set = vim_time(); |
7 | 6139 return TRUE; |
6140 } | |
6141 return FALSE; | |
6142 } | |
6143 | |
6144 /* | |
6145 * Convert history name (from table above) to its HIST_ equivalent. | |
6146 * When "name" is empty, return "cmd" history. | |
6147 * Returns -1 for unknown history name. | |
6148 */ | |
6149 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6150 get_histtype(char_u *name) |
7 | 6151 { |
6152 int i; | |
6153 int len = (int)STRLEN(name); | |
6154 | |
6155 /* No argument: use current history. */ | |
6156 if (len == 0) | |
6157 return hist_char2type(ccline.cmdfirstc); | |
6158 | |
6159 for (i = 0; history_names[i] != NULL; ++i) | |
6160 if (STRNICMP(name, history_names[i], len) == 0) | |
6161 return i; | |
6162 | |
6163 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6164 return hist_char2type(name[0]); | |
6165 | |
6166 return -1; | |
6167 } | |
6168 | |
6169 static int last_maptick = -1; /* last seen maptick */ | |
6170 | |
6171 /* | |
6172 * Add the given string to the given history. If the string is already in the | |
6173 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6174 * values. | |
6175 */ | |
6176 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6177 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6178 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6179 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6180 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
|
6181 int sep) /* separator character used (search hist) */ |
7 | 6182 { |
6183 histentry_T *hisptr; | |
6184 int len; | |
6185 | |
6186 if (hislen == 0) /* no history */ | |
6187 return; | |
6188 | |
5467 | 6189 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6190 return; | |
6191 | |
7 | 6192 /* |
6193 * Searches inside the same mapping overwrite each other, so that only | |
6194 * the last line is kept. Be careful not to remove a line that was moved | |
6195 * down, only lines that were added. | |
6196 */ | |
6197 if (histype == HIST_SEARCH && in_map) | |
6198 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6199 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6200 { |
6201 /* Current line is from the same mapping, remove it */ | |
6202 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6203 vim_free(hisptr->hisstr); | |
4258 | 6204 clear_hist_entry(hisptr); |
7 | 6205 --hisnum[histype]; |
6206 if (--hisidx[HIST_SEARCH] < 0) | |
6207 hisidx[HIST_SEARCH] = hislen - 1; | |
6208 } | |
6209 last_maptick = -1; | |
6210 } | |
4285 | 6211 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6212 { |
6213 if (++hisidx[histype] == hislen) | |
6214 hisidx[histype] = 0; | |
6215 hisptr = &history[histype][hisidx[histype]]; | |
6216 vim_free(hisptr->hisstr); | |
6217 | |
6218 /* Store the separator after the NUL of the string. */ | |
835 | 6219 len = (int)STRLEN(new_entry); |
7 | 6220 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6221 if (hisptr->hisstr != NULL) | |
6222 hisptr->hisstr[len + 1] = sep; | |
6223 | |
6224 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6225 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6226 hisptr->time_set = vim_time(); |
7 | 6227 if (histype == HIST_SEARCH && in_map) |
6228 last_maptick = maptick; | |
6229 } | |
6230 } | |
6231 | |
6232 #if defined(FEAT_EVAL) || defined(PROTO) | |
6233 | |
6234 /* | |
6235 * Get identifier of newest history entry. | |
6236 * "histype" may be one of the HIST_ values. | |
6237 */ | |
6238 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6239 get_history_idx(int histype) |
7 | 6240 { |
6241 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6242 || hisidx[histype] < 0) | |
6243 return -1; | |
6244 | |
6245 return history[histype][hisidx[histype]].hisnum; | |
6246 } | |
6247 | |
531 | 6248 /* |
7 | 6249 * Calculate history index from a number: |
6250 * num > 0: seen as identifying number of a history entry | |
6251 * num < 0: relative position in history wrt newest entry | |
6252 * "histype" may be one of the HIST_ values. | |
6253 */ | |
6254 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6255 calc_hist_idx(int histype, int num) |
7 | 6256 { |
6257 int i; | |
6258 histentry_T *hist; | |
6259 int wrapped = FALSE; | |
6260 | |
6261 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6262 || (i = hisidx[histype]) < 0 || num == 0) | |
6263 return -1; | |
6264 | |
6265 hist = history[histype]; | |
6266 if (num > 0) | |
6267 { | |
6268 while (hist[i].hisnum > num) | |
6269 if (--i < 0) | |
6270 { | |
6271 if (wrapped) | |
6272 break; | |
6273 i += hislen; | |
6274 wrapped = TRUE; | |
6275 } | |
6276 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6277 return i; | |
6278 } | |
6279 else if (-num <= hislen) | |
6280 { | |
6281 i += num + 1; | |
6282 if (i < 0) | |
6283 i += hislen; | |
6284 if (hist[i].hisstr != NULL) | |
6285 return i; | |
6286 } | |
6287 return -1; | |
6288 } | |
6289 | |
6290 /* | |
6291 * Get a history entry by its index. | |
6292 * "histype" may be one of the HIST_ values. | |
6293 */ | |
6294 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6295 get_history_entry(int histype, int idx) |
7 | 6296 { |
6297 idx = calc_hist_idx(histype, idx); | |
6298 if (idx >= 0) | |
6299 return history[histype][idx].hisstr; | |
6300 else | |
6301 return (char_u *)""; | |
6302 } | |
6303 | |
6304 /* | |
6305 * Clear all entries of a history. | |
6306 * "histype" may be one of the HIST_ values. | |
6307 */ | |
6308 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6309 clr_history(int histype) |
7 | 6310 { |
6311 int i; | |
6312 histentry_T *hisptr; | |
6313 | |
6314 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6315 { | |
6316 hisptr = history[histype]; | |
6317 for (i = hislen; i--;) | |
6318 { | |
6319 vim_free(hisptr->hisstr); | |
4258 | 6320 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6321 hisptr++; |
7 | 6322 } |
6323 hisidx[histype] = -1; /* mark history as cleared */ | |
6324 hisnum[histype] = 0; /* reset identifier counter */ | |
6325 return OK; | |
6326 } | |
6327 return FAIL; | |
6328 } | |
6329 | |
6330 /* | |
6331 * Remove all entries matching {str} from a history. | |
6332 * "histype" may be one of the HIST_ values. | |
6333 */ | |
6334 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6335 del_history_entry(int histype, char_u *str) |
7 | 6336 { |
6337 regmatch_T regmatch; | |
6338 histentry_T *hisptr; | |
6339 int idx; | |
6340 int i; | |
6341 int last; | |
6342 int found = FALSE; | |
6343 | |
6344 regmatch.regprog = NULL; | |
6345 regmatch.rm_ic = FALSE; /* always match case */ | |
6346 if (hislen != 0 | |
6347 && histype >= 0 | |
6348 && histype < HIST_COUNT | |
6349 && *str != NUL | |
6350 && (idx = hisidx[histype]) >= 0 | |
6351 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6352 != NULL) | |
6353 { | |
6354 i = last = idx; | |
6355 do | |
6356 { | |
6357 hisptr = &history[histype][i]; | |
6358 if (hisptr->hisstr == NULL) | |
6359 break; | |
6360 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6361 { | |
6362 found = TRUE; | |
6363 vim_free(hisptr->hisstr); | |
4258 | 6364 clear_hist_entry(hisptr); |
7 | 6365 } |
6366 else | |
6367 { | |
6368 if (i != last) | |
6369 { | |
6370 history[histype][last] = *hisptr; | |
4258 | 6371 clear_hist_entry(hisptr); |
7 | 6372 } |
6373 if (--last < 0) | |
6374 last += hislen; | |
6375 } | |
6376 if (--i < 0) | |
6377 i += hislen; | |
6378 } while (i != idx); | |
6379 if (history[histype][idx].hisstr == NULL) | |
6380 hisidx[histype] = -1; | |
6381 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6382 vim_regfree(regmatch.regprog); |
7 | 6383 return found; |
6384 } | |
6385 | |
6386 /* | |
6387 * Remove an indexed entry from a history. | |
6388 * "histype" may be one of the HIST_ values. | |
6389 */ | |
6390 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6391 del_history_idx(int histype, int idx) |
7 | 6392 { |
6393 int i, j; | |
6394 | |
6395 i = calc_hist_idx(histype, idx); | |
6396 if (i < 0) | |
6397 return FALSE; | |
6398 idx = hisidx[histype]; | |
6399 vim_free(history[histype][i].hisstr); | |
6400 | |
6401 /* When deleting the last added search string in a mapping, reset | |
6402 * last_maptick, so that the last added search string isn't deleted again. | |
6403 */ | |
6404 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6405 last_maptick = -1; | |
6406 | |
6407 while (i != idx) | |
6408 { | |
6409 j = (i + 1) % hislen; | |
6410 history[histype][i] = history[histype][j]; | |
6411 i = j; | |
6412 } | |
4258 | 6413 clear_hist_entry(&history[histype][i]); |
7 | 6414 if (--i < 0) |
6415 i += hislen; | |
6416 hisidx[histype] = i; | |
6417 return TRUE; | |
6418 } | |
6419 | |
6420 #endif /* FEAT_EVAL */ | |
6421 | |
6422 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6423 /* | |
6424 * Very specific function to remove the value in ":set key=val" from the | |
6425 * history. | |
6426 */ | |
6427 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6428 remove_key_from_history(void) |
7 | 6429 { |
6430 char_u *p; | |
6431 int i; | |
6432 | |
6433 i = hisidx[HIST_CMD]; | |
6434 if (i < 0) | |
6435 return; | |
6436 p = history[HIST_CMD][i].hisstr; | |
6437 if (p != NULL) | |
6438 for ( ; *p; ++p) | |
6439 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6440 { | |
6441 p = vim_strchr(p + 3, '='); | |
6442 if (p == NULL) | |
6443 break; | |
6444 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6445 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6446 if (p[i] == '\\' && p[i + 1]) |
6447 ++i; | |
1621 | 6448 STRMOVE(p, p + i); |
7 | 6449 --p; |
6450 } | |
6451 } | |
6452 #endif | |
6453 | |
6454 #endif /* FEAT_CMDHIST */ | |
6455 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6456 #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
|
6457 /* |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
6458 * Get pointer to the command line info to use. save_ccline() may clear |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 * 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
|
6460 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6463 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 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
|
6469 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6472 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6473 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6474 #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
|
6475 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 * 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
|
6477 * 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
|
6478 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 { |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6483 struct cmdline_info *p; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6484 |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6485 if (cmdline_star > 0) |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6486 return NULL; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6487 p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6488 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6489 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6490 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
|
6491 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 * 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
|
6495 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6496 * 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
|
6497 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6498 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6499 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6500 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6501 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6502 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
|
6503 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6504 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6505 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6506 return p->cmdpos; |
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 |
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 * 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
|
6511 * 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
|
6512 * 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
|
6513 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6514 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6515 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6516 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6517 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6518 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
|
6519 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6520 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6521 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6522 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6523 /* 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
|
6524 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6525 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6526 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6527 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6528 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6529 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6530 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6531 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6532 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6533 #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
|
6534 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6535 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6536 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6537 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6538 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6539 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6540 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6541 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6542 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6543 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
|
6544 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6545 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6546 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6547 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6548 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6549 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6550 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6551 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6552 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6553 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6554 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6555 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6556 |
7 | 6557 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6558 /* | |
6559 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6560 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6561 * Returns OK if parsed successfully, otherwise FAIL. | |
6562 */ | |
6563 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6564 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6565 { |
6566 int len; | |
6567 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6568 varnumber_T num; |
7 | 6569 |
6570 *str = skipwhite(*str); | |
6571 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6572 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6573 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6574 *str += len; |
6575 *num1 = (int)num; | |
6576 first = TRUE; | |
6577 } | |
6578 *str = skipwhite(*str); | |
6579 if (**str == ',') /* parse "to" part of range */ | |
6580 { | |
6581 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6582 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6583 if (len > 0) |
6584 { | |
6585 *num2 = (int)num; | |
6586 *str = skipwhite(*str + len); | |
6587 } | |
6588 else if (!first) /* no number given at all */ | |
6589 return FAIL; | |
6590 } | |
6591 else if (first) /* only one number given */ | |
6592 *num2 = *num1; | |
6593 return OK; | |
6594 } | |
6595 #endif | |
6596 | |
6597 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6598 /* | |
6599 * :history command - print a history | |
6600 */ | |
6601 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6602 ex_history(exarg_T *eap) |
7 | 6603 { |
6604 histentry_T *hist; | |
6605 int histype1 = HIST_CMD; | |
6606 int histype2 = HIST_CMD; | |
6607 int hisidx1 = 1; | |
6608 int hisidx2 = -1; | |
6609 int idx; | |
6610 int i, j, k; | |
6611 char_u *end; | |
6612 char_u *arg = eap->arg; | |
6613 | |
6614 if (hislen == 0) | |
6615 { | |
6616 MSG(_("'history' option is zero")); | |
6617 return; | |
6618 } | |
6619 | |
6620 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6621 { | |
6622 end = arg; | |
6623 while (ASCII_ISALPHA(*end) | |
6624 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6625 end++; | |
6626 i = *end; | |
6627 *end = NUL; | |
6628 histype1 = get_histtype(arg); | |
6629 if (histype1 == -1) | |
6630 { | |
1853 | 6631 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6632 { |
6633 histype1 = 0; | |
6634 histype2 = HIST_COUNT-1; | |
6635 } | |
6636 else | |
6637 { | |
6638 *end = i; | |
6639 EMSG(_(e_trailing)); | |
6640 return; | |
6641 } | |
6642 } | |
6643 else | |
6644 histype2 = histype1; | |
6645 *end = i; | |
6646 } | |
6647 else | |
6648 end = arg; | |
6649 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6650 { | |
6651 EMSG(_(e_trailing)); | |
6652 return; | |
6653 } | |
6654 | |
6655 for (; !got_int && histype1 <= histype2; ++histype1) | |
6656 { | |
6657 STRCPY(IObuff, "\n # "); | |
6658 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6659 MSG_PUTS_TITLE(IObuff); | |
6660 idx = hisidx[histype1]; | |
6661 hist = history[histype1]; | |
6662 j = hisidx1; | |
6663 k = hisidx2; | |
6664 if (j < 0) | |
6665 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6666 if (k < 0) | |
6667 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6668 if (idx >= 0 && j <= k) | |
6669 for (i = idx + 1; !got_int; ++i) | |
6670 { | |
6671 if (i == hislen) | |
6672 i = 0; | |
6673 if (hist[i].hisstr != NULL | |
6674 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6675 { | |
6676 msg_putchar('\n'); | |
6677 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6678 hist[i].hisnum); | |
6679 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6680 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6681 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6682 else |
6683 STRCAT(IObuff, hist[i].hisstr); | |
6684 msg_outtrans(IObuff); | |
6685 out_flush(); | |
6686 } | |
6687 if (i == idx) | |
6688 break; | |
6689 } | |
6690 } | |
6691 } | |
6692 #endif | |
6693 | |
6694 #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
|
6695 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6696 * 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
|
6697 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6698 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
|
6699 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6700 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
|
6701 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6702 static int viminfo_add_at_front = FALSE; |
6703 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6704 static int hist_type2char(int type, int use_question); |
7 | 6705 |
6706 /* | |
6707 * Translate a history type number to the associated character. | |
6708 */ | |
6709 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6710 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6711 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6712 int use_question) /* use '?' instead of '/' */ |
7 | 6713 { |
6714 if (type == HIST_CMD) | |
6715 return ':'; | |
6716 if (type == HIST_SEARCH) | |
6717 { | |
6718 if (use_question) | |
6719 return '?'; | |
6720 else | |
6721 return '/'; | |
6722 } | |
6723 if (type == HIST_EXPR) | |
6724 return '='; | |
6725 return '@'; | |
6726 } | |
6727 | |
6728 /* | |
6729 * Prepare for reading the history from the viminfo file. | |
6730 * This allocates history arrays to store the read history lines. | |
6731 */ | |
6732 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6733 prepare_viminfo_history(int asklen, int writing) |
7 | 6734 { |
6735 int i; | |
6736 int num; | |
6737 int type; | |
6738 int len; | |
6739 | |
6740 init_history(); | |
4285 | 6741 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6742 if (asklen > hislen) |
6743 asklen = hislen; | |
6744 | |
6745 for (type = 0; type < HIST_COUNT; ++type) | |
6746 { | |
4258 | 6747 /* Count the number of empty spaces in the history list. Entries read |
6748 * from viminfo previously are also considered empty. If there are | |
6749 * more spaces available than we request, then fill them up. */ | |
7 | 6750 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6751 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6752 num++; |
6753 len = asklen; | |
6754 if (num > len) | |
6755 len = num; | |
6756 if (len <= 0) | |
6757 viminfo_history[type] = NULL; | |
6758 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6759 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6761 if (viminfo_history[type] == NULL) |
6762 len = 0; | |
6763 viminfo_hislen[type] = len; | |
6764 viminfo_hisidx[type] = 0; | |
6765 } | |
6766 } | |
6767 | |
6768 /* | |
6769 * Accept a line from the viminfo, store it in the history array when it's | |
6770 * new. | |
6771 */ | |
6772 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6773 read_viminfo_history(vir_T *virp, int writing) |
7 | 6774 { |
6775 int type; | |
6776 long_u len; | |
6777 char_u *val; | |
6778 char_u *p; | |
6779 | |
6780 type = hist_char2type(virp->vir_line[0]); | |
6781 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6782 { | |
6783 val = viminfo_readstring(virp, 1, TRUE); | |
6784 if (val != NULL && *val != NUL) | |
6785 { | |
3316 | 6786 int sep = (*val == ' ' ? NUL : *val); |
6787 | |
7 | 6788 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6789 viminfo_add_at_front, sep, writing)) |
7 | 6790 { |
6791 /* Need to re-allocate to append the separator byte. */ | |
6792 len = STRLEN(val); | |
6793 p = lalloc(len + 2, TRUE); | |
6794 if (p != NULL) | |
6795 { | |
6796 if (type == HIST_SEARCH) | |
6797 { | |
6798 /* Search entry: Move the separator from the first | |
6799 * column to after the NUL. */ | |
6800 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6801 p[len] = sep; |
7 | 6802 } |
6803 else | |
6804 { | |
6805 /* Not a search entry: No separator in the viminfo | |
6806 * file, add a NUL separator. */ | |
6807 mch_memmove(p, val, (size_t)len + 1); | |
6808 p[len + 1] = NUL; | |
6809 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 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
|
6811 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
|
6812 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
|
6813 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
|
6814 viminfo_hisidx[type]++; |
7 | 6815 } |
6816 } | |
6817 } | |
6818 vim_free(val); | |
6819 } | |
6820 return viminfo_readline(virp); | |
6821 } | |
6822 | |
4285 | 6823 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6824 * 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
|
6825 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6829 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6830 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6831 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6832 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6834 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6836 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
|
6837 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6838 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6840 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6841 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6842 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6843 || (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
|
6844 || 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
|
6845 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6846 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6847 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6850 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
|
6851 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6852 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6854 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6855 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
|
6856 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6857 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6858 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6859 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6860 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
|
6861 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6862 /* 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
|
6863 * 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
|
6864 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
|
6865 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6866 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6868 && (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
|
6869 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6870 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6871 break; |
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 if (!overwrite) |
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 /* 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
|
6878 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6879 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6880 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6881 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6882 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6883 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6884 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6885 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
|
6886 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6887 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6888 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
|
6889 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6890 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6891 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
|
6892 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 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
|
6894 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6895 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6896 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6897 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6898 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6899 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6900 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6901 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6902 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 * 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
|
6904 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 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
|
6934 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 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
|
6937 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 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
|
6939 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 idx = hislen - 1; |
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 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 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
|
6945 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 } |
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 #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
|
6952 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 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
|
6957 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6958 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 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
|
6962 if (p1->time_set > p2->time_set) return 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6964 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6965 #endif |
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 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6968 * 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
|
6969 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 merge_history(int type) |
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 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6975 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6978 int len; |
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 /* 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
|
6981 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6982 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
|
6983 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
|
6984 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
|
6985 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6986 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6987 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6988 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6989 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6990 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
|
6991 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
|
6992 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6993 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6994 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6995 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6996 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6997 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6998 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
|
6999 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7000 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7001 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7002 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7003 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7004 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7005 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7006 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7007 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7008 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7009 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7010 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7011 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7012 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
7013 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
|
7014 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7015 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7016 for (i = 0; i < viminfo_hisidx[type]; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7017 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
|
7018 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7019 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7020 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7021 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
7022 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7023 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7024 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7025 /* |
4285 | 7026 * Finish reading history lines from viminfo. Not used when writing viminfo. |
7027 */ | |
7 | 7028 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7029 finish_viminfo_history(vir_T *virp) |
7 | 7030 { |
7031 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7032 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 7033 |
7034 for (type = 0; type < HIST_COUNT; ++type) | |
7035 { | |
7036 if (history[type] == NULL) | |
4283 | 7037 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7038 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7039 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7040 merge_history(type); |
7 | 7041 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7042 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
7043 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7044 VIM_CLEAR(viminfo_history[type]); |
4327 | 7045 viminfo_hisidx[type] = 0; |
7 | 7046 } |
7047 } | |
7048 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7049 void |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7050 cmdline_init(void) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7051 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7052 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7053 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
7054 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7055 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7056 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7057 * 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
|
7058 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7059 * 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
|
7060 */ |
7 | 7061 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7062 write_viminfo_history(FILE *fp, int merge) |
7 | 7063 { |
7064 int i; | |
7065 int type; | |
7066 int num_saved; | |
4283 | 7067 int round; |
7 | 7068 |
7069 init_history(); | |
7070 if (hislen == 0) | |
7071 return; | |
7072 for (type = 0; type < HIST_COUNT; ++type) | |
7073 { | |
7074 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7075 if (num_saved == 0) | |
7076 continue; | |
7077 if (num_saved < 0) /* Use default */ | |
7078 num_saved = hislen; | |
7079 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7080 type == HIST_CMD ? _("Command Line") : | |
7081 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7082 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7083 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7084 _("Debug Line")); |
7 | 7085 if (num_saved > hislen) |
7086 num_saved = hislen; | |
4283 | 7087 |
7088 /* | |
7089 * Merge typed and viminfo history: | |
7090 * round 1: history of typed commands. | |
7091 * round 2: history from recently read viminfo. | |
7092 */ | |
7093 for (round = 1; round <= 2; ++round) | |
7094 { | |
4307 | 7095 if (round == 1) |
7096 /* start at newest entry, somewhere in the list */ | |
7097 i = hisidx[type]; | |
7098 else if (viminfo_hisidx[type] > 0) | |
7099 /* start at newest entry, first in the list */ | |
7100 i = 0; | |
7101 else | |
7102 /* empty list */ | |
7103 i = -1; | |
4283 | 7104 if (i >= 0) |
7105 while (num_saved > 0 | |
7106 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7107 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7108 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7109 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7110 int c = NUL; |
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 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7113 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7114 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7115 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7116 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7117 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7118 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7119 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7120 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7121 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7122 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7123 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7124 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7125 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7126 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7127 || !history[type][i].viminfo)) |
7 | 7128 { |
4283 | 7129 --num_saved; |
7130 fputc(hist_type2char(type, TRUE), fp); | |
7131 /* For the search history: put the separator in the | |
7132 * second column; use a space if there isn't one. */ | |
7133 if (type == HIST_SEARCH) | |
7134 { | |
7135 c = p[STRLEN(p) + 1]; | |
7136 putc(c == NUL ? ' ' : c, fp); | |
7137 } | |
7138 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7139 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7140 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7141 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7142 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7143 /* 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
|
7144 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7145 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7146 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7147 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7148 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7149 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
|
7150 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7151 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7152 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7153 } |
7 | 7154 } |
4283 | 7155 if (round == 1) |
7156 { | |
7157 /* Decrement index, loop around and stop when back at | |
7158 * the start. */ | |
7159 if (--i < 0) | |
7160 i = hislen - 1; | |
7161 if (i == hisidx[type]) | |
7162 break; | |
7163 } | |
7164 else | |
7165 { | |
7166 /* Increment index. Stop at the end in the while. */ | |
7167 ++i; | |
7168 } | |
7 | 7169 } |
4283 | 7170 } |
4285 | 7171 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7172 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7173 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
|
7174 VIM_CLEAR(viminfo_history[type]); |
4311 | 7175 viminfo_hisidx[type] = 0; |
7 | 7176 } |
7177 } | |
7178 #endif /* FEAT_VIMINFO */ | |
7179 | |
7180 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7181 /* | |
7182 * Write a character at the current cursor+offset position. | |
7183 * It is directly written into the command buffer block. | |
7184 */ | |
7185 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7186 cmd_pchar(int c, int offset) |
7 | 7187 { |
7188 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7189 { | |
7190 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7191 return; | |
7192 } | |
7193 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7194 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7195 } | |
7196 | |
7197 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7198 cmd_gchar(int offset) |
7 | 7199 { |
7200 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7201 { | |
7202 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7203 return NUL; | |
7204 } | |
7205 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7206 } | |
7207 #endif | |
7208 | |
7209 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7210 /* | |
7211 * Open a window on the current command line and history. Allow editing in | |
7212 * the window. Returns when the window is closed. | |
7213 * Returns: | |
7214 * CR if the command is to be executed | |
7215 * Ctrl_C if it is to be abandoned | |
7216 * K_IGNORE if editing continues | |
7217 */ | |
7218 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
|
7219 open_cmdwin(void) |
7 | 7220 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7221 bufref_T old_curbuf; |
7 | 7222 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7223 bufref_T bufref; |
7 | 7224 win_T *wp; |
7225 int i; | |
7226 linenr_T lnum; | |
7227 int histtype; | |
7228 garray_T winsizes; | |
7229 int save_restart_edit = restart_edit; | |
7230 int save_State = State; | |
7231 int save_exmode = exmode_active; | |
510 | 7232 #ifdef FEAT_RIGHTLEFT |
7233 int save_cmdmsg_rl = cmdmsg_rl; | |
7234 #endif | |
6145 | 7235 #ifdef FEAT_FOLDING |
7236 int save_KeyTyped; | |
7237 #endif | |
7 | 7238 |
7239 /* Can't do this recursively. Can't do it when typing a password. */ | |
7240 if (cmdwin_type != 0 | |
7241 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7242 || cmdline_star > 0 | |
7243 # endif | |
7244 ) | |
7245 { | |
7246 beep_flush(); | |
7247 return K_IGNORE; | |
7248 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7249 set_bufref(&old_curbuf, curbuf); |
7 | 7250 |
7251 /* Save current window sizes. */ | |
7252 win_size_save(&winsizes); | |
7253 | |
7254 /* Don't execute autocommands while creating the window. */ | |
1410 | 7255 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7256 |
683 | 7257 /* don't use a new tab page */ |
7258 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
|
7259 cmdmod.noswapfile = 1; |
683 | 7260 |
7 | 7261 /* Create a window for the command-line buffer. */ |
7262 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7263 { | |
7264 beep_flush(); | |
1410 | 7265 unblock_autocmds(); |
7 | 7266 return K_IGNORE; |
7267 } | |
1831 | 7268 cmdwin_type = get_cmdline_type(); |
7 | 7269 |
7270 /* Create the command-line buffer empty. */ | |
1743 | 7271 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7272 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7273 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7274 curbuf->b_p_ma = TRUE; | |
1865 | 7275 #ifdef FEAT_FOLDING |
7276 curwin->w_p_fen = FALSE; | |
7277 #endif | |
7 | 7278 # ifdef FEAT_RIGHTLEFT |
510 | 7279 curwin->w_p_rl = cmdmsg_rl; |
7280 cmdmsg_rl = FALSE; | |
7 | 7281 # endif |
2583 | 7282 RESET_BINDING(curwin); |
7 | 7283 |
7284 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7285 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7286 /* 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
|
7287 ++curbuf_lock; |
7 | 7288 |
510 | 7289 /* Showing the prompt may have set need_wait_return, reset it. */ |
7290 need_wait_return = FALSE; | |
7291 | |
1831 | 7292 histtype = hist_char2type(cmdwin_type); |
7 | 7293 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7294 { | |
7295 if (p_wc == TAB) | |
7296 { | |
7297 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7298 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7299 } | |
7300 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7301 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7302 --curbuf_lock; |
7 | 7303 |
10 | 7304 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7305 * sets 'textwidth' to 78). */ | |
7306 curbuf->b_p_tw = 0; | |
7307 | |
7 | 7308 /* Fill the buffer with the history. */ |
7309 init_history(); | |
7310 if (hislen > 0) | |
7311 { | |
7312 i = hisidx[histtype]; | |
7313 if (i >= 0) | |
7314 { | |
7315 lnum = 0; | |
7316 do | |
7317 { | |
7318 if (++i == hislen) | |
7319 i = 0; | |
7320 if (history[histtype][i].hisstr != NULL) | |
7321 ml_append(lnum++, history[histtype][i].hisstr, | |
7322 (colnr_T)0, FALSE); | |
7323 } | |
7324 while (i != hisidx[histtype]); | |
7325 } | |
7326 } | |
7327 | |
7328 /* Replace the empty last line with the current command-line and put the | |
7329 * cursor there. */ | |
7330 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7331 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7332 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7333 changed_line_abv_curs(); |
7334 invalidate_botline(); | |
743 | 7335 redraw_later(SOME_VALID); |
7 | 7336 |
7337 /* No Ex mode here! */ | |
7338 exmode_active = 0; | |
7339 | |
7340 State = NORMAL; | |
7341 # ifdef FEAT_MOUSE | |
7342 setmouse(); | |
7343 # endif | |
7344 | |
7345 /* 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
|
7346 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7347 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7348 stuffcharReadbuff(K_NOP); | |
7 | 7349 |
7350 i = RedrawingDisabled; | |
7351 RedrawingDisabled = 0; | |
7352 | |
7353 /* | |
7354 * Call the main loop until <CR> or CTRL-C is typed. | |
7355 */ | |
7356 cmdwin_result = 0; | |
168 | 7357 main_loop(TRUE, FALSE); |
7 | 7358 |
7359 RedrawingDisabled = i; | |
7360 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7361 # ifdef FEAT_FOLDING |
6145 | 7362 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7363 # endif |
6145 | 7364 |
7 | 7365 /* 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
|
7366 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7367 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7368 # ifdef FEAT_FOLDING |
6145 | 7369 /* Restore KeyTyped in case it is modified by autocommands */ |
7370 KeyTyped = save_KeyTyped; | |
7 | 7371 # endif |
7372 | |
7373 cmdwin_type = 0; | |
7374 exmode_active = save_exmode; | |
7375 | |
1612 | 7376 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7377 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7378 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7379 { |
7380 cmdwin_result = Ctrl_C; | |
7381 EMSG(_("E199: Active window or buffer deleted")); | |
7382 } | |
7383 else | |
7384 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7385 # if defined(FEAT_EVAL) |
7 | 7386 /* autocmds may abort script processing */ |
7387 if (aborting() && cmdwin_result != K_IGNORE) | |
7388 cmdwin_result = Ctrl_C; | |
7389 # endif | |
7390 /* Set the new command line from the cmdline buffer. */ | |
7391 vim_free(ccline.cmdbuff); | |
510 | 7392 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7393 { |
510 | 7394 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7395 | |
7396 if (histtype == HIST_CMD) | |
7397 { | |
7398 /* Execute the command directly. */ | |
7399 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7400 cmdwin_result = CAR; | |
7401 } | |
7402 else | |
7403 { | |
7404 /* First need to cancel what we were doing. */ | |
7405 ccline.cmdbuff = NULL; | |
7406 stuffcharReadbuff(':'); | |
7407 stuffReadbuff((char_u *)p); | |
7408 stuffcharReadbuff(CAR); | |
7409 } | |
7 | 7410 } |
7411 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7412 { | |
7413 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7414 cmdwin_result = CAR; | |
7415 } | |
2839 | 7416 else if (cmdwin_result == Ctrl_C) |
7417 { | |
7418 /* :q or :close, don't execute any command | |
7419 * and don't modify the cmd window. */ | |
7420 ccline.cmdbuff = NULL; | |
7421 } | |
7 | 7422 else |
7423 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7424 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
|
7425 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7426 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
|
7427 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
|
7428 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
|
7429 ccline.cmdpos = 0; |
7 | 7430 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
|
7431 } |
7 | 7432 else |
7433 { | |
7434 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7435 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7436 ccline.cmdpos = curwin->w_cursor.col; | |
7437 if (ccline.cmdpos > ccline.cmdlen) | |
7438 ccline.cmdpos = ccline.cmdlen; | |
7439 if (cmdwin_result == K_IGNORE) | |
7440 { | |
7441 set_cmdspos_cursor(); | |
7442 redrawcmd(); | |
7443 } | |
7444 } | |
7445 | |
7446 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7447 block_autocmds(); |
6876 | 7448 # ifdef FEAT_CONCEAL |
7449 /* Avoid command-line window first character being concealed. */ | |
7450 curwin->w_p_cole = 0; | |
7451 # endif | |
7 | 7452 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7453 set_bufref(&bufref, curbuf); |
7 | 7454 win_goto(old_curwin); |
7455 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7456 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7457 /* 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
|
7458 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7459 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7460 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7461 |
7462 /* Restore window sizes. */ | |
7463 win_size_restore(&winsizes); | |
7464 | |
1410 | 7465 unblock_autocmds(); |
7 | 7466 } |
7467 | |
7468 ga_clear(&winsizes); | |
7469 restart_edit = save_restart_edit; | |
510 | 7470 # ifdef FEAT_RIGHTLEFT |
7471 cmdmsg_rl = save_cmdmsg_rl; | |
7472 # endif | |
7 | 7473 |
7474 State = save_State; | |
7475 # ifdef FEAT_MOUSE | |
7476 setmouse(); | |
7477 # endif | |
7478 | |
7479 return cmdwin_result; | |
7480 } | |
7481 #endif /* FEAT_CMDWIN */ | |
7482 | |
7483 /* | |
7484 * Used for commands that either take a simple command string argument, or: | |
7485 * cmd << endmarker | |
7486 * {script} | |
7487 * endmarker | |
7488 * Returns a pointer to allocated memory with {script} or NULL. | |
7489 */ | |
7490 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7491 script_get(exarg_T *eap, char_u *cmd) |
7 | 7492 { |
7493 char_u *theline; | |
7494 char *end_pattern = NULL; | |
7495 char dot[] = "."; | |
7496 garray_T ga; | |
7497 | |
7498 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7499 return NULL; | |
7500 | |
7501 ga_init2(&ga, 1, 0x400); | |
7502 | |
7503 if (cmd[2] != NUL) | |
7504 end_pattern = (char *)skipwhite(cmd + 2); | |
7505 else | |
7506 end_pattern = dot; | |
7507 | |
7508 for (;;) | |
7509 { | |
7510 theline = eap->getline( | |
7511 #ifdef FEAT_EVAL | |
75 | 7512 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7513 #endif |
7514 NUL, eap->cookie, 0); | |
7515 | |
7516 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7517 { |
7518 vim_free(theline); | |
7 | 7519 break; |
1694 | 7520 } |
7 | 7521 |
7522 ga_concat(&ga, theline); | |
7523 ga_append(&ga, '\n'); | |
7524 vim_free(theline); | |
7525 } | |
21 | 7526 ga_append(&ga, NUL); |
7 | 7527 |
7528 return (char_u *)ga.ga_data; | |
7529 } |