Mercurial > vim
annotate src/ex_getln.c @ 14503:4825955cb706 v8.1.0265
patch 8.1.0265: the getcmdline() function is way too big
commit https://github.com/vim/vim/commit/0ee81cb63876e6ec1b2a6e0125295b43f1c63c7d
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 10 22:07:32 2018 +0200
patch 8.1.0265: the getcmdline() function is way too big
Problem: The getcmdline() function is way too big.
Solution: Factor out the incremental search highlighting.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 10 Aug 2018 22:15:05 +0200 |
parents | e4c553e9132b |
children | 3648e74dd523 |
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 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
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
|
55 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
|
56 * 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
|
57 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
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 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
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 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
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #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
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 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
|
119 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
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # 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
|
125 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
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #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
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 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
|
147 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
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 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
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 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
|
152 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
|
153 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
|
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 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * 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
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 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
|
160 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
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 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
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #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
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * 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
|
172 * 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
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 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
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 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
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* 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
|
180 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
|
181 && 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
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 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
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // 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
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
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_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 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
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 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
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 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
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 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
|
208 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
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 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
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 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
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 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
|
221 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
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // 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
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 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
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * 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
|
251 * 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
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 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
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 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
|
261 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
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
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 * Return TRUE when 'incsearch' highlighting is to be done. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
267 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 do_incsearch_highlighting(int firstc) |
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 return p_is && !cmd_silent && (firstc == '/' || firstc == '?'); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
273 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
274 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
275 * 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
|
276 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
277 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
278 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
|
279 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
280 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
281 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
|
282 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
283 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
284 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
|
285 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
286 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
287 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
288 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
289 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
290 if (!do_incsearch_highlighting(firstc)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
291 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
292 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
293 // 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
|
294 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
295 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
296 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
|
297 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
298 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
299 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
|
300 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
301 // start at old position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
302 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
|
303 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
304 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
305 // If there is no command line, don't do anything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
306 if (ccline.cmdlen == 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
307 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
308 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
309 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
|
310 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
|
311 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
312 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
313 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
314 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
|
315 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
316 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
|
317 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
318 ++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
|
319 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
320 // 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
|
321 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
|
322 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
323 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
324 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
|
325 i = do_search(NULL, firstc, ccline.cmdbuff, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
326 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
327 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
328 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
329 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
330 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
331 ); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
332 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
333 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
334 // 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
|
335 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
336 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
337 (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
|
338 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
339 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
340 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
341 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
|
342 // 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
|
343 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
|
344 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
345 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
346 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
|
347 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
348 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
|
349 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
350 // 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
|
351 // 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
|
352 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
|
353 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
|
354 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
355 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
356 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
357 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
358 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
|
359 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
360 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
|
361 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
|
362 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
367 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
368 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
|
369 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
370 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
371 // Avoids a flash when typing "foo\|". |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
372 if (empty_pattern(ccline.cmdbuff)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
373 set_no_hlsearch(TRUE); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
374 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
375 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
376 // 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
|
377 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
|
378 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
|
379 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
380 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
381 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
|
382 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
383 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
|
384 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
385 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
386 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
387 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
|
388 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
389 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
390 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
391 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
|
392 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
393 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
394 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
395 * 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
|
396 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 * 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
|
398 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 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
|
401 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
402 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
403 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
|
404 int c) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
405 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
406 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
407 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
408 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
|
409 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
410 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
411 if (!do_incsearch_highlighting(firstc)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
412 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 if (ccline.cmdlen == 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
414 return FAIL; |
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 if (firstc == ccline.cmdbuff[0]) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
417 pat = last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
418 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 pat = ccline.cmdbuff; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
420 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
421 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
422 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
423 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
424 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
|
425 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 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
|
427 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
|
428 // 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
|
429 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
430 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
431 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
|
432 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
433 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
434 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
|
435 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
436 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
|
437 ++emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 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
|
442 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
444 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
445 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
|
446 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
|
447 is_state->match_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 if (c == Ctrl_T && firstc == '/') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 // 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
|
451 // 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
|
452 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
|
453 (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
|
454 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 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
|
456 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 // 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
|
458 // 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
|
459 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
|
460 (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
|
461 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 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
|
463 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
464 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 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
|
466 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 (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
|
468 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 (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
|
470 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 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
|
479 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
|
480 redrawcmdline(); |
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 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 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
|
484 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
|
485 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 |
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 * 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
|
490 * 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
|
491 * 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
|
492 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
493 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
494 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
|
495 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 if (!do_incsearch_highlighting(firstc)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
499 // 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
|
500 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
|
501 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 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
|
503 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
|
504 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
507 // 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
|
508 // 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
|
509 // the character to lowercase. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 *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
|
512 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 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
|
515 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
|
516 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 // 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
|
518 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 finish_incsearch_highlighting(int gotesc, 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
|
530 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 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
|
532 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 if (gotesc) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 if (!EQUAL_POS(is_state->save_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
|
538 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 // put the '" mark at the original position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 setpcmark(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 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
|
544 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
545 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
|
546 highlight_match = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 validate_cursor(); /* needed for TAB */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 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
|
549 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
551 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
552 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
553 /* |
7 | 554 * getcmdline() - accept a command line starting with firstc. |
555 * | |
556 * firstc == ':' get ":" command line. | |
557 * firstc == '/' or '?' get search pattern | |
558 * firstc == '=' get expression | |
559 * firstc == '@' get text for input() function | |
560 * firstc == '>' get text for debug mode | |
561 * firstc == NUL get text for :insert command | |
562 * firstc == -1 like NUL, and break on CTRL-C | |
563 * | |
564 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
565 * command line. | |
566 * | |
567 * Careful: getcmdline() can be called recursively! | |
568 * | |
569 * Return pointer to allocated string if there is a commandline, NULL | |
570 * otherwise. | |
571 */ | |
572 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
573 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
574 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
575 long count UNUSED, /* only used for incremental search */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
576 int indent) /* indent for inside conditionals */ |
7 | 577 { |
578 int c; | |
579 int i; | |
580 int j; | |
581 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
582 int do_abbr; /* when TRUE check for abbr. */ | |
583 #ifdef FEAT_CMDHIST | |
584 char_u *lookfor = NULL; /* string to match */ | |
585 int hiscnt; /* current history line in use */ | |
586 int histype; /* history type to be used */ | |
587 #endif | |
588 #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
|
589 incsearch_state_T is_state; |
7 | 590 #endif |
591 int did_wild_list = FALSE; /* did wild_list() recently */ | |
592 int wim_index = 0; /* index in wim_flags[] */ | |
593 int res; | |
594 int save_msg_scroll = msg_scroll; | |
595 int save_State = State; /* remember State when called */ | |
596 int some_key_typed = FALSE; /* one of the keys was typed */ | |
597 #ifdef FEAT_MOUSE | |
598 /* mouse drag and release events are ignored, unless they are | |
599 * preceded with a mouse down event */ | |
600 int ignore_drag_release = TRUE; | |
601 #endif | |
602 #ifdef FEAT_EVAL | |
603 int break_ctrl_c = FALSE; | |
604 #endif | |
605 expand_T xpc; | |
606 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 608 /* Everything that may work recursively should save and restore the |
609 * current command line in save_ccline. That includes update_screen(), a | |
610 * custom status line may invoke ":normal". */ | |
611 struct cmdline_info save_ccline; | |
612 #endif | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
613 int cmdline_type; |
7 | 614 |
615 #ifdef FEAT_EVAL | |
616 if (firstc == -1) | |
617 { | |
618 firstc = NUL; | |
619 break_ctrl_c = TRUE; | |
620 } | |
621 #endif | |
622 #ifdef FEAT_RIGHTLEFT | |
623 /* start without Hebrew mapping for a command line */ | |
624 if (firstc == ':' || firstc == '=' || firstc == '>') | |
625 cmd_hkmap = 0; | |
626 #endif | |
627 | |
628 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
|
629 |
7 | 630 #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
|
631 init_incsearch_state(&is_state); |
7 | 632 #endif |
633 | |
634 /* | |
635 * set some variables for redrawcmd() | |
636 */ | |
637 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 638 ccline.cmdindent = (firstc > 0 ? indent : 0); |
639 | |
640 /* alloc initial ccline.cmdbuff */ | |
641 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 642 if (ccline.cmdbuff == NULL) |
643 return NULL; /* out of memory */ | |
644 ccline.cmdlen = ccline.cmdpos = 0; | |
645 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
|
646 sb_text_start_cmdline(); |
7 | 647 |
164 | 648 /* autoindent for :insert and :append */ |
649 if (firstc <= 0) | |
650 { | |
6929 | 651 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 652 ccline.cmdbuff[indent] = NUL; |
653 ccline.cmdpos = indent; | |
654 ccline.cmdspos = indent; | |
655 ccline.cmdlen = indent; | |
656 } | |
657 | |
7 | 658 ExpandInit(&xpc); |
1718 | 659 ccline.xpc = &xpc; |
7 | 660 |
661 #ifdef FEAT_RIGHTLEFT | |
662 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
663 && (firstc == '/' || firstc == '?')) | |
664 cmdmsg_rl = TRUE; | |
665 else | |
666 cmdmsg_rl = FALSE; | |
667 #endif | |
668 | |
669 redir_off = TRUE; /* don't redirect the typed command */ | |
670 if (!cmd_silent) | |
671 { | |
672 i = msg_scrolled; | |
673 msg_scrolled = 0; /* avoid wait_return message */ | |
674 gotocmdline(TRUE); | |
675 msg_scrolled += i; | |
676 redrawcmdprompt(); /* draw prompt or indent */ | |
677 set_cmdspos(); | |
678 } | |
679 xpc.xp_context = EXPAND_NOTHING; | |
680 xpc.xp_backslash = XP_BS_NONE; | |
632 | 681 #ifndef BACKSLASH_IN_FILENAME |
682 xpc.xp_shell = FALSE; | |
683 #endif | |
7 | 684 |
531 | 685 #if defined(FEAT_EVAL) |
686 if (ccline.input_fn) | |
687 { | |
688 xpc.xp_context = ccline.xp_context; | |
689 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 690 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 691 xpc.xp_arg = ccline.xp_arg; |
1322 | 692 # endif |
531 | 693 } |
694 #endif | |
695 | |
7 | 696 /* |
697 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
698 * doing ":@0" when register 0 doesn't contain a CR. | |
699 */ | |
700 msg_scroll = FALSE; | |
701 | |
702 State = CMDLINE; | |
703 | |
704 if (firstc == '/' || firstc == '?' || firstc == '@') | |
705 { | |
706 /* Use ":lmap" mappings for search pattern and input(). */ | |
707 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
708 b_im_ptr = &curbuf->b_p_iminsert; | |
709 else | |
710 b_im_ptr = &curbuf->b_p_imsearch; | |
711 if (*b_im_ptr == B_IMODE_LMAP) | |
712 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
713 #ifdef HAVE_INPUT_METHOD |
7 | 714 im_set_active(*b_im_ptr == B_IMODE_IM); |
715 #endif | |
716 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
717 #ifdef HAVE_INPUT_METHOD |
7 | 718 else if (p_imcmdline) |
719 im_set_active(TRUE); | |
720 #endif | |
721 | |
722 #ifdef FEAT_MOUSE | |
723 setmouse(); | |
724 #endif | |
725 #ifdef CURSOR_SHAPE | |
726 ui_cursor_shape(); /* may show different cursor shape */ | |
727 #endif | |
728 | |
571 | 729 /* When inside an autocommand for writing "exiting" may be set and |
730 * terminal mode set to cooked. Need to set raw mode here then. */ | |
731 settmode(TMODE_RAW); | |
732 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
733 /* 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
|
734 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
|
735 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
|
736 |
7 | 737 #ifdef FEAT_CMDHIST |
738 init_history(); | |
739 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
740 histype = hist_char2type(firstc); | |
741 #endif | |
742 | |
743 #ifdef FEAT_DIGRAPHS | |
1868 | 744 do_digraph(-1); /* init digraph typeahead */ |
7 | 745 #endif |
746 | |
5993 | 747 /* If something above caused an error, reset the flags, we do want to type |
748 * and execute commands. Display may be messed up a bit. */ | |
749 if (did_emsg) | |
750 redrawcmd(); | |
751 did_emsg = FALSE; | |
752 got_int = FALSE; | |
753 | |
7 | 754 /* |
755 * Collect the command string, handling editing keys. | |
756 */ | |
757 for (;;) | |
758 { | |
972 | 759 redir_off = TRUE; /* Don't redirect the typed command. |
760 Repeated, because a ":redir" inside | |
761 completion may switch it on. */ | |
7 | 762 #ifdef USE_ON_FLY_SCROLL |
763 dont_scroll = FALSE; /* allow scrolling here */ | |
764 #endif | |
765 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
766 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 |
7 | 771 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 772 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
773 /* 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
|
774 * anything, such as stop completion. */ |
1472 | 775 do |
776 { | |
777 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
|
778 } while (c == K_IGNORE || c == K_NOP); |
1472 | 779 |
7 | 780 if (KeyTyped) |
781 { | |
782 some_key_typed = TRUE; | |
783 #ifdef FEAT_RIGHTLEFT | |
784 if (cmd_hkmap) | |
785 c = hkmap(c); | |
786 # ifdef FEAT_FKMAP | |
787 if (cmd_fkmap) | |
788 c = cmdl_fkmap(c); | |
789 # endif | |
790 if (cmdmsg_rl && !KeyStuffed) | |
791 { | |
792 /* Invert horizontal movements and operations. Only when | |
793 * typed by the user directly, not when the result of a | |
794 * mapping. */ | |
795 switch (c) | |
796 { | |
797 case K_RIGHT: c = K_LEFT; break; | |
798 case K_S_RIGHT: c = K_S_LEFT; break; | |
799 case K_C_RIGHT: c = K_C_LEFT; break; | |
800 case K_LEFT: c = K_RIGHT; break; | |
801 case K_S_LEFT: c = K_S_RIGHT; break; | |
802 case K_C_LEFT: c = K_C_RIGHT; break; | |
803 } | |
804 } | |
805 #endif | |
806 } | |
807 | |
808 /* | |
809 * Ignore got_int when CTRL-C was typed here. | |
810 * Don't ignore it in :global, we really need to break then, e.g., for | |
811 * ":g/pat/normal /pat" (without the <CR>). | |
812 * Don't ignore it for the input() function. | |
813 */ | |
814 if ((c == Ctrl_C | |
815 #ifdef UNIX | |
816 || c == intr_char | |
817 #endif | |
818 ) | |
819 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
820 && firstc != '@' | |
821 #endif | |
822 #ifdef FEAT_EVAL | |
823 && !break_ctrl_c | |
824 #endif | |
825 && !global_busy) | |
826 got_int = FALSE; | |
827 | |
828 #ifdef FEAT_CMDHIST | |
829 /* free old command line when finished moving around in the history | |
830 * list */ | |
831 if (lookfor != NULL | |
180 | 832 && c != K_S_DOWN && c != K_S_UP |
230 | 833 && c != K_DOWN && c != K_UP |
7 | 834 && c != K_PAGEDOWN && c != K_PAGEUP |
835 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 836 && c != K_LEFT && c != K_RIGHT |
7 | 837 && (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
|
838 VIM_CLEAR(lookfor); |
7 | 839 #endif |
840 | |
841 /* | |
1718 | 842 * When there are matching completions to select <S-Tab> works like |
843 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 844 */ |
1718 | 845 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 846 c = Ctrl_P; |
847 | |
848 #ifdef FEAT_WILDMENU | |
849 /* Special translations for 'wildmenu' */ | |
850 if (did_wild_list && p_wmnu) | |
851 { | |
230 | 852 if (c == K_LEFT) |
7 | 853 c = Ctrl_P; |
230 | 854 else if (c == K_RIGHT) |
7 | 855 c = Ctrl_N; |
856 } | |
857 /* Hitting CR after "emenu Name.": complete submenu */ | |
858 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
859 && ccline.cmdpos > 1 | |
860 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
861 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
862 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
863 c = K_DOWN; | |
864 #endif | |
865 | |
866 /* free expanded names when finished walking through matches */ | |
867 if (xpc.xp_numfiles != -1 | |
868 && !(c == p_wc && KeyTyped) && c != p_wcm | |
869 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
870 && c != Ctrl_L) | |
871 { | |
872 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
873 did_wild_list = FALSE; | |
874 #ifdef FEAT_WILDMENU | |
230 | 875 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 876 #endif |
877 xpc.xp_context = EXPAND_NOTHING; | |
878 wim_index = 0; | |
879 #ifdef FEAT_WILDMENU | |
880 if (p_wmnu && wild_menu_showing != 0) | |
881 { | |
882 int skt = KeyTyped; | |
532 | 883 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 884 |
885 if (ccline.input_fn) | |
886 RedrawingDisabled = 0; | |
7 | 887 |
888 if (wild_menu_showing == WM_SCROLLED) | |
889 { | |
890 /* Entered command line, move it up */ | |
891 cmdline_row--; | |
892 redrawcmd(); | |
893 } | |
894 else if (save_p_ls != -1) | |
895 { | |
896 /* restore 'laststatus' and 'winminheight' */ | |
897 p_ls = save_p_ls; | |
898 p_wmh = save_p_wmh; | |
899 last_status(FALSE); | |
195 | 900 save_cmdline(&save_ccline); |
7 | 901 update_screen(VALID); /* redraw the screen NOW */ |
195 | 902 restore_cmdline(&save_ccline); |
7 | 903 redrawcmd(); |
904 save_p_ls = -1; | |
905 } | |
906 else | |
907 { | |
908 win_redraw_last_status(topframe); | |
909 redraw_statuslines(); | |
910 } | |
532 | 911 KeyTyped = skt; |
912 wild_menu_showing = 0; | |
531 | 913 if (ccline.input_fn) |
914 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 915 } |
916 #endif | |
917 } | |
918 | |
919 #ifdef FEAT_WILDMENU | |
920 /* Special translations for 'wildmenu' */ | |
921 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
922 { | |
923 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 924 if (c == K_DOWN && ccline.cmdpos > 0 |
925 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 926 c = p_wc; |
230 | 927 else if (c == K_UP) |
7 | 928 { |
929 /* Hitting <Up>: Remove one submenu name in front of the | |
930 * cursor */ | |
931 int found = FALSE; | |
932 | |
933 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
934 i = 0; | |
935 while (--j > 0) | |
936 { | |
937 /* check for start of menu name */ | |
938 if (ccline.cmdbuff[j] == ' ' | |
939 && ccline.cmdbuff[j - 1] != '\\') | |
940 { | |
941 i = j + 1; | |
942 break; | |
943 } | |
944 /* check for start of submenu name */ | |
945 if (ccline.cmdbuff[j] == '.' | |
946 && ccline.cmdbuff[j - 1] != '\\') | |
947 { | |
948 if (found) | |
949 { | |
950 i = j + 1; | |
951 break; | |
952 } | |
953 else | |
954 found = TRUE; | |
955 } | |
956 } | |
957 if (i > 0) | |
958 cmdline_del(i); | |
959 c = p_wc; | |
960 xpc.xp_context = EXPAND_NOTHING; | |
961 } | |
962 } | |
714 | 963 if ((xpc.xp_context == EXPAND_FILES |
1621 | 964 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 965 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 966 { |
967 char_u upseg[5]; | |
968 | |
969 upseg[0] = PATHSEP; | |
970 upseg[1] = '.'; | |
971 upseg[2] = '.'; | |
972 upseg[3] = PATHSEP; | |
973 upseg[4] = NUL; | |
974 | |
1318 | 975 if (c == K_DOWN |
976 && ccline.cmdpos > 0 | |
977 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
978 && (ccline.cmdpos < 3 | |
979 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 980 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
981 { | |
982 /* go down a directory */ | |
983 c = p_wc; | |
984 } | |
230 | 985 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 986 { |
987 /* If in a direct ancestor, strip off one ../ to go down */ | |
988 int found = FALSE; | |
989 | |
990 j = ccline.cmdpos; | |
991 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
992 while (--j > i) | |
993 { | |
39 | 994 #ifdef FEAT_MBYTE |
995 if (has_mbyte) | |
996 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
997 #endif | |
7 | 998 if (vim_ispathsep(ccline.cmdbuff[j])) |
999 { | |
1000 found = TRUE; | |
1001 break; | |
1002 } | |
1003 } | |
1004 if (found | |
1005 && ccline.cmdbuff[j - 1] == '.' | |
1006 && ccline.cmdbuff[j - 2] == '.' | |
1007 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1008 { | |
1009 cmdline_del(j - 2); | |
1010 c = p_wc; | |
1011 } | |
1012 } | |
230 | 1013 else if (c == K_UP) |
7 | 1014 { |
1015 /* go up a directory */ | |
1016 int found = FALSE; | |
1017 | |
1018 j = ccline.cmdpos - 1; | |
1019 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1020 while (--j > i) | |
1021 { | |
1022 #ifdef FEAT_MBYTE | |
1023 if (has_mbyte) | |
1024 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1025 #endif | |
1026 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1027 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1028 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1029 ccline.cmdbuff[j + 1]) == NULL |
7 | 1030 #endif |
1031 ) | |
1032 { | |
1033 if (found) | |
1034 { | |
1035 i = j + 1; | |
1036 break; | |
1037 } | |
1038 else | |
1039 found = TRUE; | |
1040 } | |
1041 } | |
1042 | |
1043 if (!found) | |
1044 j = i; | |
1045 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1046 j += 4; | |
1047 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1048 && j == i) | |
1049 j += 3; | |
1050 else | |
1051 j = 0; | |
1052 if (j > 0) | |
1053 { | |
1054 /* TODO this is only for DOS/UNIX systems - need to put in | |
1055 * machine-specific stuff here and in upseg init */ | |
1056 cmdline_del(j); | |
1057 put_on_cmdline(upseg + 1, 3, FALSE); | |
1058 } | |
1059 else if (ccline.cmdpos > i) | |
1060 cmdline_del(i); | |
3204 | 1061 |
1062 /* Now complete in the new directory. Set KeyTyped in case the | |
1063 * Up key came from a mapping. */ | |
7 | 1064 c = p_wc; |
3204 | 1065 KeyTyped = TRUE; |
7 | 1066 } |
1067 } | |
1068 | |
1069 #endif /* FEAT_WILDMENU */ | |
1070 | |
1071 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1072 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1073 if (c == Ctrl_BSL) | |
1074 { | |
1075 ++no_mapping; | |
1076 ++allow_keys; | |
1389 | 1077 c = plain_vgetc(); |
7 | 1078 --no_mapping; |
1079 --allow_keys; | |
3859 | 1080 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1081 * is in a mapping. */ | |
1082 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1083 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1084 { |
1085 vungetc(c); | |
1086 c = Ctrl_BSL; | |
1087 } | |
1088 #ifdef FEAT_EVAL | |
1089 else if (c == 'e') | |
1090 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1091 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1092 int len; |
7 | 1093 |
1094 /* | |
1095 * Replace the command line with the result of an expression. | |
625 | 1096 * Need to save and restore the current command line, to be |
1097 * able to enter a new one... | |
7 | 1098 */ |
1099 if (ccline.cmdpos == ccline.cmdlen) | |
1100 new_cmdpos = 99999; /* keep it at the end */ | |
1101 else | |
1102 new_cmdpos = ccline.cmdpos; | |
95 | 1103 |
1104 save_cmdline(&save_ccline); | |
7 | 1105 c = get_expr_register(); |
95 | 1106 restore_cmdline(&save_ccline); |
7 | 1107 if (c == '=') |
1108 { | |
634 | 1109 /* Need to save and restore ccline. And set "textlock" |
632 | 1110 * to avoid nasty things like going to another buffer when |
1111 * evaluating an expression. */ | |
95 | 1112 save_cmdline(&save_ccline); |
634 | 1113 ++textlock; |
7 | 1114 p = get_expr_line(); |
634 | 1115 --textlock; |
95 | 1116 restore_cmdline(&save_ccline); |
2617 | 1117 |
1118 if (p != NULL) | |
7 | 1119 { |
2617 | 1120 len = (int)STRLEN(p); |
1121 if (realloc_cmdbuff(len + 1) == OK) | |
1122 { | |
1123 ccline.cmdlen = len; | |
1124 STRCPY(ccline.cmdbuff, p); | |
1125 vim_free(p); | |
1126 | |
1127 /* Restore the cursor or use the position set with | |
1128 * set_cmdline_pos(). */ | |
1129 if (new_cmdpos > ccline.cmdlen) | |
1130 ccline.cmdpos = ccline.cmdlen; | |
1131 else | |
1132 ccline.cmdpos = new_cmdpos; | |
1133 | |
1134 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1135 redrawcmd(); | |
1136 goto cmdline_changed; | |
1137 } | |
7 | 1138 } |
1139 } | |
1140 beep_flush(); | |
2636 | 1141 got_int = FALSE; /* don't abandon the command line */ |
1142 did_emsg = FALSE; | |
1143 emsg_on_display = FALSE; | |
1144 redrawcmd(); | |
1145 goto cmdline_not_changed; | |
7 | 1146 } |
1147 #endif | |
1148 else | |
1149 { | |
1150 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1151 restart_edit = 'a'; | |
1152 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1153 in history */ | |
1154 goto returncmd; /* back to Normal mode */ | |
1155 } | |
1156 } | |
1157 | |
1158 #ifdef FEAT_CMDWIN | |
1159 if (c == cedit_key || c == K_CMDWIN) | |
1160 { | |
6211 | 1161 if (ex_normal_busy == 0 && got_int == FALSE) |
1162 { | |
1163 /* | |
1164 * Open a window to edit the command line (and history). | |
1165 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1166 c = open_cmdwin(); |
6211 | 1167 some_key_typed = TRUE; |
1168 } | |
7 | 1169 } |
1170 # ifdef FEAT_DIGRAPHS | |
1171 else | |
1172 # endif | |
1173 #endif | |
1174 #ifdef FEAT_DIGRAPHS | |
1175 c = do_digraph(c); | |
1176 #endif | |
1177 | |
1178 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1179 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1180 { | |
168 | 1181 /* In Ex mode a backslash escapes a newline. */ |
1182 if (exmode_active | |
1183 && c != ESC | |
1318 | 1184 && ccline.cmdpos == ccline.cmdlen |
168 | 1185 && ccline.cmdpos > 0 |
1186 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1187 { | |
1188 if (c == K_KENTER) | |
1189 c = '\n'; | |
1190 } | |
1191 else | |
7 | 1192 { |
168 | 1193 gotesc = FALSE; /* Might have typed ESC previously, don't |
1194 truncate the cmdline now. */ | |
1195 if (ccheck_abbr(c + ABBR_OFF)) | |
1196 goto cmdline_changed; | |
1197 if (!cmd_silent) | |
1198 { | |
1199 windgoto(msg_row, 0); | |
1200 out_flush(); | |
1201 } | |
1202 break; | |
7 | 1203 } |
1204 } | |
1205 | |
1206 /* | |
1207 * Completion for 'wildchar' or 'wildcharm' key. | |
1208 * - hitting <ESC> twice means: abandon command line. | |
1209 * - wildcard expansion is only done when the 'wildchar' key is really | |
1210 * typed, not when it comes from a macro | |
1211 */ | |
1212 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1213 { | |
1214 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1215 { | |
1216 /* if 'wildmode' contains "list" may still need to list */ | |
1217 if (xpc.xp_numfiles > 1 | |
1218 && !did_wild_list | |
1219 && (wim_flags[wim_index] & WIM_LIST)) | |
1220 { | |
1221 (void)showmatches(&xpc, FALSE); | |
1222 redrawcmd(); | |
1223 did_wild_list = TRUE; | |
1224 } | |
1225 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1226 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1227 firstc != '@'); | |
7 | 1228 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1229 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1230 firstc != '@'); | |
7 | 1231 else |
1232 res = OK; /* don't insert 'wildchar' now */ | |
1233 } | |
1234 else /* typed p_wc first time */ | |
1235 { | |
1236 wim_index = 0; | |
1237 j = ccline.cmdpos; | |
1238 /* if 'wildmode' first contains "longest", get longest | |
1239 * common part */ | |
1240 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1241 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1242 firstc != '@'); | |
7 | 1243 else |
3961 | 1244 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1245 firstc != '@'); | |
7 | 1246 |
1247 /* if interrupted while completing, behave like it failed */ | |
1248 if (got_int) | |
1249 { | |
1250 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1251 got_int = FALSE; /* don't abandon the command line */ | |
1252 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1253 #ifdef FEAT_WILDMENU | |
1254 xpc.xp_context = EXPAND_NOTHING; | |
1255 #endif | |
1256 goto cmdline_changed; | |
1257 } | |
1258 | |
1259 /* when more than one match, and 'wildmode' first contains | |
1260 * "list", or no change and 'wildmode' contains "longest,list", | |
1261 * list all matches */ | |
1262 if (res == OK && xpc.xp_numfiles > 1) | |
1263 { | |
1264 /* a "longest" that didn't do anything is skipped (but not | |
1265 * "list:longest") */ | |
1266 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1267 wim_index = 1; | |
1268 if ((wim_flags[wim_index] & WIM_LIST) | |
1269 #ifdef FEAT_WILDMENU | |
1270 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1271 #endif | |
1272 ) | |
1273 { | |
1274 if (!(wim_flags[0] & WIM_LONGEST)) | |
1275 { | |
1276 #ifdef FEAT_WILDMENU | |
1277 int p_wmnu_save = p_wmnu; | |
1278 p_wmnu = 0; | |
1279 #endif | |
3961 | 1280 /* remove match */ |
1281 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1282 #ifdef FEAT_WILDMENU |
1283 p_wmnu = p_wmnu_save; | |
1284 #endif | |
1285 } | |
1286 #ifdef FEAT_WILDMENU | |
1287 (void)showmatches(&xpc, p_wmnu | |
1288 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1289 #else | |
1290 (void)showmatches(&xpc, FALSE); | |
1291 #endif | |
1292 redrawcmd(); | |
1293 did_wild_list = TRUE; | |
1294 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1295 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1296 firstc != '@'); | |
7 | 1297 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1298 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1299 firstc != '@'); | |
7 | 1300 } |
1301 else | |
6949 | 1302 vim_beep(BO_WILD); |
7 | 1303 } |
1304 #ifdef FEAT_WILDMENU | |
1305 else if (xpc.xp_numfiles == -1) | |
1306 xpc.xp_context = EXPAND_NOTHING; | |
1307 #endif | |
1308 } | |
1309 if (wim_index < 3) | |
1310 ++wim_index; | |
1311 if (c == ESC) | |
1312 gotesc = TRUE; | |
1313 if (res == OK) | |
1314 goto cmdline_changed; | |
1315 } | |
1316 | |
1317 gotesc = FALSE; | |
1318 | |
1319 /* <S-Tab> goes to last match, in a clumsy way */ | |
1320 if (c == K_S_TAB && KeyTyped) | |
1321 { | |
3961 | 1322 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1323 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1324 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1325 goto cmdline_changed; |
1326 } | |
1327 | |
1328 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1329 c = NL; | |
1330 | |
1331 do_abbr = TRUE; /* default: check for abbreviation */ | |
1332 | |
1333 /* | |
1334 * Big switch for a typed command line character. | |
1335 */ | |
1336 switch (c) | |
1337 { | |
1338 case K_BS: | |
1339 case Ctrl_H: | |
1340 case K_DEL: | |
1341 case K_KDEL: | |
1342 case Ctrl_W: | |
1343 #ifdef FEAT_FKMAP | |
1344 if (cmd_fkmap && c == K_BS) | |
1345 c = K_DEL; | |
1346 #endif | |
1347 if (c == K_KDEL) | |
1348 c = K_DEL; | |
1349 | |
1350 /* | |
1351 * delete current character is the same as backspace on next | |
1352 * character, except at end of line | |
1353 */ | |
1354 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1355 ++ccline.cmdpos; | |
1356 #ifdef FEAT_MBYTE | |
1357 if (has_mbyte && c == K_DEL) | |
1358 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1359 ccline.cmdbuff + ccline.cmdpos); | |
1360 #endif | |
1361 if (ccline.cmdpos > 0) | |
1362 { | |
1363 char_u *p; | |
1364 | |
1365 j = ccline.cmdpos; | |
1366 p = ccline.cmdbuff + j; | |
1367 #ifdef FEAT_MBYTE | |
1368 if (has_mbyte) | |
1369 { | |
1370 p = mb_prevptr(ccline.cmdbuff, p); | |
1371 if (c == Ctrl_W) | |
1372 { | |
1373 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1374 p = mb_prevptr(ccline.cmdbuff, p); | |
1375 i = mb_get_class(p); | |
1376 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1377 p = mb_prevptr(ccline.cmdbuff, p); | |
1378 if (mb_get_class(p) != i) | |
474 | 1379 p += (*mb_ptr2len)(p); |
7 | 1380 } |
1381 } | |
1382 else | |
1383 #endif | |
1384 if (c == Ctrl_W) | |
1385 { | |
1386 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1387 --p; | |
1388 i = vim_iswordc(p[-1]); | |
1389 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1390 && vim_iswordc(p[-1]) == i) | |
1391 --p; | |
1392 } | |
1393 else | |
1394 --p; | |
1395 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1396 ccline.cmdlen -= j - ccline.cmdpos; | |
1397 i = ccline.cmdpos; | |
1398 while (i < ccline.cmdlen) | |
1399 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1400 | |
1401 /* Truncate at the end, required for multi-byte chars. */ | |
1402 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1403 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1404 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1405 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1406 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
|
1407 /* 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
|
1408 * 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
|
1409 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
|
1410 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1411 #endif |
7 | 1412 redrawcmd(); |
1413 } | |
1414 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1415 && ccline.cmdprompt == NULL && indent == 0) | |
1416 { | |
1417 /* In ex and debug mode it doesn't make sense to return. */ | |
1418 if (exmode_active | |
1419 #ifdef FEAT_EVAL | |
1420 || ccline.cmdfirstc == '>' | |
1421 #endif | |
1422 ) | |
1423 goto cmdline_not_changed; | |
1424 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1425 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1426 if (!cmd_silent) |
1427 { | |
1428 #ifdef FEAT_RIGHTLEFT | |
1429 if (cmdmsg_rl) | |
1430 msg_col = Columns; | |
1431 else | |
1432 #endif | |
1433 msg_col = 0; | |
1434 msg_putchar(' '); /* delete ':' */ | |
1435 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1436 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1437 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
|
1438 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
|
1439 #endif |
7 | 1440 redraw_cmdline = TRUE; |
1441 goto returncmd; /* back to cmd mode */ | |
1442 } | |
1443 goto cmdline_changed; | |
1444 | |
1445 case K_INS: | |
1446 case K_KINS: | |
1447 #ifdef FEAT_FKMAP | |
1448 /* if Farsi mode set, we are in reverse insert mode - | |
1449 Do not change the mode */ | |
1450 if (cmd_fkmap) | |
1451 beep_flush(); | |
1452 else | |
1453 #endif | |
1454 ccline.overstrike = !ccline.overstrike; | |
1455 #ifdef CURSOR_SHAPE | |
1456 ui_cursor_shape(); /* may show different cursor shape */ | |
1457 #endif | |
1458 goto cmdline_not_changed; | |
1459 | |
1460 case Ctrl_HAT: | |
782 | 1461 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1462 { |
1463 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1464 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1465 #ifdef HAVE_INPUT_METHOD |
7 | 1466 im_set_active(FALSE); /* Disable input method */ |
1467 #endif | |
1468 if (b_im_ptr != NULL) | |
1469 { | |
1470 if (State & LANGMAP) | |
1471 *b_im_ptr = B_IMODE_LMAP; | |
1472 else | |
1473 *b_im_ptr = B_IMODE_NONE; | |
1474 } | |
1475 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1476 #ifdef HAVE_INPUT_METHOD |
7 | 1477 else |
1478 { | |
1479 /* There are no ":lmap" mappings, toggle IM. When | |
1480 * 'imdisable' is set don't try getting the status, it's | |
1481 * always off. */ | |
1482 if ((p_imdisable && b_im_ptr != NULL) | |
1483 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1484 { | |
1485 im_set_active(FALSE); /* Disable input method */ | |
1486 if (b_im_ptr != NULL) | |
1487 *b_im_ptr = B_IMODE_NONE; | |
1488 } | |
1489 else | |
1490 { | |
1491 im_set_active(TRUE); /* Enable input method */ | |
1492 if (b_im_ptr != NULL) | |
1493 *b_im_ptr = B_IMODE_IM; | |
1494 } | |
1495 } | |
1496 #endif | |
1497 if (b_im_ptr != NULL) | |
1498 { | |
1499 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1500 set_iminsert_global(); | |
1501 else | |
1502 set_imsearch_global(); | |
1503 } | |
1504 #ifdef CURSOR_SHAPE | |
1505 ui_cursor_shape(); /* may show different cursor shape */ | |
1506 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1507 #if defined(FEAT_KEYMAP) |
7 | 1508 /* Show/unshow value of 'keymap' in status lines later. */ |
1509 status_redraw_curbuf(); | |
1510 #endif | |
1511 goto cmdline_not_changed; | |
1512 | |
1513 /* case '@': only in very old vi */ | |
1514 case Ctrl_U: | |
1515 /* delete all characters left of the cursor */ | |
1516 j = ccline.cmdpos; | |
1517 ccline.cmdlen -= j; | |
1518 i = ccline.cmdpos = 0; | |
1519 while (i < ccline.cmdlen) | |
1520 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1521 /* Truncate at the end, required for multi-byte chars. */ | |
1522 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1523 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1524 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
|
1525 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
|
1526 #endif |
7 | 1527 redrawcmd(); |
1528 goto cmdline_changed; | |
1529 | |
1530 #ifdef FEAT_CLIPBOARD | |
1531 case Ctrl_Y: | |
1532 /* Copy the modeless selection, if there is one. */ | |
1533 if (clip_star.state != SELECT_CLEARED) | |
1534 { | |
1535 if (clip_star.state == SELECT_DONE) | |
1536 clip_copy_modeless_selection(TRUE); | |
1537 goto cmdline_not_changed; | |
1538 } | |
1539 break; | |
1540 #endif | |
1541 | |
1542 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1543 case Ctrl_C: | |
571 | 1544 /* In exmode it doesn't make sense to return. Except when |
161 | 1545 * ":normal" runs out of characters. */ |
1546 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1547 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1548 goto cmdline_not_changed; |
1549 | |
1550 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1551 putting it in history */ | |
1552 goto returncmd; /* back to cmd mode */ | |
1553 | |
1554 case Ctrl_R: /* insert register */ | |
1555 #ifdef USE_ON_FLY_SCROLL | |
1556 dont_scroll = TRUE; /* disallow scrolling here */ | |
1557 #endif | |
1558 putcmdline('"', TRUE); | |
1559 ++no_mapping; | |
1389 | 1560 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1561 if (i == Ctrl_O) |
1562 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1563 if (i == Ctrl_R) | |
1389 | 1564 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
|
1565 extra_char = NUL; |
7 | 1566 --no_mapping; |
1567 #ifdef FEAT_EVAL | |
1568 /* | |
1569 * Insert the result of an expression. | |
1570 * Need to save the current command line, to be able to enter | |
1571 * a new one... | |
1572 */ | |
1573 new_cmdpos = -1; | |
1574 if (c == '=') | |
1575 { | |
1576 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1577 { | |
1578 beep_flush(); | |
1579 c = ESC; | |
1580 } | |
1581 else | |
1582 { | |
95 | 1583 save_cmdline(&save_ccline); |
7 | 1584 c = get_expr_register(); |
95 | 1585 restore_cmdline(&save_ccline); |
7 | 1586 } |
1587 } | |
1588 #endif | |
1589 if (c != ESC) /* use ESC to cancel inserting register */ | |
1590 { | |
1015 | 1591 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1592 |
613 | 1593 #ifdef FEAT_EVAL |
606 | 1594 /* When there was a serious error abort getting the |
1595 * command line. */ | |
1596 if (aborting()) | |
1597 { | |
1598 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1599 putting it in history */ | |
1600 goto returncmd; /* back to cmd mode */ | |
1601 } | |
613 | 1602 #endif |
7 | 1603 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1604 #ifdef FEAT_EVAL | |
1605 if (new_cmdpos >= 0) | |
1606 { | |
1607 /* set_cmdline_pos() was used */ | |
1608 if (new_cmdpos > ccline.cmdlen) | |
1609 ccline.cmdpos = ccline.cmdlen; | |
1610 else | |
1611 ccline.cmdpos = new_cmdpos; | |
1612 } | |
1613 #endif | |
1614 } | |
1615 redrawcmd(); | |
1616 goto cmdline_changed; | |
1617 | |
1618 case Ctrl_D: | |
1619 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1620 break; /* Use ^D as normal char instead */ | |
1621 | |
1622 redrawcmd(); | |
1623 continue; /* don't do incremental search now */ | |
1624 | |
1625 case K_RIGHT: | |
1626 case K_S_RIGHT: | |
1627 case K_C_RIGHT: | |
1628 do | |
1629 { | |
1630 if (ccline.cmdpos >= ccline.cmdlen) | |
1631 break; | |
1632 i = cmdline_charsize(ccline.cmdpos); | |
1633 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1634 break; | |
1635 ccline.cmdspos += i; | |
1636 #ifdef FEAT_MBYTE | |
1637 if (has_mbyte) | |
474 | 1638 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1639 + ccline.cmdpos); |
1640 else | |
1641 #endif | |
1642 ++ccline.cmdpos; | |
1643 } | |
180 | 1644 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1645 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1646 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1647 #ifdef FEAT_MBYTE | |
1648 if (has_mbyte) | |
1649 set_cmdspos_cursor(); | |
1650 #endif | |
1651 goto cmdline_not_changed; | |
1652 | |
1653 case K_LEFT: | |
1654 case K_S_LEFT: | |
1655 case K_C_LEFT: | |
1456 | 1656 if (ccline.cmdpos == 0) |
1657 goto cmdline_not_changed; | |
7 | 1658 do |
1659 { | |
1660 --ccline.cmdpos; | |
1661 #ifdef FEAT_MBYTE | |
1662 if (has_mbyte) /* move to first byte of char */ | |
1663 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1664 ccline.cmdbuff + ccline.cmdpos); | |
1665 #endif | |
1666 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1667 } | |
1456 | 1668 while (ccline.cmdpos > 0 |
1669 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1670 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1671 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1672 #ifdef FEAT_MBYTE | |
1673 if (has_mbyte) | |
1674 set_cmdspos_cursor(); | |
1675 #endif | |
1676 goto cmdline_not_changed; | |
1677 | |
1678 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
|
1679 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1680 goto cmdline_not_changed; |
7 | 1681 |
625 | 1682 #ifdef FEAT_GUI_W32 |
1683 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1684 * cancelled. */ | |
1685 case K_F4: | |
1686 if (mod_mask == MOD_MASK_ALT) | |
1687 { | |
1688 redrawcmd(); /* somehow the cmdline is cleared */ | |
1689 goto cmdline_not_changed; | |
1690 } | |
1691 break; | |
1692 #endif | |
1693 | |
7 | 1694 #ifdef FEAT_MOUSE |
1695 case K_MIDDLEDRAG: | |
1696 case K_MIDDLERELEASE: | |
1697 goto cmdline_not_changed; /* Ignore mouse */ | |
1698 | |
1699 case K_MIDDLEMOUSE: | |
1700 # ifdef FEAT_GUI | |
1701 /* When GUI is active, also paste when 'mouse' is empty */ | |
1702 if (!gui.in_use) | |
1703 # endif | |
1704 if (!mouse_has(MOUSE_COMMAND)) | |
1705 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1706 # ifdef FEAT_CLIPBOARD |
7 | 1707 if (clip_star.available) |
1015 | 1708 cmdline_paste('*', TRUE, TRUE); |
7 | 1709 else |
692 | 1710 # endif |
1015 | 1711 cmdline_paste(0, TRUE, TRUE); |
7 | 1712 redrawcmd(); |
1713 goto cmdline_changed; | |
1714 | |
692 | 1715 # ifdef FEAT_DND |
7 | 1716 case K_DROP: |
1015 | 1717 cmdline_paste('~', TRUE, FALSE); |
7 | 1718 redrawcmd(); |
1719 goto cmdline_changed; | |
692 | 1720 # endif |
7 | 1721 |
1722 case K_LEFTDRAG: | |
1723 case K_LEFTRELEASE: | |
1724 case K_RIGHTDRAG: | |
1725 case K_RIGHTRELEASE: | |
1726 /* Ignore drag and release events when the button-down wasn't | |
1727 * seen before. */ | |
1728 if (ignore_drag_release) | |
1729 goto cmdline_not_changed; | |
1730 /* FALLTHROUGH */ | |
1731 case K_LEFTMOUSE: | |
1732 case K_RIGHTMOUSE: | |
1733 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1734 ignore_drag_release = TRUE; | |
1735 else | |
1736 ignore_drag_release = FALSE; | |
1737 # ifdef FEAT_GUI | |
1738 /* When GUI is active, also move when 'mouse' is empty */ | |
1739 if (!gui.in_use) | |
1740 # endif | |
1741 if (!mouse_has(MOUSE_COMMAND)) | |
1742 goto cmdline_not_changed; /* Ignore mouse */ | |
1743 # ifdef FEAT_CLIPBOARD | |
1744 if (mouse_row < cmdline_row && clip_star.available) | |
1745 { | |
1746 int button, is_click, is_drag; | |
1747 | |
1748 /* | |
1749 * Handle modeless selection. | |
1750 */ | |
1751 button = get_mouse_button(KEY2TERMCAP1(c), | |
1752 &is_click, &is_drag); | |
1753 if (mouse_model_popup() && button == MOUSE_LEFT | |
1754 && (mod_mask & MOD_MASK_SHIFT)) | |
1755 { | |
1756 /* Translate shift-left to right button. */ | |
1757 button = MOUSE_RIGHT; | |
1758 mod_mask &= ~MOD_MASK_SHIFT; | |
1759 } | |
1760 clip_modeless(button, is_click, is_drag); | |
1761 goto cmdline_not_changed; | |
1762 } | |
1763 # endif | |
1764 | |
1765 set_cmdspos(); | |
1766 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1767 ++ccline.cmdpos) | |
1768 { | |
1769 i = cmdline_charsize(ccline.cmdpos); | |
1770 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1771 && mouse_col < ccline.cmdspos % Columns + i) | |
1772 break; | |
692 | 1773 # ifdef FEAT_MBYTE |
7 | 1774 if (has_mbyte) |
1775 { | |
1776 /* Count ">" for double-wide char that doesn't fit. */ | |
1777 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1778 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1779 + ccline.cmdpos) - 1; |
1780 } | |
692 | 1781 # endif |
7 | 1782 ccline.cmdspos += i; |
1783 } | |
1784 goto cmdline_not_changed; | |
1785 | |
1786 /* Mouse scroll wheel: ignored here */ | |
1787 case K_MOUSEDOWN: | |
1788 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1789 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1790 case K_MOUSERIGHT: |
7 | 1791 /* Alternate buttons ignored here */ |
1792 case K_X1MOUSE: | |
1793 case K_X1DRAG: | |
1794 case K_X1RELEASE: | |
1795 case K_X2MOUSE: | |
1796 case K_X2DRAG: | |
1797 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1798 case K_MOUSEMOVE: |
7 | 1799 goto cmdline_not_changed; |
1800 | |
1801 #endif /* FEAT_MOUSE */ | |
1802 | |
1803 #ifdef FEAT_GUI | |
1804 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1805 case K_LEFTRELEASE_NM: | |
1806 goto cmdline_not_changed; | |
1807 | |
1808 case K_VER_SCROLLBAR: | |
540 | 1809 if (msg_scrolled == 0) |
7 | 1810 { |
1811 gui_do_scroll(); | |
1812 redrawcmd(); | |
1813 } | |
1814 goto cmdline_not_changed; | |
1815 | |
1816 case K_HOR_SCROLLBAR: | |
540 | 1817 if (msg_scrolled == 0) |
7 | 1818 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1819 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1820 redrawcmd(); |
1821 } | |
1822 goto cmdline_not_changed; | |
1823 #endif | |
692 | 1824 #ifdef FEAT_GUI_TABLINE |
1825 case K_TABLINE: | |
1826 case K_TABMENU: | |
1827 /* Don't want to change any tabs here. Make sure the same tab | |
1828 * is still selected. */ | |
1829 if (gui_use_tabline()) | |
1830 gui_mch_set_curtab(tabpage_index(curtab)); | |
1831 goto cmdline_not_changed; | |
1832 #endif | |
1833 | |
7 | 1834 case K_SELECT: /* end of Select mode mapping - ignore */ |
1835 goto cmdline_not_changed; | |
1836 | |
1837 case Ctrl_B: /* begin of command line */ | |
1838 case K_HOME: | |
1839 case K_KHOME: | |
1840 case K_S_HOME: | |
1841 case K_C_HOME: | |
1842 ccline.cmdpos = 0; | |
1843 set_cmdspos(); | |
1844 goto cmdline_not_changed; | |
1845 | |
1846 case Ctrl_E: /* end of command line */ | |
1847 case K_END: | |
1848 case K_KEND: | |
1849 case K_S_END: | |
1850 case K_C_END: | |
1851 ccline.cmdpos = ccline.cmdlen; | |
1852 set_cmdspos_cursor(); | |
1853 goto cmdline_not_changed; | |
1854 | |
1855 case Ctrl_A: /* all matches */ | |
3961 | 1856 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1857 break; |
1858 goto cmdline_changed; | |
1859 | |
772 | 1860 case Ctrl_L: |
1861 #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
|
1862 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 1863 goto cmdline_not_changed; |
1864 #endif | |
1865 | |
1866 /* completion: longest common part */ | |
3961 | 1867 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 1868 break; |
1869 goto cmdline_changed; | |
1870 | |
1871 case Ctrl_N: /* next match */ | |
1872 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
1873 if (xpc.xp_numfiles > 0) |
7 | 1874 { |
3961 | 1875 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
1876 0, firstc != '@') == FAIL) | |
7 | 1877 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1878 goto cmdline_not_changed; |
7 | 1879 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
1880 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1881 /* FALLTHROUGH */ |
7 | 1882 case K_UP: |
1883 case K_DOWN: | |
1884 case K_S_UP: | |
1885 case K_S_DOWN: | |
1886 case K_PAGEUP: | |
1887 case K_KPAGEUP: | |
1888 case K_PAGEDOWN: | |
1889 case K_KPAGEDOWN: | |
1890 if (hislen == 0 || firstc == NUL) /* no history */ | |
1891 goto cmdline_not_changed; | |
1892 | |
1893 i = hiscnt; | |
1894 | |
1895 /* save current command string so it can be restored later */ | |
1896 if (lookfor == NULL) | |
1897 { | |
1898 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
1899 goto cmdline_not_changed; | |
1900 lookfor[ccline.cmdpos] = NUL; | |
1901 } | |
1902 | |
1903 j = (int)STRLEN(lookfor); | |
1904 for (;;) | |
1905 { | |
1906 /* one step backwards */ | |
230 | 1907 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 1908 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 1909 { |
1910 if (hiscnt == hislen) /* first time */ | |
1911 hiscnt = hisidx[histype]; | |
1912 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
1913 hiscnt = hislen - 1; | |
1914 else if (hiscnt != hisidx[histype] + 1) | |
1915 --hiscnt; | |
1916 else /* at top of list */ | |
1917 { | |
1918 hiscnt = i; | |
1919 break; | |
1920 } | |
1921 } | |
1922 else /* one step forwards */ | |
1923 { | |
1924 /* on last entry, clear the line */ | |
1925 if (hiscnt == hisidx[histype]) | |
1926 { | |
1927 hiscnt = hislen; | |
1928 break; | |
1929 } | |
1930 | |
1931 /* not on a history line, nothing to do */ | |
1932 if (hiscnt == hislen) | |
1933 break; | |
1934 if (hiscnt == hislen - 1) /* wrap around */ | |
1935 hiscnt = 0; | |
1936 else | |
1937 ++hiscnt; | |
1938 } | |
1939 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
1940 { | |
1941 hiscnt = i; | |
1942 break; | |
1943 } | |
230 | 1944 if ((c != K_UP && c != K_DOWN) |
180 | 1945 || hiscnt == i |
7 | 1946 || STRNCMP(history[histype][hiscnt].hisstr, |
1947 lookfor, (size_t)j) == 0) | |
1948 break; | |
1949 } | |
1950 | |
1951 if (hiscnt != i) /* jumped to other entry */ | |
1952 { | |
1953 char_u *p; | |
1954 int len; | |
1955 int old_firstc; | |
1956 | |
1957 vim_free(ccline.cmdbuff); | |
1718 | 1958 xpc.xp_context = EXPAND_NOTHING; |
7 | 1959 if (hiscnt == hislen) |
1960 p = lookfor; /* back to the old one */ | |
1961 else | |
1962 p = history[histype][hiscnt].hisstr; | |
1963 | |
1964 if (histype == HIST_SEARCH | |
1965 && p != lookfor | |
1966 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
1967 { | |
1968 /* Correct for the separator character used when | |
1969 * adding the history entry vs the one used now. | |
1970 * First loop: count length. | |
1971 * Second loop: copy the characters. */ | |
1972 for (i = 0; i <= 1; ++i) | |
1973 { | |
1974 len = 0; | |
1975 for (j = 0; p[j] != NUL; ++j) | |
1976 { | |
1977 /* Replace old sep with new sep, unless it is | |
1978 * escaped. */ | |
1979 if (p[j] == old_firstc | |
1980 && (j == 0 || p[j - 1] != '\\')) | |
1981 { | |
1982 if (i > 0) | |
1983 ccline.cmdbuff[len] = firstc; | |
1984 } | |
1985 else | |
1986 { | |
1987 /* Escape new sep, unless it is already | |
1988 * escaped. */ | |
1989 if (p[j] == firstc | |
1990 && (j == 0 || p[j - 1] != '\\')) | |
1991 { | |
1992 if (i > 0) | |
1993 ccline.cmdbuff[len] = '\\'; | |
1994 ++len; | |
1995 } | |
1996 if (i > 0) | |
1997 ccline.cmdbuff[len] = p[j]; | |
1998 } | |
1999 ++len; | |
2000 } | |
2001 if (i == 0) | |
2002 { | |
2003 alloc_cmdbuff(len); | |
2004 if (ccline.cmdbuff == NULL) | |
2005 goto returncmd; | |
2006 } | |
2007 } | |
2008 ccline.cmdbuff[len] = NUL; | |
2009 } | |
2010 else | |
2011 { | |
2012 alloc_cmdbuff((int)STRLEN(p)); | |
2013 if (ccline.cmdbuff == NULL) | |
2014 goto returncmd; | |
2015 STRCPY(ccline.cmdbuff, p); | |
2016 } | |
2017 | |
2018 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2019 redrawcmd(); | |
2020 goto cmdline_changed; | |
2021 } | |
2022 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2023 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2024 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2025 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2026 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2027 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2028 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
|
2029 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
|
2030 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
|
2031 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2032 break; |
7 | 2033 #endif |
2034 | |
2035 case Ctrl_V: | |
2036 case Ctrl_Q: | |
2037 #ifdef FEAT_MOUSE | |
2038 ignore_drag_release = TRUE; | |
2039 #endif | |
2040 putcmdline('^', TRUE); | |
2041 c = get_literal(); /* get next (two) character(s) */ | |
2042 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
|
2043 extra_char = NUL; |
7 | 2044 #ifdef FEAT_MBYTE |
2045 /* may need to remove ^ when composing char was typed */ | |
2046 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2047 { | |
2048 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2049 msg_putchar(' '); | |
2050 cursorcmd(); | |
2051 } | |
2052 #endif | |
2053 break; | |
2054 | |
2055 #ifdef FEAT_DIGRAPHS | |
2056 case Ctrl_K: | |
2057 #ifdef FEAT_MOUSE | |
2058 ignore_drag_release = TRUE; | |
2059 #endif | |
2060 putcmdline('?', TRUE); | |
2061 #ifdef USE_ON_FLY_SCROLL | |
2062 dont_scroll = TRUE; /* disallow scrolling here */ | |
2063 #endif | |
2064 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
|
2065 extra_char = NUL; |
7 | 2066 if (c != NUL) |
2067 break; | |
2068 | |
2069 redrawcmd(); | |
2070 goto cmdline_not_changed; | |
2071 #endif /* FEAT_DIGRAPHS */ | |
2072 | |
2073 #ifdef FEAT_RIGHTLEFT | |
2074 case Ctrl__: /* CTRL-_: switch language mode */ | |
2075 if (!p_ari) | |
2076 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2077 # ifdef FEAT_FKMAP |
7 | 2078 if (p_altkeymap) |
2079 { | |
2080 cmd_fkmap = !cmd_fkmap; | |
2081 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2082 ccline.overstrike = FALSE; | |
2083 } | |
2084 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2085 # endif |
7 | 2086 cmd_hkmap = !cmd_hkmap; |
2087 goto cmdline_not_changed; | |
2088 #endif | |
2089 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2090 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
|
2091 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
|
2092 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
|
2093 |
7 | 2094 default: |
2095 #ifdef UNIX | |
2096 if (c == intr_char) | |
2097 { | |
2098 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2099 putting it in history */ | |
2100 goto returncmd; /* back to Normal mode */ | |
2101 } | |
2102 #endif | |
2103 /* | |
2104 * Normal character with no special meaning. Just set mod_mask | |
2105 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2106 * the string <S-Space>. This should only happen after ^V. | |
2107 */ | |
2108 if (!IS_SPECIAL(c)) | |
2109 mod_mask = 0x0; | |
2110 break; | |
2111 } | |
2112 /* | |
2113 * End of switch on command line character. | |
2114 * We come here if we have a normal character. | |
2115 */ | |
2116 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2117 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2118 #ifdef FEAT_MBYTE |
2119 /* Add ABBR_OFF for characters above 0x100, this is | |
2120 * what check_abbr() expects. */ | |
2121 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2122 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2123 c) || c == Ctrl_RSB)) |
7 | 2124 goto cmdline_changed; |
2125 | |
2126 /* | |
2127 * put the character in the command line | |
2128 */ | |
2129 if (IS_SPECIAL(c) || mod_mask != 0) | |
2130 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2131 else | |
2132 { | |
2133 #ifdef FEAT_MBYTE | |
2134 if (has_mbyte) | |
2135 { | |
2136 j = (*mb_char2bytes)(c, IObuff); | |
2137 IObuff[j] = NUL; /* exclude composing chars */ | |
2138 put_on_cmdline(IObuff, j, TRUE); | |
2139 } | |
2140 else | |
2141 #endif | |
2142 { | |
2143 IObuff[0] = c; | |
2144 put_on_cmdline(IObuff, 1, TRUE); | |
2145 } | |
2146 } | |
2147 goto cmdline_changed; | |
2148 | |
2149 /* | |
2150 * This part implements incremental searches for "/" and "?" | |
2151 * Jump to cmdline_not_changed when a character has been read but the command | |
2152 * line did not change. Then we only search and redraw if something changed in | |
2153 * the past. | |
2154 * Jump to cmdline_changed when the command line did change. | |
2155 * (Sorry for the goto's, I know it is ugly). | |
2156 */ | |
2157 cmdline_not_changed: | |
2158 #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
|
2159 if (!is_state.incsearch_postponed) |
7 | 2160 continue; |
2161 #endif | |
2162 | |
2163 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
|
2164 /* 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
|
2165 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
|
2166 |
7 | 2167 #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
|
2168 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2169 #endif |
2170 | |
2171 #ifdef FEAT_RIGHTLEFT | |
2172 if (cmdmsg_rl | |
2173 # ifdef FEAT_ARABIC | |
534 | 2174 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2175 # endif |
2176 ) | |
2177 /* Always redraw the whole command line to fix shaping and | |
3374 | 2178 * right-left typing. Not efficient, but it works. |
2179 * Do it only when there are no characters left to read | |
2180 * to avoid useless intermediate redraws. */ | |
2181 if (vpeekc() == NUL) | |
2182 redrawcmd(); | |
7 | 2183 #endif |
2184 } | |
2185 | |
2186 returncmd: | |
2187 | |
2188 #ifdef FEAT_RIGHTLEFT | |
2189 cmdmsg_rl = FALSE; | |
2190 #endif | |
2191 | |
2192 #ifdef FEAT_FKMAP | |
2193 cmd_fkmap = 0; | |
2194 #endif | |
2195 | |
2196 ExpandCleanup(&xpc); | |
1718 | 2197 ccline.xpc = NULL; |
7 | 2198 |
2199 #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
|
2200 finish_incsearch_highlighting(gotesc, &is_state); |
7 | 2201 #endif |
2202 | |
2203 if (ccline.cmdbuff != NULL) | |
2204 { | |
2205 /* | |
2206 * Put line in history buffer (":" and "=" only when it was typed). | |
2207 */ | |
2208 #ifdef FEAT_CMDHIST | |
2209 if (ccline.cmdlen && firstc != NUL | |
2210 && (some_key_typed || histype == HIST_SEARCH)) | |
2211 { | |
2212 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2213 histype == HIST_SEARCH ? firstc : NUL); | |
2214 if (firstc == ':') | |
2215 { | |
2216 vim_free(new_last_cmdline); | |
2217 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2218 } | |
2219 } | |
2220 #endif | |
2221 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2222 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
|
2223 abandon_cmdline(); |
7 | 2224 } |
2225 | |
2226 /* | |
2227 * If the screen was shifted up, redraw the whole screen (later). | |
2228 * If the line is too long, clear it, so ruler and shown command do | |
2229 * not get printed in the middle of it. | |
2230 */ | |
2231 msg_check(); | |
2232 msg_scroll = save_msg_scroll; | |
2233 redir_off = FALSE; | |
2234 | |
2235 /* When the command line was typed, no need for a wait-return prompt. */ | |
2236 if (some_key_typed) | |
2237 need_wait_return = FALSE; | |
2238 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2239 /* 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
|
2240 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
|
2241 |
7 | 2242 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2243 #ifdef HAVE_INPUT_METHOD |
7 | 2244 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2245 im_save_status(b_im_ptr); | |
2246 im_set_active(FALSE); | |
2247 #endif | |
2248 #ifdef FEAT_MOUSE | |
2249 setmouse(); | |
2250 #endif | |
2251 #ifdef CURSOR_SHAPE | |
2252 ui_cursor_shape(); /* may show different cursor shape */ | |
2253 #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
|
2254 sb_text_end_cmdline(); |
7 | 2255 |
95 | 2256 { |
2257 char_u *p = ccline.cmdbuff; | |
2258 | |
2259 /* Make ccline empty, getcmdline() may try to use it. */ | |
2260 ccline.cmdbuff = NULL; | |
2261 return p; | |
2262 } | |
7 | 2263 } |
2264 | |
2265 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2266 /* | |
2267 * Get a command line with a prompt. | |
2268 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2269 * f_input() when evaluating an expression from CTRL-R =). | |
2270 * Returns the command line in allocated memory, or NULL. | |
2271 */ | |
2272 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2273 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2274 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2275 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2276 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2277 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2278 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2279 { |
2280 char_u *s; | |
2281 struct cmdline_info save_ccline; | |
2282 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
|
2283 int msg_silent_save = msg_silent; |
7 | 2284 |
95 | 2285 save_cmdline(&save_ccline); |
7 | 2286 ccline.cmdprompt = prompt; |
2287 ccline.cmdattr = attr; | |
531 | 2288 # ifdef FEAT_EVAL |
2289 ccline.xp_context = xp_context; | |
2290 ccline.xp_arg = xp_arg; | |
2291 ccline.input_fn = (firstc == '@'); | |
2292 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2293 msg_silent = 0; |
7 | 2294 s = getcmdline(firstc, 1L, 0); |
95 | 2295 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2296 msg_silent = msg_silent_save; |
3020 | 2297 /* Restore msg_col, the prompt from input() may have changed it. |
2298 * But only if called recursively and the commandline is therefore being | |
2299 * restored to an old one; if not, the input() prompt stays on the screen, | |
2300 * so we need its modified msg_col left intact. */ | |
2301 if (ccline.cmdbuff != NULL) | |
2302 msg_col = msg_col_save; | |
7 | 2303 |
2304 return s; | |
2305 } | |
2306 #endif | |
2307 | |
632 | 2308 /* |
634 | 2309 * Return TRUE when the text must not be changed and we can't switch to |
2310 * another window or buffer. Used when editing the command line, evaluating | |
2311 * 'balloonexpr', etc. | |
632 | 2312 */ |
2313 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2314 text_locked(void) |
632 | 2315 { |
2316 #ifdef FEAT_CMDWIN | |
2317 if (cmdwin_type != 0) | |
2318 return TRUE; | |
2319 #endif | |
634 | 2320 return textlock != 0; |
632 | 2321 } |
2322 | |
2323 /* | |
2324 * Give an error message for a command that isn't allowed while the cmdline | |
2325 * window is open or editing the cmdline in another way. | |
2326 */ | |
2327 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2328 text_locked_msg(void) |
632 | 2329 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2330 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2331 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2332 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2333 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2334 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2335 { |
632 | 2336 #ifdef FEAT_CMDWIN |
2337 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2338 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2339 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2340 return e_secure; |
632 | 2341 } |
2342 | |
819 | 2343 /* |
1834 | 2344 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2345 * and give an error message. | |
819 | 2346 */ |
2347 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2348 curbuf_locked(void) |
819 | 2349 { |
2350 if (curbuf_lock > 0) | |
2351 { | |
2352 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2353 return TRUE; | |
2354 } | |
1834 | 2355 return allbuf_locked(); |
2356 } | |
2357 | |
2358 /* | |
2359 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2360 * message. | |
2361 */ | |
2362 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2363 allbuf_locked(void) |
1834 | 2364 { |
2365 if (allbuf_lock > 0) | |
2366 { | |
2367 EMSG(_("E811: Not allowed to change buffer information now")); | |
2368 return TRUE; | |
2369 } | |
819 | 2370 return FALSE; |
2371 } | |
2372 | |
7 | 2373 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2374 cmdline_charsize(int idx) |
7 | 2375 { |
2376 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2377 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2378 return 1; | |
2379 #endif | |
2380 return ptr2cells(ccline.cmdbuff + idx); | |
2381 } | |
2382 | |
2383 /* | |
2384 * Compute the offset of the cursor on the command line for the prompt and | |
2385 * indent. | |
2386 */ | |
2387 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2388 set_cmdspos(void) |
7 | 2389 { |
531 | 2390 if (ccline.cmdfirstc != NUL) |
7 | 2391 ccline.cmdspos = 1 + ccline.cmdindent; |
2392 else | |
2393 ccline.cmdspos = 0 + ccline.cmdindent; | |
2394 } | |
2395 | |
2396 /* | |
2397 * Compute the screen position for the cursor on the command line. | |
2398 */ | |
2399 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2400 set_cmdspos_cursor(void) |
7 | 2401 { |
2402 int i, m, c; | |
2403 | |
2404 set_cmdspos(); | |
2405 if (KeyTyped) | |
534 | 2406 { |
7 | 2407 m = Columns * Rows; |
534 | 2408 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2409 m = MAXCOL; | |
2410 } | |
7 | 2411 else |
2412 m = MAXCOL; | |
2413 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2414 { | |
2415 c = cmdline_charsize(i); | |
2416 #ifdef FEAT_MBYTE | |
2417 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2418 if (has_mbyte) | |
2419 correct_cmdspos(i, c); | |
2420 #endif | |
1612 | 2421 /* If the cmdline doesn't fit, show cursor on last visible char. |
2422 * Don't move the cursor itself, so we can still append. */ | |
7 | 2423 if ((ccline.cmdspos += c) >= m) |
2424 { | |
2425 ccline.cmdspos -= c; | |
2426 break; | |
2427 } | |
2428 #ifdef FEAT_MBYTE | |
2429 if (has_mbyte) | |
474 | 2430 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2431 #endif |
2432 } | |
2433 } | |
2434 | |
2435 #ifdef FEAT_MBYTE | |
2436 /* | |
2437 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2438 * character that doesn't fit, so that a ">" must be displayed. | |
2439 */ | |
2440 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2441 correct_cmdspos(int idx, int cells) |
7 | 2442 { |
474 | 2443 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2444 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2445 && ccline.cmdspos % Columns + cells > Columns) | |
2446 ccline.cmdspos++; | |
2447 } | |
2448 #endif | |
2449 | |
2450 /* | |
2451 * Get an Ex command line for the ":" command. | |
2452 */ | |
2453 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2454 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2455 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2456 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2457 int indent) /* indent for inside conditionals */ |
7 | 2458 { |
2459 /* When executing a register, remove ':' that's in front of each line. */ | |
2460 if (exec_from_reg && vpeekc() == ':') | |
2461 (void)vgetc(); | |
2462 return getcmdline(c, 1L, indent); | |
2463 } | |
2464 | |
2465 /* | |
2466 * Get an Ex command line for Ex mode. | |
2467 * In Ex mode we only use the OS supplied line editing features and no | |
2468 * mappings or abbreviations. | |
168 | 2469 * Returns a string in allocated memory or NULL. |
7 | 2470 */ |
2471 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2472 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2473 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2474 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2475 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2476 int indent) /* indent for inside conditionals */ |
7 | 2477 { |
168 | 2478 garray_T line_ga; |
2479 char_u *pend; | |
2480 int startcol = 0; | |
1329 | 2481 int c1 = 0; |
168 | 2482 int escaped = FALSE; /* CTRL-V typed */ |
2483 int vcol = 0; | |
2484 char_u *p; | |
1329 | 2485 int prev_char; |
5966 | 2486 int len; |
7 | 2487 |
2488 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2489 * confuses the system function that computes tabstops. */ | |
2490 cursor_on(); | |
2491 | |
2492 /* always start in column 0; write a newline if necessary */ | |
2493 compute_cmdrow(); | |
168 | 2494 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2495 msg_putchar('\n'); |
168 | 2496 if (promptc == ':') |
7 | 2497 { |
164 | 2498 /* indent that is only displayed, not in the line itself */ |
168 | 2499 if (p_prompt) |
2500 msg_putchar(':'); | |
7 | 2501 while (indent-- > 0) |
2502 msg_putchar(' '); | |
2503 startcol = msg_col; | |
2504 } | |
2505 | |
2506 ga_init2(&line_ga, 1, 30); | |
2507 | |
164 | 2508 /* autoindent for :insert and :append is in the line itself */ |
168 | 2509 if (promptc <= 0) |
164 | 2510 { |
2511 vcol = indent; | |
2512 while (indent >= 8) | |
2513 { | |
2514 ga_append(&line_ga, TAB); | |
2515 msg_puts((char_u *)" "); | |
2516 indent -= 8; | |
2517 } | |
2518 while (indent-- > 0) | |
2519 { | |
2520 ga_append(&line_ga, ' '); | |
2521 msg_putchar(' '); | |
2522 } | |
2523 } | |
168 | 2524 ++no_mapping; |
2525 ++allow_keys; | |
164 | 2526 |
7 | 2527 /* |
2528 * Get the line, one character at a time. | |
2529 */ | |
2530 got_int = FALSE; | |
168 | 2531 while (!got_int) |
7 | 2532 { |
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
|
2533 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
|
2534 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
|
2535 |
7 | 2536 if (ga_grow(&line_ga, 40) == FAIL) |
2537 break; | |
2538 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2539 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2540 * 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
|
2541 */ |
1329 | 2542 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
|
2543 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2544 /* 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
|
2545 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
|
2546 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
|
2547 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2548 c1 = vgetc(); |
7 | 2549 |
2550 /* | |
168 | 2551 * Handle line editing. |
2552 * Previously this was left to the system, putting the terminal in | |
2553 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2554 */ |
168 | 2555 if (got_int) |
2556 { | |
2557 msg_putchar('\n'); | |
2558 break; | |
2559 } | |
2560 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2561 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
|
2562 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2563 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
|
2564 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
|
2565 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2566 |
168 | 2567 if (!escaped) |
7 | 2568 { |
168 | 2569 /* CR typed means "enter", which is NL */ |
2570 if (c1 == '\r') | |
2571 c1 = '\n'; | |
2572 | |
2573 if (c1 == BS || c1 == K_BS | |
2574 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2575 { |
168 | 2576 if (line_ga.ga_len > 0) |
2577 { | |
5966 | 2578 #ifdef FEAT_MBYTE |
2579 if (has_mbyte) | |
2580 { | |
2581 p = (char_u *)line_ga.ga_data; | |
2582 p[line_ga.ga_len] = NUL; | |
2583 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2584 line_ga.ga_len -= len; | |
2585 } | |
2586 else | |
2587 #endif | |
2588 --line_ga.ga_len; | |
168 | 2589 goto redraw; |
2590 } | |
2591 continue; | |
7 | 2592 } |
2593 | |
168 | 2594 if (c1 == Ctrl_U) |
7 | 2595 { |
168 | 2596 msg_col = startcol; |
2597 msg_clr_eos(); | |
2598 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
|
2599 goto redraw; |
168 | 2600 } |
2601 | |
2602 if (c1 == Ctrl_T) | |
2603 { | |
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
|
2604 sw = get_sw_value(curbuf); |
168 | 2605 p = (char_u *)line_ga.ga_data; |
2606 p[line_ga.ga_len] = NUL; | |
5995 | 2607 indent = get_indent_str(p, 8, FALSE); |
3740 | 2608 indent += sw - indent % sw; |
168 | 2609 add_indent: |
5995 | 2610 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2611 { |
7009 | 2612 (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
|
2613 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
|
2614 s = skipwhite(p); |
168 | 2615 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2616 *s = ' '; | |
2617 ++line_ga.ga_len; | |
7 | 2618 } |
168 | 2619 redraw: |
2620 /* redraw the line */ | |
2621 msg_col = startcol; | |
2622 vcol = 0; | |
5966 | 2623 p = (char_u *)line_ga.ga_data; |
2624 p[line_ga.ga_len] = NUL; | |
2625 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2626 { |
168 | 2627 if (*p == TAB) |
7 | 2628 { |
168 | 2629 do |
7 | 2630 { |
168 | 2631 msg_putchar(' '); |
2632 } while (++vcol % 8); | |
5966 | 2633 ++p; |
7 | 2634 } |
168 | 2635 else |
164 | 2636 { |
5966 | 2637 len = MB_PTR2LEN(p); |
2638 msg_outtrans_len(p, len); | |
2639 vcol += ptr2cells(p); | |
2640 p += len; | |
7 | 2641 } |
2642 } | |
168 | 2643 msg_clr_eos(); |
1329 | 2644 windgoto(msg_row, msg_col); |
168 | 2645 continue; |
2646 } | |
2647 | |
2648 if (c1 == Ctrl_D) | |
2649 { | |
2650 /* Delete one shiftwidth. */ | |
2651 p = (char_u *)line_ga.ga_data; | |
2652 if (prev_char == '0' || prev_char == '^') | |
7 | 2653 { |
168 | 2654 if (prev_char == '^') |
2655 ex_keep_indent = TRUE; | |
2656 indent = 0; | |
2657 p[--line_ga.ga_len] = NUL; | |
7 | 2658 } |
2659 else | |
2660 { | |
168 | 2661 p[line_ga.ga_len] = NUL; |
5995 | 2662 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
|
2663 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
|
2664 { |
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
|
2665 --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
|
2666 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
|
2667 } |
168 | 2668 } |
5995 | 2669 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2670 { |
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
|
2671 s = skipwhite(p); |
168 | 2672 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2673 --line_ga.ga_len; | |
7 | 2674 } |
168 | 2675 goto add_indent; |
2676 } | |
2677 | |
2678 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2679 { | |
2680 escaped = TRUE; | |
2681 continue; | |
7 | 2682 } |
168 | 2683 |
2684 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2685 if (IS_SPECIAL(c1)) | |
2686 continue; | |
7 | 2687 } |
168 | 2688 |
2689 if (IS_SPECIAL(c1)) | |
2690 c1 = '?'; | |
5966 | 2691 #ifdef FEAT_MBYTE |
2692 if (has_mbyte) | |
2693 len = (*mb_char2bytes)(c1, | |
2694 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2695 else | |
2696 #endif | |
2697 { | |
2698 len = 1; | |
2699 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2700 } | |
168 | 2701 if (c1 == '\n') |
2702 msg_putchar('\n'); | |
2703 else if (c1 == TAB) | |
2704 { | |
2705 /* Don't use chartabsize(), 'ts' can be different */ | |
2706 do | |
2707 { | |
2708 msg_putchar(' '); | |
2709 } while (++vcol % 8); | |
2710 } | |
7 | 2711 else |
2712 { | |
168 | 2713 msg_outtrans_len( |
5966 | 2714 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2715 vcol += char2cells(c1); |
7 | 2716 } |
5966 | 2717 line_ga.ga_len += len; |
168 | 2718 escaped = FALSE; |
2719 | |
2720 windgoto(msg_row, msg_col); | |
164 | 2721 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2722 |
2590 | 2723 /* We are done when a NL is entered, but not when it comes after an |
2724 * odd number of backslashes, that results in a NUL. */ | |
2725 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2726 { |
2590 | 2727 int bcount = 0; |
2728 | |
2729 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2730 ++bcount; | |
2731 | |
2732 if (bcount > 0) | |
2733 { | |
2734 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2735 * "\NL", etc. */ | |
2736 line_ga.ga_len -= (bcount + 1) / 2; | |
2737 pend -= (bcount + 1) / 2; | |
2738 pend[-1] = '\n'; | |
2739 } | |
2740 | |
2741 if ((bcount & 1) == 0) | |
2742 { | |
2743 --line_ga.ga_len; | |
2744 --pend; | |
2745 *pend = NUL; | |
2746 break; | |
2747 } | |
7 | 2748 } |
2749 } | |
2750 | |
168 | 2751 --no_mapping; |
2752 --allow_keys; | |
2753 | |
7 | 2754 /* make following messages go to the next line */ |
2755 msg_didout = FALSE; | |
2756 msg_col = 0; | |
2757 if (msg_row < Rows - 1) | |
2758 ++msg_row; | |
2759 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2760 | |
2761 if (got_int) | |
2762 ga_clear(&line_ga); | |
2763 | |
2764 return (char_u *)line_ga.ga_data; | |
2765 } | |
2766 | |
502 | 2767 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2768 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2769 /* |
2770 * Return TRUE if ccline.overstrike is on. | |
2771 */ | |
2772 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2773 cmdline_overstrike(void) |
7 | 2774 { |
2775 return ccline.overstrike; | |
2776 } | |
2777 | |
2778 /* | |
2779 * Return TRUE if the cursor is at the end of the cmdline. | |
2780 */ | |
2781 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2782 cmdline_at_end(void) |
7 | 2783 { |
2784 return (ccline.cmdpos >= ccline.cmdlen); | |
2785 } | |
2786 #endif | |
2787 | |
574 | 2788 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2789 /* |
2790 * Return the virtual column number at the current cursor position. | |
2791 * This is used by the IM code to obtain the start of the preedit string. | |
2792 */ | |
2793 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2794 cmdline_getvcol_cursor(void) |
7 | 2795 { |
2796 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2797 return MAXCOL; | |
2798 | |
2799 # ifdef FEAT_MBYTE | |
2800 if (has_mbyte) | |
2801 { | |
2802 colnr_T col; | |
2803 int i = 0; | |
2804 | |
2805 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2806 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2807 |
2808 return col; | |
2809 } | |
2810 else | |
2811 # endif | |
2812 return ccline.cmdpos; | |
2813 } | |
2814 #endif | |
2815 | |
2816 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2817 /* | |
2818 * If part of the command line is an IM preedit string, redraw it with | |
2819 * IM feedback attributes. The cursor position is restored after drawing. | |
2820 */ | |
2821 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2822 redrawcmd_preedit(void) |
7 | 2823 { |
2824 if ((State & CMDLINE) | |
2825 && xic != NULL | |
976 | 2826 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2827 && !p_imdisable |
2828 && im_is_preediting()) | |
2829 { | |
2830 int cmdpos = 0; | |
2831 int cmdspos; | |
2832 int old_row; | |
2833 int old_col; | |
2834 colnr_T col; | |
2835 | |
2836 old_row = msg_row; | |
2837 old_col = msg_col; | |
531 | 2838 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2839 |
2840 # ifdef FEAT_MBYTE | |
2841 if (has_mbyte) | |
2842 { | |
2843 for (col = 0; col < preedit_start_col | |
2844 && cmdpos < ccline.cmdlen; ++col) | |
2845 { | |
2846 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2847 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2848 } |
2849 } | |
2850 else | |
2851 # endif | |
2852 { | |
2853 cmdspos += preedit_start_col; | |
2854 cmdpos += preedit_start_col; | |
2855 } | |
2856 | |
2857 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2858 msg_col = cmdspos % (int)Columns; | |
2859 if (msg_row >= Rows) | |
2860 msg_row = Rows - 1; | |
2861 | |
2862 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
2863 { | |
2864 int char_len; | |
2865 int char_attr; | |
2866 | |
2867 char_attr = im_get_feedback_attr(col); | |
2868 if (char_attr < 0) | |
2869 break; /* end of preedit string */ | |
2870 | |
2871 # ifdef FEAT_MBYTE | |
2872 if (has_mbyte) | |
474 | 2873 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2874 else |
2875 # endif | |
2876 char_len = 1; | |
2877 | |
2878 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
2879 cmdpos += char_len; | |
2880 } | |
2881 | |
2882 msg_row = old_row; | |
2883 msg_col = old_col; | |
2884 } | |
2885 } | |
2886 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
2887 | |
2888 /* | |
2889 * Allocate a new command line buffer. | |
2890 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
2891 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
2892 */ | |
2893 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2894 alloc_cmdbuff(int len) |
7 | 2895 { |
2896 /* | |
2897 * give some extra space to avoid having to allocate all the time | |
2898 */ | |
2899 if (len < 80) | |
2900 len = 100; | |
2901 else | |
2902 len += 20; | |
2903 | |
2904 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
2905 ccline.cmdbufflen = len; | |
2906 } | |
2907 | |
2908 /* | |
2909 * Re-allocate the command line to length len + something extra. | |
2910 * return FAIL for failure, OK otherwise | |
2911 */ | |
2912 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2913 realloc_cmdbuff(int len) |
7 | 2914 { |
2915 char_u *p; | |
2916 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
2917 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
2918 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
|
2919 |
7 | 2920 p = ccline.cmdbuff; |
2921 alloc_cmdbuff(len); /* will get some more */ | |
2922 if (ccline.cmdbuff == NULL) /* out of memory */ | |
2923 { | |
2924 ccline.cmdbuff = p; /* keep the old one */ | |
2925 return FAIL; | |
2926 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
2927 /* 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
|
2928 * 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
|
2929 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
|
2930 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 2931 vim_free(p); |
1718 | 2932 |
2933 if (ccline.xpc != NULL | |
2934 && ccline.xpc->xp_pattern != NULL | |
2935 && ccline.xpc->xp_context != EXPAND_NOTHING | |
2936 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
2937 { | |
1754 | 2938 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 2939 |
2940 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
2941 * to point into the newly allocated memory. */ | |
2942 if (i >= 0 && i <= ccline.cmdlen) | |
2943 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
2944 } | |
2945 | |
7 | 2946 return OK; |
2947 } | |
2948 | |
359 | 2949 #if defined(FEAT_ARABIC) || defined(PROTO) |
2950 static char_u *arshape_buf = NULL; | |
2951 | |
2952 # if defined(EXITFREE) || defined(PROTO) | |
2953 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2954 free_cmdline_buf(void) |
359 | 2955 { |
2956 vim_free(arshape_buf); | |
2957 } | |
2958 # endif | |
2959 #endif | |
2960 | |
7 | 2961 /* |
2962 * Draw part of the cmdline at the current cursor position. But draw stars | |
2963 * when cmdline_star is TRUE. | |
2964 */ | |
2965 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2966 draw_cmdline(int start, int len) |
7 | 2967 { |
2968 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2969 int i; | |
2970 | |
2971 if (cmdline_star > 0) | |
2972 for (i = 0; i < len; ++i) | |
2973 { | |
2974 msg_putchar('*'); | |
2975 # ifdef FEAT_MBYTE | |
2976 if (has_mbyte) | |
474 | 2977 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 2978 # endif |
2979 } | |
2980 else | |
2981 #endif | |
2982 #ifdef FEAT_ARABIC | |
2983 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
2984 { | |
2985 static int buflen = 0; | |
2986 char_u *p; | |
2987 int j; | |
2988 int newlen = 0; | |
2989 int mb_l; | |
719 | 2990 int pc, pc1 = 0; |
7 | 2991 int prev_c = 0; |
2992 int prev_c1 = 0; | |
714 | 2993 int u8c; |
2994 int u8cc[MAX_MCO]; | |
7 | 2995 int nc = 0; |
2996 | |
2997 /* | |
2998 * Do arabic shaping into a temporary buffer. This is very | |
2999 * inefficient! | |
3000 */ | |
507 | 3001 if (len * 2 + 2 > buflen) |
7 | 3002 { |
3003 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3004 * alloc()/free() calls. */ | |
359 | 3005 vim_free(arshape_buf); |
507 | 3006 buflen = len * 2 + 2; |
359 | 3007 arshape_buf = alloc(buflen); |
3008 if (arshape_buf == NULL) | |
7 | 3009 return; /* out of memory */ |
3010 } | |
3011 | |
507 | 3012 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3013 { | |
3014 /* Prepend a space to draw the leading composing char on. */ | |
3015 arshape_buf[0] = ' '; | |
3016 newlen = 1; | |
3017 } | |
3018 | |
7 | 3019 for (j = start; j < start + len; j += mb_l) |
3020 { | |
3021 p = ccline.cmdbuff + j; | |
714 | 3022 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3023 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3024 if (ARABIC_CHAR(u8c)) |
3025 { | |
3026 /* Do Arabic shaping. */ | |
3027 if (cmdmsg_rl) | |
3028 { | |
3029 /* displaying from right to left */ | |
3030 pc = prev_c; | |
3031 pc1 = prev_c1; | |
714 | 3032 prev_c1 = u8cc[0]; |
7 | 3033 if (j + mb_l >= start + len) |
3034 nc = NUL; | |
3035 else | |
3036 nc = utf_ptr2char(p + mb_l); | |
3037 } | |
3038 else | |
3039 { | |
3040 /* displaying from left to right */ | |
3041 if (j + mb_l >= start + len) | |
3042 pc = NUL; | |
3043 else | |
714 | 3044 { |
3045 int pcc[MAX_MCO]; | |
3046 | |
3047 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3048 start + len - j - mb_l); |
714 | 3049 pc1 = pcc[0]; |
3050 } | |
7 | 3051 nc = prev_c; |
3052 } | |
3053 prev_c = u8c; | |
3054 | |
714 | 3055 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3056 |
359 | 3057 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3058 if (u8cc[0] != 0) |
7 | 3059 { |
714 | 3060 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3061 if (u8cc[1] != 0) | |
3062 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3063 arshape_buf + newlen); |
7 | 3064 } |
3065 } | |
3066 else | |
3067 { | |
3068 prev_c = u8c; | |
359 | 3069 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3070 newlen += mb_l; |
3071 } | |
3072 } | |
3073 | |
359 | 3074 msg_outtrans_len(arshape_buf, newlen); |
7 | 3075 } |
3076 else | |
3077 #endif | |
3078 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3079 } | |
3080 | |
3081 /* | |
3082 * Put a character on the command line. Shifts the following text to the | |
3083 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3084 * "c" must be printable (fit in one display cell)! | |
3085 */ | |
3086 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3087 putcmdline(int c, int shift) |
7 | 3088 { |
3089 if (cmd_silent) | |
3090 return; | |
3091 msg_no_more = TRUE; | |
3092 msg_putchar(c); | |
3093 if (shift) | |
3094 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3095 msg_no_more = FALSE; | |
3096 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3097 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3098 extra_char_shift = shift; |
7 | 3099 } |
3100 | |
3101 /* | |
3102 * Undo a putcmdline(c, FALSE). | |
3103 */ | |
3104 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3105 unputcmdline(void) |
7 | 3106 { |
3107 if (cmd_silent) | |
3108 return; | |
3109 msg_no_more = TRUE; | |
3110 if (ccline.cmdlen == ccline.cmdpos) | |
3111 msg_putchar(' '); | |
3558 | 3112 #ifdef FEAT_MBYTE |
3113 else if (has_mbyte) | |
3114 draw_cmdline(ccline.cmdpos, | |
3115 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3116 #endif | |
7 | 3117 else |
3118 draw_cmdline(ccline.cmdpos, 1); | |
3119 msg_no_more = FALSE; | |
3120 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3121 extra_char = NUL; |
7 | 3122 } |
3123 | |
3124 /* | |
3125 * Put the given string, of the given length, onto the command line. | |
3126 * If len is -1, then STRLEN() is used to calculate the length. | |
3127 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3128 * part will be redrawn, otherwise it will not. If this function is called | |
3129 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3130 * called afterwards. | |
3131 */ | |
3132 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3133 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3134 { |
3135 int retval; | |
3136 int i; | |
3137 int m; | |
3138 int c; | |
3139 | |
3140 if (len < 0) | |
3141 len = (int)STRLEN(str); | |
3142 | |
3143 /* Check if ccline.cmdbuff needs to be longer */ | |
3144 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
|
3145 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3146 else |
3147 retval = OK; | |
3148 if (retval == OK) | |
3149 { | |
3150 if (!ccline.overstrike) | |
3151 { | |
3152 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3153 ccline.cmdbuff + ccline.cmdpos, | |
3154 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3155 ccline.cmdlen += len; | |
3156 } | |
3157 else | |
3158 { | |
3159 #ifdef FEAT_MBYTE | |
3160 if (has_mbyte) | |
3161 { | |
3162 /* Count nr of characters in the new string. */ | |
3163 m = 0; | |
474 | 3164 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3165 ++m; |
3166 /* Count nr of bytes in cmdline that are overwritten by these | |
3167 * characters. */ | |
3168 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3169 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3170 --m; |
3171 if (i < ccline.cmdlen) | |
3172 { | |
3173 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3174 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3175 ccline.cmdlen += ccline.cmdpos + len - i; | |
3176 } | |
3177 else | |
3178 ccline.cmdlen = ccline.cmdpos + len; | |
3179 } | |
3180 else | |
3181 #endif | |
3182 if (ccline.cmdpos + len > ccline.cmdlen) | |
3183 ccline.cmdlen = ccline.cmdpos + len; | |
3184 } | |
3185 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3186 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3187 | |
3188 #ifdef FEAT_MBYTE | |
3189 if (enc_utf8) | |
3190 { | |
3191 /* When the inserted text starts with a composing character, | |
3192 * backup to the character before it. There could be two of them. | |
3193 */ | |
3194 i = 0; | |
3195 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3196 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3197 { | |
3198 i = (*mb_head_off)(ccline.cmdbuff, | |
3199 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3200 ccline.cmdpos -= i; | |
3201 len += i; | |
3202 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3203 } | |
3204 # ifdef FEAT_ARABIC | |
3205 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3206 { | |
3207 /* Check the previous character for Arabic combining pair. */ | |
3208 i = (*mb_head_off)(ccline.cmdbuff, | |
3209 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3210 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3211 + ccline.cmdpos - i), c)) | |
3212 { | |
3213 ccline.cmdpos -= i; | |
3214 len += i; | |
3215 } | |
3216 else | |
3217 i = 0; | |
3218 } | |
3219 # endif | |
3220 if (i != 0) | |
3221 { | |
3222 /* Also backup the cursor position. */ | |
3223 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3224 ccline.cmdspos -= i; | |
3225 msg_col -= i; | |
3226 if (msg_col < 0) | |
3227 { | |
3228 msg_col += Columns; | |
3229 --msg_row; | |
3230 } | |
3231 } | |
3232 } | |
3233 #endif | |
3234 | |
3235 if (redraw && !cmd_silent) | |
3236 { | |
3237 msg_no_more = TRUE; | |
3238 i = cmdline_row; | |
3114 | 3239 cursorcmd(); |
7 | 3240 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3241 /* Avoid clearing the rest of the line too often. */ | |
3242 if (cmdline_row != i || ccline.overstrike) | |
3243 msg_clr_eos(); | |
3244 msg_no_more = FALSE; | |
3245 } | |
3246 #ifdef FEAT_FKMAP | |
3247 /* | |
3248 * If we are in Farsi command mode, the character input must be in | |
3249 * Insert mode. So do not advance the cmdpos. | |
3250 */ | |
3251 if (!cmd_fkmap) | |
3252 #endif | |
3253 { | |
3254 if (KeyTyped) | |
534 | 3255 { |
7 | 3256 m = Columns * Rows; |
534 | 3257 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3258 m = MAXCOL; | |
3259 } | |
7 | 3260 else |
3261 m = MAXCOL; | |
3262 for (i = 0; i < len; ++i) | |
3263 { | |
3264 c = cmdline_charsize(ccline.cmdpos); | |
3265 #ifdef FEAT_MBYTE | |
3266 /* count ">" for a double-wide char that doesn't fit. */ | |
3267 if (has_mbyte) | |
3268 correct_cmdspos(ccline.cmdpos, c); | |
3269 #endif | |
1612 | 3270 /* Stop cursor at the end of the screen, but do increment the |
3271 * insert position, so that entering a very long command | |
3272 * works, even though you can't see it. */ | |
3273 if (ccline.cmdspos + c < m) | |
3274 ccline.cmdspos += c; | |
7 | 3275 #ifdef FEAT_MBYTE |
3276 if (has_mbyte) | |
3277 { | |
474 | 3278 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3279 if (c > len - i - 1) |
3280 c = len - i - 1; | |
3281 ccline.cmdpos += c; | |
3282 i += c; | |
3283 } | |
3284 #endif | |
3285 ++ccline.cmdpos; | |
3286 } | |
3287 } | |
3288 } | |
3289 if (redraw) | |
3290 msg_check(); | |
3291 return retval; | |
3292 } | |
3293 | |
95 | 3294 static struct cmdline_info prev_ccline; |
3295 static int prev_ccline_used = FALSE; | |
3296 | |
3297 /* | |
3298 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3299 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3300 * available globally in prev_ccline. | |
3301 */ | |
3302 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3303 save_cmdline(struct cmdline_info *ccp) |
95 | 3304 { |
3305 if (!prev_ccline_used) | |
3306 { | |
3307 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3308 prev_ccline_used = TRUE; | |
3309 } | |
3310 *ccp = prev_ccline; | |
3311 prev_ccline = ccline; | |
3312 ccline.cmdbuff = NULL; | |
3313 ccline.cmdprompt = NULL; | |
1718 | 3314 ccline.xpc = NULL; |
95 | 3315 } |
3316 | |
3317 /* | |
1214 | 3318 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3319 */ |
3320 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3321 restore_cmdline(struct cmdline_info *ccp) |
95 | 3322 { |
3323 ccline = prev_ccline; | |
3324 prev_ccline = *ccp; | |
3325 } | |
3326 | |
849 | 3327 #if defined(FEAT_EVAL) || defined(PROTO) |
3328 /* | |
3329 * Save the command line into allocated memory. Returns a pointer to be | |
3330 * passed to restore_cmdline_alloc() later. | |
3331 * Returns NULL when failed. | |
3332 */ | |
3333 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3334 save_cmdline_alloc(void) |
849 | 3335 { |
3336 struct cmdline_info *p; | |
3337 | |
3338 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3339 if (p != NULL) | |
3340 save_cmdline(p); | |
3341 return (char_u *)p; | |
3342 } | |
3343 | |
3344 /* | |
3345 * Restore the command line from the return value of save_cmdline_alloc(). | |
3346 */ | |
3347 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3348 restore_cmdline_alloc(char_u *p) |
849 | 3349 { |
3350 if (p != NULL) | |
3351 { | |
3352 restore_cmdline((struct cmdline_info *)p); | |
3353 vim_free(p); | |
3354 } | |
3355 } | |
3356 #endif | |
3357 | |
15 | 3358 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3359 * 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
|
3360 * Used by CTRL-R command in command-line mode. |
15 | 3361 * insert_reg() can't be used here, because special characters from the |
3362 * register contents will be interpreted as commands. | |
3363 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3364 * Return FAIL for failure, OK otherwise. |
15 | 3365 */ |
3366 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3367 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3368 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3369 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
|
3370 int remcr) /* remove trailing CR */ |
15 | 3371 { |
3372 long i; | |
3373 char_u *arg; | |
772 | 3374 char_u *p; |
15 | 3375 int allocated; |
3376 struct cmdline_info save_ccline; | |
3377 | |
3378 /* check for valid regname; also accept special characters for CTRL-R in | |
3379 * the command line */ | |
3380 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
|
3381 && 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
|
3382 && !valid_yank_reg(regname, FALSE)) |
15 | 3383 return FAIL; |
3384 | |
3385 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3386 * CTRL-C to break the loop. */ | |
3387 line_breakcheck(); | |
3388 if (got_int) | |
3389 return FAIL; | |
3390 | |
3391 #ifdef FEAT_CLIPBOARD | |
3392 regname = may_get_selection(regname); | |
3393 #endif | |
3394 | |
634 | 3395 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3396 * things like going to another buffer when evaluating an expression. */ |
95 | 3397 save_cmdline(&save_ccline); |
634 | 3398 ++textlock; |
15 | 3399 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3400 --textlock; |
95 | 3401 restore_cmdline(&save_ccline); |
15 | 3402 |
3403 if (i) | |
3404 { | |
3405 /* Got the value of a special register in "arg". */ | |
3406 if (arg == NULL) | |
3407 return FAIL; | |
772 | 3408 |
3409 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3410 * part of the word. */ | |
3411 p = arg; | |
3412 if (p_is && regname == Ctrl_W) | |
3413 { | |
3414 char_u *w; | |
3415 int len; | |
3416 | |
3417 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3418 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3419 { |
3420 #ifdef FEAT_MBYTE | |
3421 if (has_mbyte) | |
3422 { | |
3423 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3424 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3425 break; | |
3426 w -= len; | |
3427 } | |
3428 else | |
3429 #endif | |
3430 { | |
3431 if (!vim_iswordc(w[-1])) | |
3432 break; | |
3433 --w; | |
3434 } | |
3435 } | |
2937 | 3436 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3437 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3438 p += len; | |
3439 } | |
3440 | |
3441 cmdline_paste_str(p, literally); | |
15 | 3442 if (allocated) |
3443 vim_free(arg); | |
3444 return OK; | |
3445 } | |
3446 | |
1015 | 3447 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3448 } |
3449 | |
3450 /* | |
3451 * Put a string on the command line. | |
3452 * When "literally" is TRUE, insert literally. | |
3453 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3454 * line. | |
3455 */ | |
3456 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3457 cmdline_paste_str(char_u *s, int literally) |
15 | 3458 { |
3459 int c, cv; | |
3460 | |
3461 if (literally) | |
3462 put_on_cmdline(s, -1, TRUE); | |
3463 else | |
3464 while (*s != NUL) | |
3465 { | |
3466 cv = *s; | |
3467 if (cv == Ctrl_V && s[1]) | |
3468 ++s; | |
3469 #ifdef FEAT_MBYTE | |
3470 if (has_mbyte) | |
1606 | 3471 c = mb_cptr2char_adv(&s); |
15 | 3472 else |
3473 #endif | |
3474 c = *s++; | |
3628 | 3475 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3476 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3477 #ifdef UNIX |
3478 || c == intr_char | |
3479 #endif | |
3480 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3481 stuffcharReadbuff(Ctrl_V); | |
3482 stuffcharReadbuff(c); | |
3483 } | |
3484 } | |
3485 | |
7 | 3486 #ifdef FEAT_WILDMENU |
3487 /* | |
3488 * Delete characters on the command line, from "from" to the current | |
3489 * position. | |
3490 */ | |
3491 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3492 cmdline_del(int from) |
7 | 3493 { |
3494 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3495 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3496 ccline.cmdlen -= ccline.cmdpos - from; | |
3497 ccline.cmdpos = from; | |
3498 } | |
3499 #endif | |
3500 | |
3501 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3502 * 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
|
3503 * 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
|
3504 * overwritten. |
7 | 3505 */ |
3506 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3507 redrawcmdline(void) |
7 | 3508 { |
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
|
3509 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
|
3510 } |
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
|
3511 |
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
|
3512 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
|
3513 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
|
3514 { |
7 | 3515 if (cmd_silent) |
3516 return; | |
3517 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
|
3518 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
|
3519 compute_cmdrow(); |
7 | 3520 redrawcmd(); |
3521 cursorcmd(); | |
3522 } | |
3523 | |
3524 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3525 redrawcmdprompt(void) |
7 | 3526 { |
3527 int i; | |
3528 | |
3529 if (cmd_silent) | |
3530 return; | |
531 | 3531 if (ccline.cmdfirstc != NUL) |
7 | 3532 msg_putchar(ccline.cmdfirstc); |
3533 if (ccline.cmdprompt != NULL) | |
3534 { | |
3535 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3536 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3537 /* do the reverse of set_cmdspos() */ | |
531 | 3538 if (ccline.cmdfirstc != NUL) |
7 | 3539 --ccline.cmdindent; |
3540 } | |
3541 else | |
3542 for (i = ccline.cmdindent; i > 0; --i) | |
3543 msg_putchar(' '); | |
3544 } | |
3545 | |
3546 /* | |
3547 * Redraw what is currently on the command line. | |
3548 */ | |
3549 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3550 redrawcmd(void) |
7 | 3551 { |
3552 if (cmd_silent) | |
3553 return; | |
3554 | |
683 | 3555 /* when 'incsearch' is set there may be no command line while redrawing */ |
3556 if (ccline.cmdbuff == NULL) | |
3557 { | |
3558 windgoto(cmdline_row, 0); | |
3559 msg_clr_eos(); | |
3560 return; | |
3561 } | |
3562 | |
7 | 3563 msg_start(); |
3564 redrawcmdprompt(); | |
3565 | |
3566 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3567 msg_no_more = TRUE; | |
3568 draw_cmdline(0, ccline.cmdlen); | |
3569 msg_clr_eos(); | |
3570 msg_no_more = FALSE; | |
3571 | |
3572 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
|
3573 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
|
3574 putcmdline(extra_char, extra_char_shift); |
7 | 3575 |
3576 /* | |
3577 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3578 * in cmdline mode we can reset them now. | |
3579 */ | |
3580 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3581 | |
3582 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3583 * in cmdline mode */ | |
3584 skip_redraw = FALSE; | |
3585 } | |
3586 | |
3587 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3588 compute_cmdrow(void) |
7 | 3589 { |
540 | 3590 if (exmode_active || msg_scrolled != 0) |
7 | 3591 cmdline_row = Rows - 1; |
3592 else | |
3593 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
|
3594 + lastwin->w_status_height; |
7 | 3595 } |
3596 | |
3597 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3598 cursorcmd(void) |
7 | 3599 { |
3600 if (cmd_silent) | |
3601 return; | |
3602 | |
3603 #ifdef FEAT_RIGHTLEFT | |
3604 if (cmdmsg_rl) | |
3605 { | |
3606 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3607 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3608 if (msg_row <= 0) | |
3609 msg_row = Rows - 1; | |
3610 } | |
3611 else | |
3612 #endif | |
3613 { | |
3614 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3615 msg_col = ccline.cmdspos % (int)Columns; | |
3616 if (msg_row >= Rows) | |
3617 msg_row = Rows - 1; | |
3618 } | |
3619 | |
3620 windgoto(msg_row, msg_col); | |
3621 #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
|
3622 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
|
3623 redrawcmd_preedit(); |
7 | 3624 #endif |
3625 #ifdef MCH_CURSOR_SHAPE | |
3626 mch_update_cursor(); | |
3627 #endif | |
3628 } | |
3629 | |
3630 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3631 gotocmdline(int clr) |
7 | 3632 { |
3633 msg_start(); | |
3634 #ifdef FEAT_RIGHTLEFT | |
3635 if (cmdmsg_rl) | |
3636 msg_col = Columns - 1; | |
3637 else | |
3638 #endif | |
3639 msg_col = 0; /* always start in column 0 */ | |
3640 if (clr) /* clear the bottom line(s) */ | |
3641 msg_clr_eos(); /* will reset clear_cmdline */ | |
3642 windgoto(cmdline_row, 0); | |
3643 } | |
3644 | |
3645 /* | |
3646 * Check the word in front of the cursor for an abbreviation. | |
3647 * Called when the non-id character "c" has been entered. | |
3648 * When an abbreviation is recognized it is removed from the text with | |
3649 * backspaces and the replacement string is inserted, followed by "c". | |
3650 */ | |
3651 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3652 ccheck_abbr(int c) |
7 | 3653 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3654 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3655 |
7 | 3656 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3657 return FALSE; | |
3658 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3659 /* 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
|
3660 * 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
|
3661 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
|
3662 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3663 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
|
3664 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3665 && 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
|
3666 && 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
|
3667 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3668 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3669 /* 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
|
3670 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3671 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3672 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3673 } |
3674 | |
3164 | 3675 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3676 static int | |
3677 #ifdef __BORLANDC__ | |
3678 _RTLENTRYF | |
3679 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3680 sort_func_compare(const void *s1, const void *s2) |
3164 | 3681 { |
3682 char_u *p1 = *(char_u **)s1; | |
3683 char_u *p2 = *(char_u **)s2; | |
3684 | |
3685 if (*p1 != '<' && *p2 == '<') return -1; | |
3686 if (*p1 == '<' && *p2 != '<') return 1; | |
3687 return STRCMP(p1, p2); | |
3688 } | |
3689 #endif | |
3690 | |
7 | 3691 /* |
3692 * Return FAIL if this is not an appropriate context in which to do | |
3693 * completion of anything, return OK if it is (even if there are no matches). | |
3694 * For the caller, this means that the character is just passed through like a | |
3695 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3696 */ | |
3697 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3698 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3699 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3700 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3701 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3702 int escape) /* if TRUE, escape the returned matches */ |
7 | 3703 { |
3704 int i, j; | |
3705 char_u *p1; | |
3706 char_u *p2; | |
3707 int difflen; | |
3708 int v; | |
3709 | |
3710 if (xp->xp_numfiles == -1) | |
3711 { | |
3712 set_expand_context(xp); | |
3713 cmd_showtail = expand_showtail(xp); | |
3714 } | |
3715 | |
3716 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3717 { | |
3718 beep_flush(); | |
3719 return OK; /* Something illegal on command line */ | |
3720 } | |
3721 if (xp->xp_context == EXPAND_NOTHING) | |
3722 { | |
3723 /* Caller can use the character as a normal char instead */ | |
3724 return FAIL; | |
3725 } | |
3726 | |
3727 MSG_PUTS("..."); /* show that we are busy */ | |
3728 out_flush(); | |
3729 | |
3730 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3731 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3732 |
3733 if (type == WILD_NEXT || type == WILD_PREV) | |
3734 { | |
3735 /* | |
3736 * Get next/previous match for a previous expanded pattern. | |
3737 */ | |
3738 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3739 } | |
3740 else | |
3741 { | |
3742 /* | |
3743 * Translate string into pattern and expand it. | |
3744 */ | |
1965 | 3745 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3746 xp->xp_context)) == NULL) | |
7 | 3747 p2 = NULL; |
3748 else | |
3749 { | |
2652 | 3750 int use_options = options | |
3961 | 3751 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3752 if (escape) | |
3753 use_options |= WILD_ESCAPE; | |
2652 | 3754 |
3755 if (p_wic) | |
3756 use_options += WILD_ICASE; | |
1965 | 3757 p2 = ExpandOne(xp, p1, |
3758 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3759 use_options, type); |
7 | 3760 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3761 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3762 if (p2 != NULL && type == WILD_LONGEST) |
3763 { | |
1965 | 3764 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3765 if (ccline.cmdbuff[i + j] == '*' |
3766 || ccline.cmdbuff[i + j] == '?') | |
3767 break; | |
3768 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
|
3769 VIM_CLEAR(p2); |
7 | 3770 } |
3771 } | |
3772 } | |
3773 | |
3774 if (p2 != NULL && !got_int) | |
3775 { | |
1965 | 3776 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
|
3777 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3778 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3779 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3780 xp->xp_pattern = ccline.cmdbuff + i; |
3781 } | |
3782 else | |
3783 v = OK; | |
3784 if (v == OK) | |
3785 { | |
323 | 3786 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3787 &ccline.cmdbuff[ccline.cmdpos], | |
3788 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3789 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3790 ccline.cmdlen += difflen; |
3791 ccline.cmdpos += difflen; | |
3792 } | |
3793 } | |
3794 vim_free(p2); | |
3795 | |
3796 redrawcmd(); | |
33 | 3797 cursorcmd(); |
7 | 3798 |
3799 /* When expanding a ":map" command and no matches are found, assume that | |
3800 * the key is supposed to be inserted literally */ | |
3801 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3802 return FAIL; | |
3803 | |
3804 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3805 beep_flush(); | |
3806 else if (xp->xp_numfiles == 1) | |
3807 /* free expanded pattern */ | |
3808 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3809 | |
3810 return OK; | |
3811 } | |
3812 | |
3813 /* | |
3814 * Do wildcard expansion on the string 'str'. | |
3815 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3816 * Return a pointer to allocated memory containing the new string. |
7 | 3817 * Return NULL for failure. |
3818 * | |
1412 | 3819 * "orig" is the originally expanded string, copied to allocated memory. It |
3820 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3821 * WILD_PREV "orig" should be NULL. | |
3822 * | |
838 | 3823 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3824 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3825 * |
3826 * mode = WILD_FREE: just free previously expanded matches | |
3827 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3828 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3829 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3830 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3831 * mode = WILD_ALL: return all matches concatenated | |
3832 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3833 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3834 * |
3835 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3836 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3837 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3838 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3839 * options = WILD_ADD_SLASH: add a slash after directory names | |
3840 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3841 * options = WILD_SILENT: don't print warning messages | |
3842 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3843 * options = WILD_ICASE: ignore case for files |
7 | 3844 * |
3845 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3846 */ | |
3847 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3848 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3849 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3850 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3851 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
|
3852 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3853 int mode) |
7 | 3854 { |
3855 char_u *ss = NULL; | |
3856 static int findex; | |
3857 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3858 int orig_saved = FALSE; |
7 | 3859 int i; |
3860 long_u len; | |
3861 int non_suf_match; /* number without matching suffix */ | |
3862 | |
3863 /* | |
3864 * first handle the case of using an old match | |
3865 */ | |
3866 if (mode == WILD_NEXT || mode == WILD_PREV) | |
3867 { | |
3868 if (xp->xp_numfiles > 0) | |
3869 { | |
3870 if (mode == WILD_PREV) | |
3871 { | |
3872 if (findex == -1) | |
3873 findex = xp->xp_numfiles; | |
3874 --findex; | |
3875 } | |
3876 else /* mode == WILD_NEXT */ | |
3877 ++findex; | |
3878 | |
3879 /* | |
3880 * When wrapping around, return the original string, set findex to | |
3881 * -1. | |
3882 */ | |
3883 if (findex < 0) | |
3884 { | |
3885 if (orig_save == NULL) | |
3886 findex = xp->xp_numfiles - 1; | |
3887 else | |
3888 findex = -1; | |
3889 } | |
3890 if (findex >= xp->xp_numfiles) | |
3891 { | |
3892 if (orig_save == NULL) | |
3893 findex = 0; | |
3894 else | |
3895 findex = -1; | |
3896 } | |
3897 #ifdef FEAT_WILDMENU | |
3898 if (p_wmnu) | |
3899 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
3900 findex, cmd_showtail); | |
3901 #endif | |
3902 if (findex == -1) | |
3903 return vim_strsave(orig_save); | |
3904 return vim_strsave(xp->xp_files[findex]); | |
3905 } | |
3906 else | |
3907 return NULL; | |
3908 } | |
3909 | |
1412 | 3910 /* free old names */ |
7 | 3911 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
3912 { | |
3913 FreeWild(xp->xp_numfiles, xp->xp_files); | |
3914 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
|
3915 VIM_CLEAR(orig_save); |
7 | 3916 } |
3917 findex = 0; | |
3918 | |
3919 if (mode == WILD_FREE) /* only release file name */ | |
3920 return NULL; | |
3921 | |
3922 if (xp->xp_numfiles == -1) | |
3923 { | |
3924 vim_free(orig_save); | |
3925 orig_save = orig; | |
1432 | 3926 orig_saved = TRUE; |
7 | 3927 |
3928 /* | |
3929 * Do the expansion. | |
3930 */ | |
3931 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
3932 options) == FAIL) | |
3933 { | |
3934 #ifdef FNAME_ILLEGAL | |
3935 /* Illegal file name has been silently skipped. But when there | |
3936 * are wildcards, the real problem is that there was no match, | |
3937 * causing the pattern to be added, which has illegal characters. | |
3938 */ | |
3939 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
3940 EMSG2(_(e_nomatch2), str); | |
3941 #endif | |
3942 } | |
3943 else if (xp->xp_numfiles == 0) | |
3944 { | |
3945 if (!(options & WILD_SILENT)) | |
3946 EMSG2(_(e_nomatch2), str); | |
3947 } | |
3948 else | |
3949 { | |
3950 /* Escape the matches for use on the command line. */ | |
3951 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
3952 | |
3953 /* | |
3954 * Check for matching suffixes in file names. | |
3955 */ | |
3398 | 3956 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
3957 && mode != WILD_LONGEST) | |
7 | 3958 { |
3959 if (xp->xp_numfiles) | |
3960 non_suf_match = xp->xp_numfiles; | |
3961 else | |
3962 non_suf_match = 1; | |
3963 if ((xp->xp_context == EXPAND_FILES | |
3964 || xp->xp_context == EXPAND_DIRECTORIES) | |
3965 && xp->xp_numfiles > 1) | |
3966 { | |
3967 /* | |
3968 * More than one match; check suffix. | |
3969 * The files will have been sorted on matching suffix in | |
3970 * expand_wildcards, only need to check the first two. | |
3971 */ | |
3972 non_suf_match = 0; | |
3973 for (i = 0; i < 2; ++i) | |
3974 if (match_suffix(xp->xp_files[i])) | |
3975 ++non_suf_match; | |
3976 } | |
3977 if (non_suf_match != 1) | |
3978 { | |
3979 /* Can we ever get here unless it's while expanding | |
3980 * interactively? If not, we can get rid of this all | |
3981 * together. Don't really want to wait for this message | |
3982 * (and possibly have to hit return to continue!). | |
3983 */ | |
3984 if (!(options & WILD_SILENT)) | |
3985 EMSG(_(e_toomany)); | |
3986 else if (!(options & WILD_NO_BEEP)) | |
3987 beep_flush(); | |
3988 } | |
3989 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
3990 ss = vim_strsave(xp->xp_files[0]); | |
3991 } | |
3992 } | |
3993 } | |
3994 | |
3995 /* Find longest common part */ | |
3996 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
3997 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3998 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3999 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4000 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4001 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4002 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4003 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4004 if (has_mbyte) |
7 | 4005 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4006 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
|
4007 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
|
4008 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4009 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4010 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4011 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
|
4012 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
|
4013 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4014 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4015 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4016 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
|
4017 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4018 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4019 ci = xp->xp_files[i][len]; |
4242 | 4020 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4021 || xp->xp_context == EXPAND_FILES |
714 | 4022 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4023 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4024 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4025 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4026 break; |
4027 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4028 else if (c0 != ci) |
7 | 4029 break; |
4030 } | |
4031 if (i < xp->xp_numfiles) | |
4032 { | |
4033 if (!(options & WILD_NO_BEEP)) | |
6949 | 4034 vim_beep(BO_WILD); |
7 | 4035 break; |
4036 } | |
4037 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4038 |
7 | 4039 ss = alloc((unsigned)len + 1); |
4040 if (ss) | |
419 | 4041 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4042 findex = -1; /* next p_wc gets first one */ |
4043 } | |
4044 | |
4045 /* Concatenate all matching names */ | |
4046 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4047 { | |
4048 len = 0; | |
4049 for (i = 0; i < xp->xp_numfiles; ++i) | |
4050 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4051 ss = lalloc(len, TRUE); | |
4052 if (ss != NULL) | |
4053 { | |
4054 *ss = NUL; | |
4055 for (i = 0; i < xp->xp_numfiles; ++i) | |
4056 { | |
4057 STRCAT(ss, xp->xp_files[i]); | |
4058 if (i != xp->xp_numfiles - 1) | |
4059 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4060 } | |
4061 } | |
4062 } | |
4063 | |
4064 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4065 ExpandCleanup(xp); | |
4066 | |
1412 | 4067 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4068 if (!orig_saved) |
1412 | 4069 vim_free(orig); |
4070 | |
7 | 4071 return ss; |
4072 } | |
4073 | |
4074 /* | |
4075 * Prepare an expand structure for use. | |
4076 */ | |
4077 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4078 ExpandInit(expand_T *xp) |
7 | 4079 { |
1718 | 4080 xp->xp_pattern = NULL; |
1965 | 4081 xp->xp_pattern_len = 0; |
7 | 4082 xp->xp_backslash = XP_BS_NONE; |
632 | 4083 #ifndef BACKSLASH_IN_FILENAME |
4084 xp->xp_shell = FALSE; | |
4085 #endif | |
7 | 4086 xp->xp_numfiles = -1; |
4087 xp->xp_files = NULL; | |
632 | 4088 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4089 xp->xp_arg = NULL; | |
4090 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4091 xp->xp_line = NULL; |
7 | 4092 } |
4093 | |
4094 /* | |
4095 * Cleanup an expand structure after use. | |
4096 */ | |
4097 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4098 ExpandCleanup(expand_T *xp) |
7 | 4099 { |
4100 if (xp->xp_numfiles >= 0) | |
4101 { | |
4102 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4103 xp->xp_numfiles = -1; | |
4104 } | |
4105 } | |
4106 | |
4107 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4108 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4109 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4110 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4111 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4112 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4113 int options) |
7 | 4114 { |
4115 int i; | |
4116 char_u *p; | |
4117 | |
4118 /* | |
4119 * May change home directory back to "~" | |
4120 */ | |
4121 if (options & WILD_HOME_REPLACE) | |
4122 tilde_replace(str, numfiles, files); | |
4123 | |
4124 if (options & WILD_ESCAPE) | |
4125 { | |
4126 if (xp->xp_context == EXPAND_FILES | |
2778 | 4127 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4128 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4129 || xp->xp_context == EXPAND_BUFFERS |
4130 || xp->xp_context == EXPAND_DIRECTORIES) | |
4131 { | |
4132 /* | |
4133 * Insert a backslash into a file name before a space, \, %, # | |
4134 * and wildmatch characters, except '~'. | |
4135 */ | |
4136 for (i = 0; i < numfiles; ++i) | |
4137 { | |
4138 /* for ":set path=" we need to escape spaces twice */ | |
4139 if (xp->xp_backslash == XP_BS_THREE) | |
4140 { | |
4141 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4142 if (p != NULL) | |
4143 { | |
4144 vim_free(files[i]); | |
4145 files[i] = p; | |
719 | 4146 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4147 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4148 if (p != NULL) | |
4149 { | |
4150 vim_free(files[i]); | |
4151 files[i] = p; | |
4152 } | |
4153 #endif | |
4154 } | |
4155 } | |
1589 | 4156 #ifdef BACKSLASH_IN_FILENAME |
4157 p = vim_strsave_fnameescape(files[i], FALSE); | |
4158 #else | |
1586 | 4159 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4160 #endif |
7 | 4161 if (p != NULL) |
4162 { | |
4163 vim_free(files[i]); | |
4164 files[i] = p; | |
4165 } | |
4166 | |
4167 /* If 'str' starts with "\~", replace "~" at start of | |
4168 * files[i] with "\~". */ | |
4169 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4170 escape_fname(&files[i]); |
7 | 4171 } |
4172 xp->xp_backslash = XP_BS_NONE; | |
435 | 4173 |
4174 /* If the first file starts with a '+' escape it. Otherwise it | |
4175 * could be seen as "+cmd". */ | |
4176 if (*files[0] == '+') | |
4177 escape_fname(&files[0]); | |
7 | 4178 } |
4179 else if (xp->xp_context == EXPAND_TAGS) | |
4180 { | |
4181 /* | |
4182 * Insert a backslash before characters in a tag name that | |
4183 * would terminate the ":tag" command. | |
4184 */ | |
4185 for (i = 0; i < numfiles; ++i) | |
4186 { | |
4187 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4188 if (p != NULL) | |
4189 { | |
4190 vim_free(files[i]); | |
4191 files[i] = p; | |
4192 } | |
4193 } | |
4194 } | |
4195 } | |
4196 } | |
4197 | |
4198 /* | |
1586 | 4199 * Escape special characters in "fname" for when used as a file name argument |
4200 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4201 * Returns the result in allocated memory. | |
4202 */ | |
4203 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4204 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4205 { |
1685 | 4206 char_u *p; |
1586 | 4207 #ifdef BACKSLASH_IN_FILENAME |
4208 char_u buf[20]; | |
4209 int j = 0; | |
4210 | |
5481 | 4211 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4212 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4213 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4214 buf[j++] = *p; |
4215 buf[j] = NUL; | |
1700 | 4216 p = vim_strsave_escaped(fname, buf); |
1586 | 4217 #else |
1685 | 4218 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4219 if (shell && csh_like_shell() && p != NULL) | |
4220 { | |
4221 char_u *s; | |
4222 | |
4223 /* For csh and similar shells need to put two backslashes before '!'. | |
4224 * One is taken by Vim, one by the shell. */ | |
4225 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4226 vim_free(p); | |
4227 p = s; | |
4228 } | |
1700 | 4229 #endif |
4230 | |
4231 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4232 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4233 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4234 escape_fname(&p); |
4235 | |
1685 | 4236 return p; |
1586 | 4237 } |
4238 | |
4239 /* | |
435 | 4240 * Put a backslash before the file name in "pp", which is in allocated memory. |
4241 */ | |
4242 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4243 escape_fname(char_u **pp) |
435 | 4244 { |
4245 char_u *p; | |
4246 | |
4247 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4248 if (p != NULL) | |
4249 { | |
4250 p[0] = '\\'; | |
4251 STRCPY(p + 1, *pp); | |
4252 vim_free(*pp); | |
4253 *pp = p; | |
4254 } | |
4255 } | |
4256 | |
4257 /* | |
7 | 4258 * For each file name in files[num_files]: |
4259 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4260 */ | |
4261 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4262 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4263 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4264 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4265 char_u **files) |
7 | 4266 { |
4267 int i; | |
4268 char_u *p; | |
4269 | |
4270 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4271 { | |
4272 for (i = 0; i < num_files; ++i) | |
4273 { | |
4274 p = home_replace_save(NULL, files[i]); | |
4275 if (p != NULL) | |
4276 { | |
4277 vim_free(files[i]); | |
4278 files[i] = p; | |
4279 } | |
4280 } | |
4281 } | |
4282 } | |
4283 | |
4284 /* | |
4285 * Show all matches for completion on the command line. | |
4286 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4287 * be inserted like a normal character. | |
4288 */ | |
4289 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4290 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4291 { |
4292 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4293 int num_files; | |
4294 char_u **files_found; | |
4295 int i, j, k; | |
4296 int maxlen; | |
4297 int lines; | |
4298 int columns; | |
4299 char_u *p; | |
4300 int lastlen; | |
4301 int attr; | |
4302 int showtail; | |
4303 | |
4304 if (xp->xp_numfiles == -1) | |
4305 { | |
4306 set_expand_context(xp); | |
4307 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4308 &num_files, &files_found); | |
4309 showtail = expand_showtail(xp); | |
4310 if (i != EXPAND_OK) | |
4311 return i; | |
4312 | |
4313 } | |
4314 else | |
4315 { | |
4316 num_files = xp->xp_numfiles; | |
4317 files_found = xp->xp_files; | |
4318 showtail = cmd_showtail; | |
4319 } | |
4320 | |
4321 #ifdef FEAT_WILDMENU | |
4322 if (!wildmenu) | |
4323 { | |
4324 #endif | |
4325 msg_didany = FALSE; /* lines_left will be set */ | |
4326 msg_start(); /* prepare for paging */ | |
4327 msg_putchar('\n'); | |
4328 out_flush(); | |
4329 cmdline_row = msg_row; | |
4330 msg_didany = FALSE; /* lines_left will be set again */ | |
4331 msg_start(); /* prepare for paging */ | |
4332 #ifdef FEAT_WILDMENU | |
4333 } | |
4334 #endif | |
4335 | |
4336 if (got_int) | |
4337 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4338 #ifdef FEAT_WILDMENU | |
4339 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
|
4340 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4341 #endif |
4342 else | |
4343 { | |
4344 /* find the length of the longest file name */ | |
4345 maxlen = 0; | |
4346 for (i = 0; i < num_files; ++i) | |
4347 { | |
4348 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4349 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4350 || xp->xp_context == EXPAND_BUFFERS)) |
4351 { | |
4352 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4353 j = vim_strsize(NameBuff); | |
4354 } | |
4355 else | |
4356 j = vim_strsize(L_SHOWFILE(i)); | |
4357 if (j > maxlen) | |
4358 maxlen = j; | |
4359 } | |
4360 | |
4361 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4362 lines = num_files; | |
4363 else | |
4364 { | |
4365 /* compute the number of columns and lines for the listing */ | |
4366 maxlen += 2; /* two spaces between file names */ | |
4367 columns = ((int)Columns + 2) / maxlen; | |
4368 if (columns < 1) | |
4369 columns = 1; | |
4370 lines = (num_files + columns - 1) / columns; | |
4371 } | |
4372 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4373 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4374 |
4375 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4376 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4377 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4378 msg_clr_eos(); |
4379 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
|
4380 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4381 } |
4382 | |
4383 /* list the files line by line */ | |
4384 for (i = 0; i < lines; ++i) | |
4385 { | |
4386 lastlen = 999; | |
4387 for (k = i; k < num_files; k += lines) | |
4388 { | |
4389 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4390 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4391 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4392 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4393 msg_advance(maxlen + 1); | |
4394 msg_puts(p); | |
4395 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
|
4396 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4397 break; |
4398 } | |
4399 for (j = maxlen - lastlen; --j >= 0; ) | |
4400 msg_putchar(' '); | |
4401 if (xp->xp_context == EXPAND_FILES | |
714 | 4402 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4403 || xp->xp_context == EXPAND_BUFFERS) |
4404 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4405 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4406 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4407 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4408 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4409 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4410 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4411 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4412 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4413 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4414 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
|
4415 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4416 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4417 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4418 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4419 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4420 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4421 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4422 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4423 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4424 j = mch_isdir(files_found[k]); |
7 | 4425 if (showtail) |
4426 p = L_SHOWFILE(k); | |
4427 else | |
4428 { | |
4429 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4430 TRUE); | |
4431 p = NameBuff; | |
4432 } | |
4433 } | |
4434 else | |
4435 { | |
4436 j = FALSE; | |
4437 p = L_SHOWFILE(k); | |
4438 } | |
4439 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4440 } | |
4441 if (msg_col > 0) /* when not wrapped around */ | |
4442 { | |
4443 msg_clr_eos(); | |
4444 msg_putchar('\n'); | |
4445 } | |
4446 out_flush(); /* show one line at a time */ | |
4447 if (got_int) | |
4448 { | |
4449 got_int = FALSE; | |
4450 break; | |
4451 } | |
4452 } | |
4453 | |
4454 /* | |
4455 * we redraw the command below the lines that we have just listed | |
4456 * This is a bit tricky, but it saves a lot of screen updating. | |
4457 */ | |
4458 cmdline_row = msg_row; /* will put it back later */ | |
4459 } | |
4460 | |
4461 if (xp->xp_numfiles == -1) | |
4462 FreeWild(num_files, files_found); | |
4463 | |
4464 return EXPAND_OK; | |
4465 } | |
4466 | |
4467 /* | |
4468 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4469 * Find tail of file name path, but ignore trailing "/". | |
4470 */ | |
4471 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4472 sm_gettail(char_u *s) |
7 | 4473 { |
4474 char_u *p; | |
4475 char_u *t = s; | |
4476 int had_sep = FALSE; | |
4477 | |
4478 for (p = s; *p != NUL; ) | |
4479 { | |
4480 if (vim_ispathsep(*p) | |
4481 #ifdef BACKSLASH_IN_FILENAME | |
4482 && !rem_backslash(p) | |
4483 #endif | |
4484 ) | |
4485 had_sep = TRUE; | |
4486 else if (had_sep) | |
4487 { | |
4488 t = p; | |
4489 had_sep = FALSE; | |
4490 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4491 MB_PTR_ADV(p); |
7 | 4492 } |
4493 return t; | |
4494 } | |
4495 | |
4496 /* | |
4497 * Return TRUE if we only need to show the tail of completion matches. | |
4498 * When not completing file names or there is a wildcard in the path FALSE is | |
4499 * returned. | |
4500 */ | |
4501 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4502 expand_showtail(expand_T *xp) |
7 | 4503 { |
4504 char_u *s; | |
4505 char_u *end; | |
4506 | |
4507 /* When not completing file names a "/" may mean something different. */ | |
714 | 4508 if (xp->xp_context != EXPAND_FILES |
4509 && xp->xp_context != EXPAND_SHELLCMD | |
4510 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4511 return FALSE; |
4512 | |
4513 end = gettail(xp->xp_pattern); | |
4514 if (end == xp->xp_pattern) /* there is no path separator */ | |
4515 return FALSE; | |
4516 | |
4517 for (s = xp->xp_pattern; s < end; s++) | |
4518 { | |
4519 /* Skip escaped wildcards. Only when the backslash is not a path | |
4520 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4521 if (rem_backslash(s)) | |
4522 ++s; | |
4523 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4524 return FALSE; | |
4525 } | |
4526 return TRUE; | |
4527 } | |
4528 | |
4529 /* | |
4530 * Prepare a string for expansion. | |
4531 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4532 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4533 * When expanding other names: The string will be used with regcomp(). Copy |
4534 * the name into allocated memory and prepend "^". | |
4535 */ | |
4536 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4537 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4538 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4539 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4540 int context) /* EXPAND_FILES etc. */ |
7 | 4541 { |
4542 char_u *retval; | |
4543 int i, j; | |
4544 int new_len; | |
4545 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4546 int ends_in_star; |
7 | 4547 |
714 | 4548 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4549 && context != EXPAND_FILES_IN_PATH |
714 | 4550 && context != EXPAND_SHELLCMD |
4551 && context != EXPAND_DIRECTORIES) | |
7 | 4552 { |
4553 /* | |
4554 * Matching will be done internally (on something other than files). | |
4555 * So we convert the file-matching-type wildcards into our kind for | |
4556 * use with vim_regcomp(). First work out how long it will be: | |
4557 */ | |
4558 | |
4559 /* For help tags the translation is done in find_help_tags(). | |
4560 * For a tag pattern starting with "/" no translation is needed. */ | |
4561 if (context == EXPAND_HELP | |
4562 || context == EXPAND_COLORS | |
4563 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4564 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4565 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4566 || 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
|
4567 || ((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
|
4568 || 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
|
4569 && fname[0] == '/')) |
7 | 4570 retval = vim_strnsave(fname, len); |
4571 else | |
4572 { | |
4573 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4574 for (i = 0; i < len; i++) | |
4575 { | |
4576 if (fname[i] == '*' || fname[i] == '~') | |
4577 new_len++; /* '*' needs to be replaced by ".*" | |
4578 '~' needs to be replaced by "\~" */ | |
4579 | |
4580 /* Buffer names are like file names. "." should be literal */ | |
4581 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4582 new_len++; /* "." becomes "\." */ | |
4583 | |
4584 /* Custom expansion takes care of special things, match | |
4585 * backslashes literally (perhaps also for other types?) */ | |
634 | 4586 if ((context == EXPAND_USER_DEFINED |
4587 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4588 new_len++; /* '\' becomes "\\" */ |
4589 } | |
4590 retval = alloc(new_len); | |
4591 if (retval != NULL) | |
4592 { | |
4593 retval[0] = '^'; | |
4594 j = 1; | |
4595 for (i = 0; i < len; i++, j++) | |
4596 { | |
4597 /* Skip backslash. But why? At least keep it for custom | |
4598 * expansion. */ | |
4599 if (context != EXPAND_USER_DEFINED | |
407 | 4600 && context != EXPAND_USER_LIST |
4601 && fname[i] == '\\' | |
4602 && ++i == len) | |
7 | 4603 break; |
4604 | |
4605 switch (fname[i]) | |
4606 { | |
4607 case '*': retval[j++] = '.'; | |
4608 break; | |
4609 case '~': retval[j++] = '\\'; | |
4610 break; | |
4611 case '?': retval[j] = '.'; | |
4612 continue; | |
4613 case '.': if (context == EXPAND_BUFFERS) | |
4614 retval[j++] = '\\'; | |
4615 break; | |
407 | 4616 case '\\': if (context == EXPAND_USER_DEFINED |
4617 || context == EXPAND_USER_LIST) | |
7 | 4618 retval[j++] = '\\'; |
4619 break; | |
4620 } | |
4621 retval[j] = fname[i]; | |
4622 } | |
4623 retval[j] = NUL; | |
4624 } | |
4625 } | |
4626 } | |
4627 else | |
4628 { | |
4629 retval = alloc(len + 4); | |
4630 if (retval != NULL) | |
4631 { | |
419 | 4632 vim_strncpy(retval, fname, len); |
7 | 4633 |
4634 /* | |
831 | 4635 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4636 * * would become **, which walks the whole tree. | |
7 | 4637 * ~ would be at the start of the file name, but not the tail. |
4638 * $ could be anywhere in the tail. | |
4639 * ` could be anywhere in the file name. | |
1484 | 4640 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4641 */ |
4642 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4643 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
|
4644 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4645 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4646 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4647 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4648 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4649 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4650 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4651 #endif |
7 | 4652 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4653 && !ends_in_star |
7 | 4654 && vim_strchr(tail, '$') == NULL |
4655 && vim_strchr(retval, '`') == NULL) | |
4656 retval[len++] = '*'; | |
1484 | 4657 else if (len > 0 && retval[len - 1] == '$') |
4658 --len; | |
7 | 4659 retval[len] = NUL; |
4660 } | |
4661 } | |
4662 return retval; | |
4663 } | |
4664 | |
4665 /* | |
4666 * Must parse the command line so far to work out what context we are in. | |
4667 * Completion can then be done based on that context. | |
4668 * This routine sets the variables: | |
4669 * xp->xp_pattern The start of the pattern to be expanded within | |
4670 * the command line (ends at the cursor). | |
4671 * xp->xp_context The type of thing to expand. Will be one of: | |
4672 * | |
4673 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4674 * the command line, like an unknown command. Caller | |
4675 * should beep. | |
4676 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4677 * a normal char, rather than for completion. eg | |
4678 * :s/^I/ | |
4679 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4680 * it. | |
4681 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4682 * EXPAND_FILES After command with XFILE set, or after setting | |
4683 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4684 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4685 * when we know only directories are of interest. eg | |
4686 * :set dir=^I | |
714 | 4687 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4688 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4689 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4690 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4691 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4692 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4693 * EXPAND_EVENTS Complete event names | |
4694 * EXPAND_SYNTAX Complete :syntax command arguments | |
4695 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4696 * EXPAND_AUGROUP Complete autocommand group names | |
4697 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4698 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4699 * eg :unmap a^I , :cunab x^I | |
4700 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4701 * eg :call sub^I | |
4702 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4703 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4704 * names in expressions, eg :while s^I | |
4705 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4706 * EXPAND_USER Complete user names |
7 | 4707 */ |
4708 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4709 set_expand_context(expand_T *xp) |
7 | 4710 { |
168 | 4711 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4712 if (ccline.cmdfirstc != ':' |
4713 #ifdef FEAT_EVAL | |
168 | 4714 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4715 && !ccline.input_fn |
7 | 4716 #endif |
4717 ) | |
4718 { | |
4719 xp->xp_context = EXPAND_NOTHING; | |
4720 return; | |
4721 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4722 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4723 } |
4724 | |
4725 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4726 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4727 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4728 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
|
4729 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
|
4730 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4731 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4732 { |
4733 int old_char = NUL; | |
4734 char_u *nextcomm; | |
4735 | |
4736 /* | |
4737 * Avoid a UMR warning from Purify, only save the character if it has been | |
4738 * written before. | |
4739 */ | |
4740 if (col < len) | |
4741 old_char = str[col]; | |
4742 str[col] = NUL; | |
4743 nextcomm = str; | |
168 | 4744 |
4745 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4746 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4747 { |
4748 # ifdef FEAT_CMDL_COMPL | |
168 | 4749 /* pass CMD_SIZE because there is no real command */ |
4750 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4751 # endif |
4752 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4753 else if (use_ccline && ccline.input_fn) |
531 | 4754 { |
4755 xp->xp_context = ccline.xp_context; | |
4756 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4757 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4758 xp->xp_arg = ccline.xp_arg; |
1322 | 4759 # endif |
531 | 4760 } |
168 | 4761 else |
4762 #endif | |
4763 while (nextcomm != NULL) | |
4764 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4765 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4766 /* 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
|
4767 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4768 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4769 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4770 |
7 | 4771 str[col] = old_char; |
4772 } | |
4773 | |
4774 /* | |
4775 * Expand the command line "str" from context "xp". | |
4776 * "xp" must have been set by set_cmd_context(). | |
4777 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4778 * starts. | |
4779 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4780 * cursor. | |
4781 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4782 * key that triggered expansion literally. | |
4783 * Returns EXPAND_OK otherwise. | |
4784 */ | |
4785 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4786 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4787 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4788 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
|
4789 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4790 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4791 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4792 { |
4793 char_u *file_str = NULL; | |
2652 | 4794 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4795 |
4796 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4797 { | |
4798 beep_flush(); | |
4799 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4800 } | |
4801 if (xp->xp_context == EXPAND_NOTHING) | |
4802 { | |
4803 /* Caller can use the character as a normal char instead */ | |
4804 return EXPAND_NOTHING; | |
4805 } | |
4806 | |
4807 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4808 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4809 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4810 if (file_str == NULL) |
4811 return EXPAND_UNSUCCESSFUL; | |
4812 | |
2652 | 4813 if (p_wic) |
4814 options += WILD_ICASE; | |
4815 | |
7 | 4816 /* find all files that match the description */ |
2652 | 4817 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4818 { |
4819 *matchcount = 0; | |
4820 *matches = NULL; | |
4821 } | |
4822 vim_free(file_str); | |
4823 | |
4824 return EXPAND_OK; | |
4825 } | |
4826 | |
4827 #ifdef FEAT_MULTI_LANG | |
4828 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4829 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4830 * 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
|
4831 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4832 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4833 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4834 |
4835 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4836 cleanup_help_tags(int num_file, char_u **file) |
7 | 4837 { |
4838 int i, j; | |
4839 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4840 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4841 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4842 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4843 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
|
4844 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4845 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4846 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4847 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4848 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4849 *p = NUL; |
7 | 4850 |
4851 for (i = 0; i < num_file; ++i) | |
4852 { | |
4853 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
|
4854 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4855 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4856 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4857 { |
4858 /* Sorting on priority means the same item in another language may | |
4859 * be anywhere. Search all items for a match up to the "@en". */ | |
4860 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
|
4861 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
|
4862 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 4863 break; |
4864 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4865 /* item only exists with @en, remove it */ |
7 | 4866 file[i][len] = NUL; |
4867 } | |
4868 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4869 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4870 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4871 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
|
4872 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4873 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4874 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4875 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4876 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
|
4877 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4878 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4879 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4880 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4881 } |
7 | 4882 } |
4883 #endif | |
4884 | |
4885 /* | |
4886 * Do the expansion based on xp->xp_context and "pat". | |
4887 */ | |
4888 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4889 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4890 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4891 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4892 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4893 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4894 int options) /* EW_ flags */ |
7 | 4895 { |
4896 #ifdef FEAT_CMDL_COMPL | |
4897 regmatch_T regmatch; | |
4898 #endif | |
4899 int ret; | |
4900 int flags; | |
4901 | |
4902 flags = EW_DIR; /* include directories */ | |
4903 if (options & WILD_LIST_NOTFOUND) | |
4904 flags |= EW_NOTFOUND; | |
4905 if (options & WILD_ADD_SLASH) | |
4906 flags |= EW_ADDSLASH; | |
4907 if (options & WILD_KEEP_ALL) | |
4908 flags |= EW_KEEPALL; | |
4909 if (options & WILD_SILENT) | |
4910 flags |= EW_SILENT; | |
6659 | 4911 if (options & WILD_ALLLINKS) |
4912 flags |= EW_ALLLINKS; | |
7 | 4913 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4914 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4915 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4916 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 4917 { |
4918 /* | |
4919 * Expand file or directory names. | |
4920 */ | |
4921 int free_pat = FALSE; | |
4922 int i; | |
4923 | |
4924 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
4925 * space */ | |
4926 if (xp->xp_backslash != XP_BS_NONE) | |
4927 { | |
4928 free_pat = TRUE; | |
4929 pat = vim_strsave(pat); | |
4930 for (i = 0; pat[i]; ++i) | |
4931 if (pat[i] == '\\') | |
4932 { | |
4933 if (xp->xp_backslash == XP_BS_THREE | |
4934 && pat[i + 1] == '\\' | |
4935 && pat[i + 2] == '\\' | |
4936 && pat[i + 3] == ' ') | |
1621 | 4937 STRMOVE(pat + i, pat + i + 3); |
7 | 4938 if (xp->xp_backslash == XP_BS_ONE |
4939 && pat[i + 1] == ' ') | |
1621 | 4940 STRMOVE(pat + i, pat + i + 1); |
7 | 4941 } |
4942 } | |
4943 | |
4944 if (xp->xp_context == EXPAND_FILES) | |
4945 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4946 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
|
4947 flags |= (EW_FILE | EW_PATH); |
7 | 4948 else |
4949 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 4950 if (options & WILD_ICASE) |
4951 flags |= EW_ICASE; | |
4952 | |
2016 | 4953 /* Expand wildcards, supporting %:h and the like. */ |
4954 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 4955 if (free_pat) |
4956 vim_free(pat); | |
4957 return ret; | |
4958 } | |
4959 | |
4960 *file = (char_u **)""; | |
4961 *num_file = 0; | |
4962 if (xp->xp_context == EXPAND_HELP) | |
4963 { | |
1696 | 4964 /* With an empty argument we would get all the help tags, which is |
4965 * very slow. Get matches for "help" instead. */ | |
4966 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
4967 num_file, file, FALSE) == OK) | |
7 | 4968 { |
4969 #ifdef FEAT_MULTI_LANG | |
4970 cleanup_help_tags(*num_file, *file); | |
4971 #endif | |
4972 return OK; | |
4973 } | |
4974 return FAIL; | |
4975 } | |
4976 | |
4977 #ifndef FEAT_CMDL_COMPL | |
4978 return FAIL; | |
4979 #else | |
716 | 4980 if (xp->xp_context == EXPAND_SHELLCMD) |
4981 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 4982 if (xp->xp_context == EXPAND_OLD_SETTING) |
4983 return ExpandOldSetting(num_file, file); | |
4984 if (xp->xp_context == EXPAND_BUFFERS) | |
4985 return ExpandBufnames(pat, num_file, file, options); | |
4986 if (xp->xp_context == EXPAND_TAGS | |
4987 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4988 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
4989 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 4990 { |
4991 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
4992 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
|
4993 directories); |
2929 | 4994 } |
7 | 4995 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 4996 { |
3106 | 4997 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
4998 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 4999 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5000 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5001 { |
5002 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5003 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5004 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5005 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5006 { |
5007 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
|
5008 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5009 } |
407 | 5010 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5011 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5012 return ExpandUserList(xp, num_file, file); |
407 | 5013 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5014 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5015 return ExpandPackAddDir(pat, num_file, file); |
7 | 5016 |
5017 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5018 if (regmatch.regprog == NULL) | |
5019 return FAIL; | |
5020 | |
5021 /* set ignore-case according to p_ic, p_scs and pat */ | |
5022 regmatch.rm_ic = ignorecase(pat); | |
5023 | |
5024 if (xp->xp_context == EXPAND_SETTINGS | |
5025 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5026 ret = ExpandSettings(xp, ®match, num_file, file); | |
5027 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5028 ret = ExpandMappings(®match, num_file, file); | |
5029 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5030 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5031 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5032 # endif | |
5033 else | |
5034 { | |
5035 static struct expgen | |
5036 { | |
5037 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5038 char_u *((*func)(expand_T *, int)); |
7 | 5039 int ic; |
2849 | 5040 int escaped; |
7 | 5041 } tab[] = |
5042 { | |
2849 | 5043 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5044 {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
|
5045 {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
|
5046 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5047 #ifdef FEAT_CMDHIST |
5048 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5049 #endif | |
7 | 5050 #ifdef FEAT_USR_CMDS |
2849 | 5051 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5052 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5053 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5054 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5055 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5056 #endif |
5057 #ifdef FEAT_EVAL | |
2849 | 5058 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5059 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5060 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5061 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5062 #endif |
5063 #ifdef FEAT_MENU | |
2849 | 5064 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5065 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5066 #endif |
5067 #ifdef FEAT_SYN_HL | |
2849 | 5068 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5069 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5070 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5071 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5072 #endif |
2849 | 5073 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5074 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5075 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5076 #ifdef FEAT_CSCOPE |
2849 | 5077 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5078 #endif |
1868 | 5079 #ifdef FEAT_SIGNS |
2849 | 5080 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5081 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5082 #ifdef FEAT_PROFILE |
2849 | 5083 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5084 #endif |
7 | 5085 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5086 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5087 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5088 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5089 #endif | |
5090 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5091 {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
|
5092 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5093 }; |
5094 int i; | |
5095 | |
5096 /* | |
5097 * Find a context in the table and call the ExpandGeneric() with the | |
5098 * right function to do the expansion. | |
5099 */ | |
5100 ret = FAIL; | |
1880 | 5101 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5102 if (xp->xp_context == tab[i].context) |
5103 { | |
5104 if (tab[i].ic) | |
5105 regmatch.rm_ic = TRUE; | |
2849 | 5106 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5107 tab[i].func, tab[i].escaped); |
7 | 5108 break; |
5109 } | |
5110 } | |
5111 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5112 vim_regfree(regmatch.regprog); |
7 | 5113 |
5114 return ret; | |
5115 #endif /* FEAT_CMDL_COMPL */ | |
5116 } | |
5117 | |
5118 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5119 /* | |
5120 * Expand a list of names. | |
5121 * | |
5122 * Generic function for command line completion. It calls a function to | |
5123 * obtain strings, one by one. The strings are matched against a regexp | |
5124 * program. Matching strings are copied into an array, which is returned. | |
5125 * | |
5126 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5127 */ | |
5128 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5129 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5130 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5131 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5132 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5133 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5134 char_u *((*func)(expand_T *, int)), |
7 | 5135 /* 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
|
5136 int escaped) |
7 | 5137 { |
5138 int i; | |
5139 int count = 0; | |
480 | 5140 int round; |
7 | 5141 char_u *str; |
5142 | |
5143 /* do this loop twice: | |
480 | 5144 * round == 0: count the number of matching names |
5145 * round == 1: copy the matching names into allocated memory | |
7 | 5146 */ |
480 | 5147 for (round = 0; round <= 1; ++round) |
7 | 5148 { |
5149 for (i = 0; ; ++i) | |
5150 { | |
5151 str = (*func)(xp, i); | |
5152 if (str == NULL) /* end of list */ | |
5153 break; | |
5154 if (*str == NUL) /* skip empty strings */ | |
5155 continue; | |
5156 | |
5157 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5158 { | |
480 | 5159 if (round) |
7 | 5160 { |
2849 | 5161 if (escaped) |
5162 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5163 else | |
5164 str = vim_strsave(str); | |
7 | 5165 (*file)[count] = str; |
5166 #ifdef FEAT_MENU | |
5167 if (func == get_menu_names && str != NULL) | |
5168 { | |
5169 /* test for separator added by get_menu_names() */ | |
5170 str += STRLEN(str) - 1; | |
5171 if (*str == '\001') | |
5172 *str = '.'; | |
5173 } | |
5174 #endif | |
5175 } | |
5176 ++count; | |
5177 } | |
5178 } | |
480 | 5179 if (round == 0) |
7 | 5180 { |
5181 if (count == 0) | |
5182 return OK; | |
5183 *num_file = count; | |
5184 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5185 if (*file == NULL) | |
5186 { | |
5187 *file = (char_u **)""; | |
5188 return FAIL; | |
5189 } | |
5190 count = 0; | |
5191 } | |
5192 } | |
480 | 5193 |
828 | 5194 /* Sort the results. Keep menu's in the specified order. */ |
5195 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5196 { |
5197 if (xp->xp_context == EXPAND_EXPRESSION | |
5198 || xp->xp_context == EXPAND_FUNCTIONS | |
5199 || xp->xp_context == EXPAND_USER_FUNC) | |
5200 /* <SNR> functions should be sorted to the end. */ | |
5201 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5202 sort_func_compare); | |
5203 else | |
5204 sort_strings(*file, *num_file); | |
5205 } | |
480 | 5206 |
1322 | 5207 #ifdef FEAT_CMDL_COMPL |
5208 /* Reset the variables used for special highlight names expansion, so that | |
5209 * they don't show up when getting normal highlight names by ID. */ | |
5210 reset_expand_highlight(); | |
5211 #endif | |
5212 | |
7 | 5213 return OK; |
5214 } | |
5215 | |
716 | 5216 /* |
5217 * Complete a shell command. | |
5218 * Returns FAIL or OK; | |
5219 */ | |
5220 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5221 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5222 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
|
5223 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
|
5224 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
|
5225 int flagsarg) /* EW_ flags */ |
716 | 5226 { |
5227 char_u *pat; | |
5228 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5229 char_u *path = NULL; |
716 | 5230 int mustfree = FALSE; |
5231 garray_T ga; | |
5232 char_u *buf = alloc(MAXPATHL); | |
5233 size_t l; | |
5234 char_u *s, *e; | |
5235 int flags = flagsarg; | |
5236 int ret; | |
6695 | 5237 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5238 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5239 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5240 hash_T hash; |
716 | 5241 |
5242 if (buf == NULL) | |
5243 return FAIL; | |
5244 | |
5245 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5246 * space */ | |
5247 pat = vim_strsave(filepat); | |
5248 for (i = 0; pat[i]; ++i) | |
5249 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5250 STRMOVE(pat + i, pat + i + 1); |
716 | 5251 |
6695 | 5252 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5253 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5254 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
|
5255 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5256 path = (char_u *)"."; |
5257 else | |
2630 | 5258 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5259 /* 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
|
5260 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5261 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5262 if (path == NULL) |
5263 path = (char_u *)""; | |
5264 } | |
716 | 5265 |
5266 /* | |
5267 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5268 * collect them in "ga". When "." is not in $PATH also expand for the |
5269 * current directory, to find "subdir/cmd". | |
716 | 5270 */ |
5271 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
|
5272 hash_init(&found_ht); |
6695 | 5273 for (s = path; ; s = e) |
716 | 5274 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5275 #if defined(MSWIN) |
716 | 5276 e = vim_strchr(s, ';'); |
5277 #else | |
5278 e = vim_strchr(s, ':'); | |
5279 #endif | |
5280 if (e == NULL) | |
5281 e = s + STRLEN(s); | |
5282 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5283 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
|
5284 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5285 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
|
5286 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5287 // 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
|
5288 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
|
5289 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
|
5290 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5291 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
|
5292 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5293 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
|
5294 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
|
5295 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5296 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5297 // 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
|
5298 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
|
5299 |
716 | 5300 l = e - s; |
5301 if (l > MAXPATHL - 5) | |
5302 break; | |
5303 vim_strncpy(buf, s, l); | |
5304 add_pathsep(buf); | |
5305 l = STRLEN(buf); | |
5306 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5307 | |
5308 /* Expand matches in one directory of $PATH. */ | |
5309 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5310 if (ret == OK) | |
5311 { | |
5312 if (ga_grow(&ga, *num_file) == FAIL) | |
5313 FreeWild(*num_file, *file); | |
5314 else | |
5315 { | |
5316 for (i = 0; i < *num_file; ++i) | |
5317 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5318 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5319 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5320 if (STRLEN(name) > l) |
716 | 5321 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5322 // 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
|
5323 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5324 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
|
5325 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5326 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5327 // 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
|
5328 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5329 ((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
|
5330 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
|
5331 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5332 } |
716 | 5333 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5334 vim_free(name); |
716 | 5335 } |
5336 vim_free(*file); | |
5337 } | |
5338 } | |
5339 if (*e != NUL) | |
5340 ++e; | |
5341 } | |
5342 *file = ga.ga_data; | |
5343 *num_file = ga.ga_len; | |
5344 | |
5345 vim_free(buf); | |
5346 vim_free(pat); | |
5347 if (mustfree) | |
5348 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5349 hash_clear(&found_ht); |
716 | 5350 return OK; |
5351 } | |
5352 | |
5353 | |
7 | 5354 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5355 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5356 * 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
|
5357 * return the result (either a string or a List). |
7 | 5358 */ |
407 | 5359 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5360 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
|
5361 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
|
5362 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5363 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5364 char_u ***file) |
7 | 5365 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5366 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
|
5367 typval_T args[4]; |
7 | 5368 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5369 char_u *pat = NULL; |
407 | 5370 void *ret; |
13 | 5371 struct cmdline_info save_ccline; |
7 | 5372 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5373 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5374 return NULL; |
7 | 5375 *num_file = 0; |
5376 *file = NULL; | |
5377 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5378 if (ccline.cmdbuff != NULL) |
1518 | 5379 { |
5380 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5381 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5382 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5383 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5384 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
|
5385 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5386 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
|
5387 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
|
5388 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
|
5389 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
|
5390 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
|
5391 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
|
5392 args[3].v_type = VAR_UNKNOWN; |
7 | 5393 |
13 | 5394 /* Save the cmdline, we don't know what the function may do. */ |
5395 save_ccline = ccline; | |
5396 ccline.cmdbuff = NULL; | |
5397 ccline.cmdprompt = NULL; | |
7 | 5398 current_SID = xp->xp_scriptID; |
13 | 5399 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5400 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5401 |
5402 ccline = save_ccline; | |
7 | 5403 current_SID = save_current_SID; |
1518 | 5404 if (ccline.cmdbuff != NULL) |
5405 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5406 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5407 vim_free(pat); |
407 | 5408 return ret; |
5409 } | |
5410 | |
5411 /* | |
5412 * Expand names with a function defined by the user. | |
5413 */ | |
5414 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5415 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5416 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5417 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5418 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5419 char_u ***file) |
407 | 5420 { |
5421 char_u *retstr; | |
5422 char_u *s; | |
5423 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
|
5424 int keep; |
407 | 5425 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
|
5426 int skip; |
407 | 5427 |
5428 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5429 if (retstr == NULL) | |
7 | 5430 return FAIL; |
5431 | |
5432 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5433 for (s = retstr; *s != NUL; s = e) |
7 | 5434 { |
5435 e = vim_strchr(s, '\n'); | |
5436 if (e == NULL) | |
5437 e = s + STRLEN(s); | |
5438 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
|
5439 *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
|
5440 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5441 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
|
5442 *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
|
5443 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5444 if (!skip) |
7 | 5445 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5446 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
|
5447 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5448 ((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
|
5449 ++ga.ga_len; |
7 | 5450 } |
5451 | |
5452 if (*e != NUL) | |
5453 ++e; | |
5454 } | |
407 | 5455 vim_free(retstr); |
5456 *file = ga.ga_data; | |
5457 *num_file = ga.ga_len; | |
5458 return OK; | |
5459 } | |
5460 | |
5461 /* | |
5462 * Expand names with a list returned by a function defined by the user. | |
5463 */ | |
5464 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5465 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5466 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5467 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5468 char_u ***file) |
407 | 5469 { |
5470 list_T *retlist; | |
5471 listitem_T *li; | |
5472 garray_T ga; | |
5473 | |
5474 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5475 if (retlist == NULL) | |
5476 return FAIL; | |
5477 | |
5478 ga_init2(&ga, (int)sizeof(char *), 3); | |
5479 /* Loop over the items in the list. */ | |
5480 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5481 { | |
1917 | 5482 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5483 continue; /* Skip non-string items and empty strings */ | |
407 | 5484 |
5485 if (ga_grow(&ga, 1) == FAIL) | |
5486 break; | |
5487 | |
5488 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5489 vim_strsave(li->li_tv.vval.v_string); |
407 | 5490 ++ga.ga_len; |
5491 } | |
5492 list_unref(retlist); | |
5493 | |
7 | 5494 *file = ga.ga_data; |
5495 *num_file = ga.ga_len; | |
5496 return OK; | |
5497 } | |
5498 #endif | |
5499 | |
5500 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5501 * 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
|
5502 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5503 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5504 * 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
|
5505 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5506 * 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
|
5507 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5508 * "dirnames" is an array with one or more directory names. |
7 | 5509 */ |
5510 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5511 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5512 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5513 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5514 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5515 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5516 char *dirnames[]) |
7 | 5517 { |
5518 char_u *s; | |
5519 char_u *e; | |
5873 | 5520 char_u *match; |
7 | 5521 garray_T ga; |
2929 | 5522 int i; |
5523 int pat_len; | |
7 | 5524 |
5525 *num_file = 0; | |
5526 *file = NULL; | |
2931 | 5527 pat_len = (int)STRLEN(pat); |
2929 | 5528 ga_init2(&ga, (int)sizeof(char *), 10); |
5529 | |
5530 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5531 { |
2929 | 5532 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5533 if (s == NULL) | |
5534 { | |
5535 ga_clear_strings(&ga); | |
5536 return FAIL; | |
5537 } | |
5538 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5539 globpath(p_rtp, s, &ga, 0); |
2929 | 5540 vim_free(s); |
5873 | 5541 } |
5542 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5543 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5544 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
|
5545 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5546 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
|
5547 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5548 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5549 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5550 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5551 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5552 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
|
5553 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5554 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5555 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5556 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5557 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5558 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5559 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
|
5560 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5561 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
|
5562 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5563 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5564 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5565 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5566 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5567 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
|
5568 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5569 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5570 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5571 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5572 |
5873 | 5573 for (i = 0; i < ga.ga_len; ++i) |
5574 { | |
5575 match = ((char_u **)ga.ga_data)[i]; | |
5576 s = match; | |
5577 e = s + STRLEN(s); | |
5578 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5579 { |
5873 | 5580 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5581 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5582 if (s < match || vim_ispathsep(*s)) |
5583 break; | |
5584 ++s; | |
5585 *e = NUL; | |
5586 mch_memmove(match, s, e - s + 1); | |
7 | 5587 } |
5588 } | |
5873 | 5589 |
2929 | 5590 if (ga.ga_len == 0) |
3628 | 5591 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5592 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5593 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5594 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5595 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5596 |
7 | 5597 *file = ga.ga_data; |
5598 *num_file = ga.ga_len; | |
5599 return OK; | |
5600 } | |
5601 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5602 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5603 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5604 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5605 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5606 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5607 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5608 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5609 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5610 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5611 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5612 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5613 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5614 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5615 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5616 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5617 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5618 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5619 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5620 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5621 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5622 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
|
5623 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5624 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5625 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5626 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5627 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5628 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5629 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5630 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
|
5631 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5632 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5633 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5634 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
|
5635 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5636 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
|
5637 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5638 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5639 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
|
5640 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5641 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5642 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5643 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5644 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5645 /* 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
|
5646 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5647 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5648 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5649 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5650 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5651 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5652 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5653 |
7 | 5654 #endif |
5655 | |
5656 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5657 /* | |
5658 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5659 * Adds the matches to "ga". Caller must init "ga". |
7 | 5660 */ |
5873 | 5661 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5662 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5663 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5664 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5665 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5666 int expand_options) |
7 | 5667 { |
5668 expand_T xpc; | |
5669 char_u *buf; | |
5670 int i; | |
5671 int num_p; | |
5672 char_u **p; | |
5673 | |
5674 buf = alloc(MAXPATHL); | |
5675 if (buf == NULL) | |
5873 | 5676 return; |
7 | 5677 |
632 | 5678 ExpandInit(&xpc); |
7 | 5679 xpc.xp_context = EXPAND_FILES; |
632 | 5680 |
7 | 5681 /* Loop over all entries in {path}. */ |
5682 while (*path != NUL) | |
5683 { | |
5684 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5685 copy_option_part(&path, buf, MAXPATHL, ","); | |
5686 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5687 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5688 # 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
|
5689 /* 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
|
5690 * 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
|
5691 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
|
5692 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5693 # else |
7 | 5694 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
|
5695 # endif |
7 | 5696 STRCAT(buf, file); |
1754 | 5697 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5698 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5699 { |
1754 | 5700 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5701 |
5702 if (ga_grow(ga, num_p) == OK) | |
7 | 5703 { |
5704 for (i = 0; i < num_p; ++i) | |
5705 { | |
5873 | 5706 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5707 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5708 ++ga->ga_len; |
7 | 5709 } |
5710 } | |
5873 | 5711 |
7 | 5712 FreeWild(num_p, p); |
5713 } | |
5714 } | |
5715 } | |
5716 | |
5717 vim_free(buf); | |
5718 } | |
5719 | |
5720 #endif | |
5721 | |
5722 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5723 | |
5724 /********************************* | |
5725 * Command line history stuff * | |
5726 *********************************/ | |
5727 | |
5728 /* | |
5729 * Translate a history character to the associated type number. | |
5730 */ | |
5731 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5732 hist_char2type(int c) |
7 | 5733 { |
5734 if (c == ':') | |
5735 return HIST_CMD; | |
5736 if (c == '=') | |
5737 return HIST_EXPR; | |
5738 if (c == '@') | |
5739 return HIST_INPUT; | |
5740 if (c == '>') | |
5741 return HIST_DEBUG; | |
5742 return HIST_SEARCH; /* must be '?' or '/' */ | |
5743 } | |
5744 | |
5745 /* | |
5746 * Table of history names. | |
5747 * These names are used in :history and various hist...() functions. | |
5748 * It is sufficient to give the significant prefix of a history name. | |
5749 */ | |
5750 | |
5751 static char *(history_names[]) = | |
5752 { | |
5753 "cmd", | |
5754 "search", | |
5755 "expr", | |
5756 "input", | |
5757 "debug", | |
5758 NULL | |
5759 }; | |
5760 | |
3503 | 5761 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5762 /* | |
5763 * Function given to ExpandGeneric() to obtain the possible first | |
5764 * arguments of the ":history command. | |
5765 */ | |
5766 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5767 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5768 { |
5769 static char_u compl[2] = { NUL, NUL }; | |
5770 char *short_names = ":=@>?/"; | |
3529 | 5771 int short_names_count = (int)STRLEN(short_names); |
3503 | 5772 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5773 | |
5774 if (idx < short_names_count) | |
5775 { | |
5776 compl[0] = (char_u)short_names[idx]; | |
5777 return compl; | |
5778 } | |
5779 if (idx < short_names_count + history_name_count) | |
5780 return (char_u *)history_names[idx - short_names_count]; | |
5781 if (idx == short_names_count + history_name_count) | |
5782 return (char_u *)"all"; | |
5783 return NULL; | |
5784 } | |
5785 #endif | |
5786 | |
7 | 5787 /* |
5788 * init_history() - Initialize the command line history. | |
5789 * Also used to re-allocate the history when the size changes. | |
5790 */ | |
356 | 5791 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5792 init_history(void) |
7 | 5793 { |
5794 int newlen; /* new length of history table */ | |
5795 histentry_T *temp; | |
5796 int i; | |
5797 int j; | |
5798 int type; | |
5799 | |
5800 /* | |
5801 * If size of history table changed, reallocate it | |
5802 */ | |
5803 newlen = (int)p_hi; | |
5804 if (newlen != hislen) /* history length changed */ | |
5805 { | |
5806 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5807 { | |
5808 if (newlen) | |
5809 { | |
5810 temp = (histentry_T *)lalloc( | |
5811 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5812 if (temp == NULL) /* out of memory! */ | |
5813 { | |
5814 if (type == 0) /* first one: just keep the old length */ | |
5815 { | |
5816 newlen = hislen; | |
5817 break; | |
5818 } | |
5819 /* Already changed one table, now we can only have zero | |
5820 * length for all tables. */ | |
5821 newlen = 0; | |
5822 type = -1; | |
5823 continue; | |
5824 } | |
5825 } | |
5826 else | |
5827 temp = NULL; | |
5828 if (newlen == 0 || temp != NULL) | |
5829 { | |
5830 if (hisidx[type] < 0) /* there are no entries yet */ | |
5831 { | |
5832 for (i = 0; i < newlen; ++i) | |
4258 | 5833 clear_hist_entry(&temp[i]); |
7 | 5834 } |
5835 else if (newlen > hislen) /* array becomes bigger */ | |
5836 { | |
5837 for (i = 0; i <= hisidx[type]; ++i) | |
5838 temp[i] = history[type][i]; | |
5839 j = i; | |
5840 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5841 clear_hist_entry(&temp[i]); |
7 | 5842 for ( ; j < hislen; ++i, ++j) |
5843 temp[i] = history[type][j]; | |
5844 } | |
5845 else /* array becomes smaller or 0 */ | |
5846 { | |
5847 j = hisidx[type]; | |
5848 for (i = newlen - 1; ; --i) | |
5849 { | |
5850 if (i >= 0) /* copy newest entries */ | |
5851 temp[i] = history[type][j]; | |
5852 else /* remove older entries */ | |
5853 vim_free(history[type][j].hisstr); | |
5854 if (--j < 0) | |
5855 j = hislen - 1; | |
5856 if (j == hisidx[type]) | |
5857 break; | |
5858 } | |
5859 hisidx[type] = newlen - 1; | |
5860 } | |
5861 vim_free(history[type]); | |
5862 history[type] = temp; | |
5863 } | |
5864 } | |
5865 hislen = newlen; | |
5866 } | |
5867 } | |
5868 | |
4258 | 5869 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5870 clear_hist_entry(histentry_T *hisptr) |
4258 | 5871 { |
5872 hisptr->hisnum = 0; | |
5873 hisptr->viminfo = FALSE; | |
5874 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
5875 hisptr->time_set = 0; |
4258 | 5876 } |
5877 | |
7 | 5878 /* |
5879 * Check if command line 'str' is already in history. | |
5880 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
5881 */ | |
5882 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5883 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5884 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5885 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5886 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
|
5887 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5888 int writing) /* ignore entries read from viminfo */ |
7 | 5889 { |
5890 int i; | |
5891 int last_i = -1; | |
2986 | 5892 char_u *p; |
7 | 5893 |
5894 if (hisidx[type] < 0) | |
5895 return FALSE; | |
5896 i = hisidx[type]; | |
5897 do | |
5898 { | |
5899 if (history[type][i].hisstr == NULL) | |
5900 return FALSE; | |
2986 | 5901 |
5902 /* For search history, check that the separator character matches as | |
5903 * well. */ | |
5904 p = history[type][i].hisstr; | |
5905 if (STRCMP(str, p) == 0 | |
4285 | 5906 && !(writing && history[type][i].viminfo) |
2986 | 5907 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 5908 { |
5909 if (!move_to_front) | |
5910 return TRUE; | |
5911 last_i = i; | |
5912 break; | |
5913 } | |
5914 if (--i < 0) | |
5915 i = hislen - 1; | |
5916 } while (i != hisidx[type]); | |
5917 | |
5918 if (last_i >= 0) | |
5919 { | |
5920 str = history[type][i].hisstr; | |
5921 while (i != hisidx[type]) | |
5922 { | |
5923 if (++i >= hislen) | |
5924 i = 0; | |
5925 history[type][last_i] = history[type][i]; | |
5926 last_i = i; | |
5927 } | |
4258 | 5928 history[type][i].hisnum = ++hisnum[type]; |
5929 history[type][i].viminfo = FALSE; | |
7 | 5930 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
5931 history[type][i].time_set = vim_time(); |
7 | 5932 return TRUE; |
5933 } | |
5934 return FALSE; | |
5935 } | |
5936 | |
5937 /* | |
5938 * Convert history name (from table above) to its HIST_ equivalent. | |
5939 * When "name" is empty, return "cmd" history. | |
5940 * Returns -1 for unknown history name. | |
5941 */ | |
5942 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5943 get_histtype(char_u *name) |
7 | 5944 { |
5945 int i; | |
5946 int len = (int)STRLEN(name); | |
5947 | |
5948 /* No argument: use current history. */ | |
5949 if (len == 0) | |
5950 return hist_char2type(ccline.cmdfirstc); | |
5951 | |
5952 for (i = 0; history_names[i] != NULL; ++i) | |
5953 if (STRNICMP(name, history_names[i], len) == 0) | |
5954 return i; | |
5955 | |
5956 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
5957 return hist_char2type(name[0]); | |
5958 | |
5959 return -1; | |
5960 } | |
5961 | |
5962 static int last_maptick = -1; /* last seen maptick */ | |
5963 | |
5964 /* | |
5965 * Add the given string to the given history. If the string is already in the | |
5966 * history then it is moved to the front. "histype" may be one of he HIST_ | |
5967 * values. | |
5968 */ | |
5969 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5970 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5971 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5972 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5973 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
|
5974 int sep) /* separator character used (search hist) */ |
7 | 5975 { |
5976 histentry_T *hisptr; | |
5977 int len; | |
5978 | |
5979 if (hislen == 0) /* no history */ | |
5980 return; | |
5981 | |
5467 | 5982 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
5983 return; | |
5984 | |
7 | 5985 /* |
5986 * Searches inside the same mapping overwrite each other, so that only | |
5987 * the last line is kept. Be careful not to remove a line that was moved | |
5988 * down, only lines that were added. | |
5989 */ | |
5990 if (histype == HIST_SEARCH && in_map) | |
5991 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
5992 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 5993 { |
5994 /* Current line is from the same mapping, remove it */ | |
5995 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
5996 vim_free(hisptr->hisstr); | |
4258 | 5997 clear_hist_entry(hisptr); |
7 | 5998 --hisnum[histype]; |
5999 if (--hisidx[HIST_SEARCH] < 0) | |
6000 hisidx[HIST_SEARCH] = hislen - 1; | |
6001 } | |
6002 last_maptick = -1; | |
6003 } | |
4285 | 6004 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6005 { |
6006 if (++hisidx[histype] == hislen) | |
6007 hisidx[histype] = 0; | |
6008 hisptr = &history[histype][hisidx[histype]]; | |
6009 vim_free(hisptr->hisstr); | |
6010 | |
6011 /* Store the separator after the NUL of the string. */ | |
835 | 6012 len = (int)STRLEN(new_entry); |
7 | 6013 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6014 if (hisptr->hisstr != NULL) | |
6015 hisptr->hisstr[len + 1] = sep; | |
6016 | |
6017 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6018 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6019 hisptr->time_set = vim_time(); |
7 | 6020 if (histype == HIST_SEARCH && in_map) |
6021 last_maptick = maptick; | |
6022 } | |
6023 } | |
6024 | |
6025 #if defined(FEAT_EVAL) || defined(PROTO) | |
6026 | |
6027 /* | |
6028 * Get identifier of newest history entry. | |
6029 * "histype" may be one of the HIST_ values. | |
6030 */ | |
6031 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6032 get_history_idx(int histype) |
7 | 6033 { |
6034 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6035 || hisidx[histype] < 0) | |
6036 return -1; | |
6037 | |
6038 return history[histype][hisidx[histype]].hisnum; | |
6039 } | |
6040 | |
531 | 6041 /* |
7 | 6042 * Calculate history index from a number: |
6043 * num > 0: seen as identifying number of a history entry | |
6044 * num < 0: relative position in history wrt newest entry | |
6045 * "histype" may be one of the HIST_ values. | |
6046 */ | |
6047 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6048 calc_hist_idx(int histype, int num) |
7 | 6049 { |
6050 int i; | |
6051 histentry_T *hist; | |
6052 int wrapped = FALSE; | |
6053 | |
6054 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6055 || (i = hisidx[histype]) < 0 || num == 0) | |
6056 return -1; | |
6057 | |
6058 hist = history[histype]; | |
6059 if (num > 0) | |
6060 { | |
6061 while (hist[i].hisnum > num) | |
6062 if (--i < 0) | |
6063 { | |
6064 if (wrapped) | |
6065 break; | |
6066 i += hislen; | |
6067 wrapped = TRUE; | |
6068 } | |
6069 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6070 return i; | |
6071 } | |
6072 else if (-num <= hislen) | |
6073 { | |
6074 i += num + 1; | |
6075 if (i < 0) | |
6076 i += hislen; | |
6077 if (hist[i].hisstr != NULL) | |
6078 return i; | |
6079 } | |
6080 return -1; | |
6081 } | |
6082 | |
6083 /* | |
6084 * Get a history entry by its index. | |
6085 * "histype" may be one of the HIST_ values. | |
6086 */ | |
6087 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6088 get_history_entry(int histype, int idx) |
7 | 6089 { |
6090 idx = calc_hist_idx(histype, idx); | |
6091 if (idx >= 0) | |
6092 return history[histype][idx].hisstr; | |
6093 else | |
6094 return (char_u *)""; | |
6095 } | |
6096 | |
6097 /* | |
6098 * Clear all entries of a history. | |
6099 * "histype" may be one of the HIST_ values. | |
6100 */ | |
6101 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6102 clr_history(int histype) |
7 | 6103 { |
6104 int i; | |
6105 histentry_T *hisptr; | |
6106 | |
6107 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6108 { | |
6109 hisptr = history[histype]; | |
6110 for (i = hislen; i--;) | |
6111 { | |
6112 vim_free(hisptr->hisstr); | |
4258 | 6113 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6114 hisptr++; |
7 | 6115 } |
6116 hisidx[histype] = -1; /* mark history as cleared */ | |
6117 hisnum[histype] = 0; /* reset identifier counter */ | |
6118 return OK; | |
6119 } | |
6120 return FAIL; | |
6121 } | |
6122 | |
6123 /* | |
6124 * Remove all entries matching {str} from a history. | |
6125 * "histype" may be one of the HIST_ values. | |
6126 */ | |
6127 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6128 del_history_entry(int histype, char_u *str) |
7 | 6129 { |
6130 regmatch_T regmatch; | |
6131 histentry_T *hisptr; | |
6132 int idx; | |
6133 int i; | |
6134 int last; | |
6135 int found = FALSE; | |
6136 | |
6137 regmatch.regprog = NULL; | |
6138 regmatch.rm_ic = FALSE; /* always match case */ | |
6139 if (hislen != 0 | |
6140 && histype >= 0 | |
6141 && histype < HIST_COUNT | |
6142 && *str != NUL | |
6143 && (idx = hisidx[histype]) >= 0 | |
6144 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6145 != NULL) | |
6146 { | |
6147 i = last = idx; | |
6148 do | |
6149 { | |
6150 hisptr = &history[histype][i]; | |
6151 if (hisptr->hisstr == NULL) | |
6152 break; | |
6153 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6154 { | |
6155 found = TRUE; | |
6156 vim_free(hisptr->hisstr); | |
4258 | 6157 clear_hist_entry(hisptr); |
7 | 6158 } |
6159 else | |
6160 { | |
6161 if (i != last) | |
6162 { | |
6163 history[histype][last] = *hisptr; | |
4258 | 6164 clear_hist_entry(hisptr); |
7 | 6165 } |
6166 if (--last < 0) | |
6167 last += hislen; | |
6168 } | |
6169 if (--i < 0) | |
6170 i += hislen; | |
6171 } while (i != idx); | |
6172 if (history[histype][idx].hisstr == NULL) | |
6173 hisidx[histype] = -1; | |
6174 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6175 vim_regfree(regmatch.regprog); |
7 | 6176 return found; |
6177 } | |
6178 | |
6179 /* | |
6180 * Remove an indexed entry from a history. | |
6181 * "histype" may be one of the HIST_ values. | |
6182 */ | |
6183 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6184 del_history_idx(int histype, int idx) |
7 | 6185 { |
6186 int i, j; | |
6187 | |
6188 i = calc_hist_idx(histype, idx); | |
6189 if (i < 0) | |
6190 return FALSE; | |
6191 idx = hisidx[histype]; | |
6192 vim_free(history[histype][i].hisstr); | |
6193 | |
6194 /* When deleting the last added search string in a mapping, reset | |
6195 * last_maptick, so that the last added search string isn't deleted again. | |
6196 */ | |
6197 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6198 last_maptick = -1; | |
6199 | |
6200 while (i != idx) | |
6201 { | |
6202 j = (i + 1) % hislen; | |
6203 history[histype][i] = history[histype][j]; | |
6204 i = j; | |
6205 } | |
4258 | 6206 clear_hist_entry(&history[histype][i]); |
7 | 6207 if (--i < 0) |
6208 i += hislen; | |
6209 hisidx[histype] = i; | |
6210 return TRUE; | |
6211 } | |
6212 | |
6213 #endif /* FEAT_EVAL */ | |
6214 | |
6215 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6216 /* | |
6217 * Very specific function to remove the value in ":set key=val" from the | |
6218 * history. | |
6219 */ | |
6220 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6221 remove_key_from_history(void) |
7 | 6222 { |
6223 char_u *p; | |
6224 int i; | |
6225 | |
6226 i = hisidx[HIST_CMD]; | |
6227 if (i < 0) | |
6228 return; | |
6229 p = history[HIST_CMD][i].hisstr; | |
6230 if (p != NULL) | |
6231 for ( ; *p; ++p) | |
6232 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6233 { | |
6234 p = vim_strchr(p + 3, '='); | |
6235 if (p == NULL) | |
6236 break; | |
6237 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6238 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6239 if (p[i] == '\\' && p[i + 1]) |
6240 ++i; | |
1621 | 6241 STRMOVE(p, p + i); |
7 | 6242 --p; |
6243 } | |
6244 } | |
6245 #endif | |
6246 | |
6247 #endif /* FEAT_CMDHIST */ | |
6248 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6249 #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
|
6250 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6251 * Get pointer to the command line info to use. cmdline_paste() may clear |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6252 * 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
|
6253 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6254 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6255 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6256 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6257 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6258 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6259 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6260 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6261 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
|
6262 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6263 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6264 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6265 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6266 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6267 #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
|
6268 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6269 * 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
|
6270 * 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
|
6271 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6272 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6273 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6274 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6275 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6276 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
|
6277 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6278 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6279 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6280 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
|
6281 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6282 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6283 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6284 * 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
|
6285 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6286 * 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
|
6287 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6288 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6289 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6290 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6291 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6292 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
|
6293 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6294 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6295 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6296 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6297 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6298 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6299 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6300 * 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
|
6301 * 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
|
6302 * 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
|
6303 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6304 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6305 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6306 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6307 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6308 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
|
6309 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6310 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6311 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6312 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6313 /* 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
|
6314 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6315 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6316 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6317 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6318 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6319 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6320 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6321 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6322 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6323 #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
|
6324 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6325 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6326 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6327 * 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
|
6328 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6329 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6330 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6331 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6332 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6333 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
|
6334 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6335 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6336 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6337 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6338 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6339 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6340 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6341 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6342 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6343 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6344 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6345 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6346 |
7 | 6347 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6348 /* | |
6349 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6350 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6351 * Returns OK if parsed successfully, otherwise FAIL. | |
6352 */ | |
6353 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6354 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6355 { |
6356 int len; | |
6357 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6358 varnumber_T num; |
7 | 6359 |
6360 *str = skipwhite(*str); | |
6361 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6362 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6363 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6364 *str += len; |
6365 *num1 = (int)num; | |
6366 first = TRUE; | |
6367 } | |
6368 *str = skipwhite(*str); | |
6369 if (**str == ',') /* parse "to" part of range */ | |
6370 { | |
6371 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6372 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6373 if (len > 0) |
6374 { | |
6375 *num2 = (int)num; | |
6376 *str = skipwhite(*str + len); | |
6377 } | |
6378 else if (!first) /* no number given at all */ | |
6379 return FAIL; | |
6380 } | |
6381 else if (first) /* only one number given */ | |
6382 *num2 = *num1; | |
6383 return OK; | |
6384 } | |
6385 #endif | |
6386 | |
6387 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6388 /* | |
6389 * :history command - print a history | |
6390 */ | |
6391 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6392 ex_history(exarg_T *eap) |
7 | 6393 { |
6394 histentry_T *hist; | |
6395 int histype1 = HIST_CMD; | |
6396 int histype2 = HIST_CMD; | |
6397 int hisidx1 = 1; | |
6398 int hisidx2 = -1; | |
6399 int idx; | |
6400 int i, j, k; | |
6401 char_u *end; | |
6402 char_u *arg = eap->arg; | |
6403 | |
6404 if (hislen == 0) | |
6405 { | |
6406 MSG(_("'history' option is zero")); | |
6407 return; | |
6408 } | |
6409 | |
6410 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6411 { | |
6412 end = arg; | |
6413 while (ASCII_ISALPHA(*end) | |
6414 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6415 end++; | |
6416 i = *end; | |
6417 *end = NUL; | |
6418 histype1 = get_histtype(arg); | |
6419 if (histype1 == -1) | |
6420 { | |
1853 | 6421 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6422 { |
6423 histype1 = 0; | |
6424 histype2 = HIST_COUNT-1; | |
6425 } | |
6426 else | |
6427 { | |
6428 *end = i; | |
6429 EMSG(_(e_trailing)); | |
6430 return; | |
6431 } | |
6432 } | |
6433 else | |
6434 histype2 = histype1; | |
6435 *end = i; | |
6436 } | |
6437 else | |
6438 end = arg; | |
6439 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6440 { | |
6441 EMSG(_(e_trailing)); | |
6442 return; | |
6443 } | |
6444 | |
6445 for (; !got_int && histype1 <= histype2; ++histype1) | |
6446 { | |
6447 STRCPY(IObuff, "\n # "); | |
6448 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6449 MSG_PUTS_TITLE(IObuff); | |
6450 idx = hisidx[histype1]; | |
6451 hist = history[histype1]; | |
6452 j = hisidx1; | |
6453 k = hisidx2; | |
6454 if (j < 0) | |
6455 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6456 if (k < 0) | |
6457 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6458 if (idx >= 0 && j <= k) | |
6459 for (i = idx + 1; !got_int; ++i) | |
6460 { | |
6461 if (i == hislen) | |
6462 i = 0; | |
6463 if (hist[i].hisstr != NULL | |
6464 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6465 { | |
6466 msg_putchar('\n'); | |
6467 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6468 hist[i].hisnum); | |
6469 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6470 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6471 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6472 else |
6473 STRCAT(IObuff, hist[i].hisstr); | |
6474 msg_outtrans(IObuff); | |
6475 out_flush(); | |
6476 } | |
6477 if (i == idx) | |
6478 break; | |
6479 } | |
6480 } | |
6481 } | |
6482 #endif | |
6483 | |
6484 #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
|
6485 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6486 * 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
|
6487 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6488 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
|
6489 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6490 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
|
6491 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6492 static int viminfo_add_at_front = FALSE; |
6493 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6494 static int hist_type2char(int type, int use_question); |
7 | 6495 |
6496 /* | |
6497 * Translate a history type number to the associated character. | |
6498 */ | |
6499 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6500 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6501 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6502 int use_question) /* use '?' instead of '/' */ |
7 | 6503 { |
6504 if (type == HIST_CMD) | |
6505 return ':'; | |
6506 if (type == HIST_SEARCH) | |
6507 { | |
6508 if (use_question) | |
6509 return '?'; | |
6510 else | |
6511 return '/'; | |
6512 } | |
6513 if (type == HIST_EXPR) | |
6514 return '='; | |
6515 return '@'; | |
6516 } | |
6517 | |
6518 /* | |
6519 * Prepare for reading the history from the viminfo file. | |
6520 * This allocates history arrays to store the read history lines. | |
6521 */ | |
6522 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6523 prepare_viminfo_history(int asklen, int writing) |
7 | 6524 { |
6525 int i; | |
6526 int num; | |
6527 int type; | |
6528 int len; | |
6529 | |
6530 init_history(); | |
4285 | 6531 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6532 if (asklen > hislen) |
6533 asklen = hislen; | |
6534 | |
6535 for (type = 0; type < HIST_COUNT; ++type) | |
6536 { | |
4258 | 6537 /* Count the number of empty spaces in the history list. Entries read |
6538 * from viminfo previously are also considered empty. If there are | |
6539 * more spaces available than we request, then fill them up. */ | |
7 | 6540 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6541 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6542 num++; |
6543 len = asklen; | |
6544 if (num > len) | |
6545 len = num; | |
6546 if (len <= 0) | |
6547 viminfo_history[type] = NULL; | |
6548 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6549 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6550 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6551 if (viminfo_history[type] == NULL) |
6552 len = 0; | |
6553 viminfo_hislen[type] = len; | |
6554 viminfo_hisidx[type] = 0; | |
6555 } | |
6556 } | |
6557 | |
6558 /* | |
6559 * Accept a line from the viminfo, store it in the history array when it's | |
6560 * new. | |
6561 */ | |
6562 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6563 read_viminfo_history(vir_T *virp, int writing) |
7 | 6564 { |
6565 int type; | |
6566 long_u len; | |
6567 char_u *val; | |
6568 char_u *p; | |
6569 | |
6570 type = hist_char2type(virp->vir_line[0]); | |
6571 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6572 { | |
6573 val = viminfo_readstring(virp, 1, TRUE); | |
6574 if (val != NULL && *val != NUL) | |
6575 { | |
3316 | 6576 int sep = (*val == ' ' ? NUL : *val); |
6577 | |
7 | 6578 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6579 viminfo_add_at_front, sep, writing)) |
7 | 6580 { |
6581 /* Need to re-allocate to append the separator byte. */ | |
6582 len = STRLEN(val); | |
6583 p = lalloc(len + 2, TRUE); | |
6584 if (p != NULL) | |
6585 { | |
6586 if (type == HIST_SEARCH) | |
6587 { | |
6588 /* Search entry: Move the separator from the first | |
6589 * column to after the NUL. */ | |
6590 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6591 p[len] = sep; |
7 | 6592 } |
6593 else | |
6594 { | |
6595 /* Not a search entry: No separator in the viminfo | |
6596 * file, add a NUL separator. */ | |
6597 mch_memmove(p, val, (size_t)len + 1); | |
6598 p[len + 1] = NUL; | |
6599 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6600 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
|
6601 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
|
6602 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
|
6603 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
|
6604 viminfo_hisidx[type]++; |
7 | 6605 } |
6606 } | |
6607 } | |
6608 vim_free(val); | |
6609 } | |
6610 return viminfo_readline(virp); | |
6611 } | |
6612 | |
4285 | 6613 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6614 * 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
|
6615 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6616 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6617 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6618 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6619 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6620 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6621 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6622 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6623 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6624 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6625 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6626 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
|
6627 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6628 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6629 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6630 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6631 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6632 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6633 || (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
|
6634 || 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
|
6635 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6636 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6637 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6638 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6639 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6640 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
|
6641 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6642 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6643 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6644 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6645 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
|
6646 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6647 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6648 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6649 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6650 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
|
6651 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6652 /* 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
|
6653 * 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
|
6654 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
|
6655 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6656 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6657 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6658 && (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
|
6659 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6660 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6661 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6662 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6663 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6664 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6665 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6666 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6667 /* 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
|
6668 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6669 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6670 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6671 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6672 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6673 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6674 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6675 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
|
6676 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6677 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6678 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
|
6679 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6680 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6681 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
|
6682 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6683 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
|
6684 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6685 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6686 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6687 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6688 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6689 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6690 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6691 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6692 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6693 * 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
|
6694 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6695 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6696 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6697 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6698 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6699 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6700 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6701 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6702 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6703 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6704 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6705 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6706 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6707 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6708 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6709 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6710 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6711 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6712 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6713 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6714 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6715 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6716 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6717 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6718 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6719 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6720 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6721 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6722 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6723 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
|
6724 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6725 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6726 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
|
6727 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6728 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
|
6729 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6730 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6731 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6732 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6733 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6734 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
|
6735 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6736 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6737 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6738 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6739 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6740 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6741 #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
|
6742 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6743 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6744 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6745 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6746 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
|
6747 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6748 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6749 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6750 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6751 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
|
6752 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
|
6753 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6754 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6755 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6756 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6757 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6758 * 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
|
6759 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6760 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6761 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6762 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6763 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6764 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6765 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6766 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6767 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6768 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6769 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6770 /* 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
|
6771 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6772 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
|
6773 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
|
6774 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
|
6775 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6776 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6777 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6778 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6779 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6780 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
|
6781 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
|
6782 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6783 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6784 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6785 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6786 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6787 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6788 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
|
6789 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6790 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6791 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6792 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6793 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6794 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6795 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6796 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6797 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6798 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6799 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6800 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6801 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6802 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6803 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
|
6804 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6805 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6806 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
|
6807 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
|
6808 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6809 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6810 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6811 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6812 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6813 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6814 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6815 /* |
4285 | 6816 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6817 */ | |
7 | 6818 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6819 finish_viminfo_history(vir_T *virp) |
7 | 6820 { |
6821 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6822 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6823 |
6824 for (type = 0; type < HIST_COUNT; ++type) | |
6825 { | |
6826 if (history[type] == NULL) | |
4283 | 6827 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6828 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6829 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6830 merge_history(type); |
7 | 6831 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6832 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6833 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6834 VIM_CLEAR(viminfo_history[type]); |
4327 | 6835 viminfo_hisidx[type] = 0; |
7 | 6836 } |
6837 } | |
6838 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6839 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6840 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6841 * 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
|
6842 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6843 * 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
|
6844 */ |
7 | 6845 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6846 write_viminfo_history(FILE *fp, int merge) |
7 | 6847 { |
6848 int i; | |
6849 int type; | |
6850 int num_saved; | |
4283 | 6851 int round; |
7 | 6852 |
6853 init_history(); | |
6854 if (hislen == 0) | |
6855 return; | |
6856 for (type = 0; type < HIST_COUNT; ++type) | |
6857 { | |
6858 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6859 if (num_saved == 0) | |
6860 continue; | |
6861 if (num_saved < 0) /* Use default */ | |
6862 num_saved = hislen; | |
6863 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
6864 type == HIST_CMD ? _("Command Line") : | |
6865 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6866 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6867 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6868 _("Debug Line")); |
7 | 6869 if (num_saved > hislen) |
6870 num_saved = hislen; | |
4283 | 6871 |
6872 /* | |
6873 * Merge typed and viminfo history: | |
6874 * round 1: history of typed commands. | |
6875 * round 2: history from recently read viminfo. | |
6876 */ | |
6877 for (round = 1; round <= 2; ++round) | |
6878 { | |
4307 | 6879 if (round == 1) |
6880 /* start at newest entry, somewhere in the list */ | |
6881 i = hisidx[type]; | |
6882 else if (viminfo_hisidx[type] > 0) | |
6883 /* start at newest entry, first in the list */ | |
6884 i = 0; | |
6885 else | |
6886 /* empty list */ | |
6887 i = -1; | |
4283 | 6888 if (i >= 0) |
6889 while (num_saved > 0 | |
6890 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 6891 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6892 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6893 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6894 int c = NUL; |
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 if (round == 1) |
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 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6899 timestamp = history[type][i].time_set; |
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 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6902 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6903 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6904 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6905 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6906 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6907 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6908 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6909 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6910 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6911 || !history[type][i].viminfo)) |
7 | 6912 { |
4283 | 6913 --num_saved; |
6914 fputc(hist_type2char(type, TRUE), fp); | |
6915 /* For the search history: put the separator in the | |
6916 * second column; use a space if there isn't one. */ | |
6917 if (type == HIST_SEARCH) | |
6918 { | |
6919 c = p[STRLEN(p) + 1]; | |
6920 putc(c == NUL ? ' ' : c, fp); | |
6921 } | |
6922 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6923 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6924 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6925 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6926 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6927 /* 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
|
6928 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6929 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6930 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6931 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6932 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6933 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
|
6934 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6935 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6936 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6937 } |
7 | 6938 } |
4283 | 6939 if (round == 1) |
6940 { | |
6941 /* Decrement index, loop around and stop when back at | |
6942 * the start. */ | |
6943 if (--i < 0) | |
6944 i = hislen - 1; | |
6945 if (i == hisidx[type]) | |
6946 break; | |
6947 } | |
6948 else | |
6949 { | |
6950 /* Increment index. Stop at the end in the while. */ | |
6951 ++i; | |
6952 } | |
7 | 6953 } |
4283 | 6954 } |
4285 | 6955 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 6956 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6957 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
|
6958 VIM_CLEAR(viminfo_history[type]); |
4311 | 6959 viminfo_hisidx[type] = 0; |
7 | 6960 } |
6961 } | |
6962 #endif /* FEAT_VIMINFO */ | |
6963 | |
6964 #if defined(FEAT_FKMAP) || defined(PROTO) | |
6965 /* | |
6966 * Write a character at the current cursor+offset position. | |
6967 * It is directly written into the command buffer block. | |
6968 */ | |
6969 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6970 cmd_pchar(int c, int offset) |
7 | 6971 { |
6972 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
6973 { | |
6974 EMSG(_("E198: cmd_pchar beyond the command length")); | |
6975 return; | |
6976 } | |
6977 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
6978 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
6979 } | |
6980 | |
6981 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6982 cmd_gchar(int offset) |
7 | 6983 { |
6984 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
6985 { | |
6986 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
6987 return NUL; | |
6988 } | |
6989 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
6990 } | |
6991 #endif | |
6992 | |
6993 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
6994 /* | |
6995 * Open a window on the current command line and history. Allow editing in | |
6996 * the window. Returns when the window is closed. | |
6997 * Returns: | |
6998 * CR if the command is to be executed | |
6999 * Ctrl_C if it is to be abandoned | |
7000 * K_IGNORE if editing continues | |
7001 */ | |
7002 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
|
7003 open_cmdwin(void) |
7 | 7004 { |
7005 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7006 bufref_T old_curbuf; |
7 | 7007 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7008 bufref_T bufref; |
7 | 7009 win_T *wp; |
7010 int i; | |
7011 linenr_T lnum; | |
7012 int histtype; | |
7013 garray_T winsizes; | |
7014 int save_restart_edit = restart_edit; | |
7015 int save_State = State; | |
7016 int save_exmode = exmode_active; | |
510 | 7017 #ifdef FEAT_RIGHTLEFT |
7018 int save_cmdmsg_rl = cmdmsg_rl; | |
7019 #endif | |
6145 | 7020 #ifdef FEAT_FOLDING |
7021 int save_KeyTyped; | |
7022 #endif | |
7 | 7023 |
7024 /* Can't do this recursively. Can't do it when typing a password. */ | |
7025 if (cmdwin_type != 0 | |
7026 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7027 || cmdline_star > 0 | |
7028 # endif | |
7029 ) | |
7030 { | |
7031 beep_flush(); | |
7032 return K_IGNORE; | |
7033 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7034 set_bufref(&old_curbuf, curbuf); |
7 | 7035 |
7036 /* Save current window sizes. */ | |
7037 win_size_save(&winsizes); | |
7038 | |
7039 /* Don't execute autocommands while creating the window. */ | |
1410 | 7040 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7041 |
683 | 7042 /* don't use a new tab page */ |
7043 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
|
7044 cmdmod.noswapfile = 1; |
683 | 7045 |
7 | 7046 /* Create a window for the command-line buffer. */ |
7047 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7048 { | |
7049 beep_flush(); | |
1410 | 7050 unblock_autocmds(); |
7 | 7051 return K_IGNORE; |
7052 } | |
1831 | 7053 cmdwin_type = get_cmdline_type(); |
7 | 7054 |
7055 /* Create the command-line buffer empty. */ | |
1743 | 7056 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7057 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7058 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7059 curbuf->b_p_ma = TRUE; | |
1865 | 7060 #ifdef FEAT_FOLDING |
7061 curwin->w_p_fen = FALSE; | |
7062 #endif | |
7 | 7063 # ifdef FEAT_RIGHTLEFT |
510 | 7064 curwin->w_p_rl = cmdmsg_rl; |
7065 cmdmsg_rl = FALSE; | |
7 | 7066 # endif |
2583 | 7067 RESET_BINDING(curwin); |
7 | 7068 |
7069 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7070 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7071 /* 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
|
7072 ++curbuf_lock; |
7 | 7073 |
510 | 7074 /* Showing the prompt may have set need_wait_return, reset it. */ |
7075 need_wait_return = FALSE; | |
7076 | |
1831 | 7077 histtype = hist_char2type(cmdwin_type); |
7 | 7078 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7079 { | |
7080 if (p_wc == TAB) | |
7081 { | |
7082 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7083 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7084 } | |
7085 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7086 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7087 --curbuf_lock; |
7 | 7088 |
10 | 7089 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7090 * sets 'textwidth' to 78). */ | |
7091 curbuf->b_p_tw = 0; | |
7092 | |
7 | 7093 /* Fill the buffer with the history. */ |
7094 init_history(); | |
7095 if (hislen > 0) | |
7096 { | |
7097 i = hisidx[histtype]; | |
7098 if (i >= 0) | |
7099 { | |
7100 lnum = 0; | |
7101 do | |
7102 { | |
7103 if (++i == hislen) | |
7104 i = 0; | |
7105 if (history[histtype][i].hisstr != NULL) | |
7106 ml_append(lnum++, history[histtype][i].hisstr, | |
7107 (colnr_T)0, FALSE); | |
7108 } | |
7109 while (i != hisidx[histtype]); | |
7110 } | |
7111 } | |
7112 | |
7113 /* Replace the empty last line with the current command-line and put the | |
7114 * cursor there. */ | |
7115 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7116 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7117 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7118 changed_line_abv_curs(); |
7119 invalidate_botline(); | |
743 | 7120 redraw_later(SOME_VALID); |
7 | 7121 |
7122 /* Save the command line info, can be used recursively. */ | |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7123 save_cmdline(&save_ccline); |
7 | 7124 |
7125 /* No Ex mode here! */ | |
7126 exmode_active = 0; | |
7127 | |
7128 State = NORMAL; | |
7129 # ifdef FEAT_MOUSE | |
7130 setmouse(); | |
7131 # endif | |
7132 | |
7133 /* 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
|
7134 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7135 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7136 stuffcharReadbuff(K_NOP); | |
7 | 7137 |
7138 i = RedrawingDisabled; | |
7139 RedrawingDisabled = 0; | |
7140 | |
7141 /* | |
7142 * Call the main loop until <CR> or CTRL-C is typed. | |
7143 */ | |
7144 cmdwin_result = 0; | |
168 | 7145 main_loop(TRUE, FALSE); |
7 | 7146 |
7147 RedrawingDisabled = i; | |
7148 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7149 # ifdef FEAT_FOLDING |
6145 | 7150 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7151 # endif |
6145 | 7152 |
7 | 7153 /* 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
|
7154 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7155 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7156 # ifdef FEAT_FOLDING |
6145 | 7157 /* Restore KeyTyped in case it is modified by autocommands */ |
7158 KeyTyped = save_KeyTyped; | |
7 | 7159 # endif |
7160 | |
1214 | 7161 /* Restore the command line info. */ |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7162 restore_cmdline(&save_ccline); |
7 | 7163 cmdwin_type = 0; |
7164 | |
7165 exmode_active = save_exmode; | |
7166 | |
1612 | 7167 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7168 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7169 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7170 { |
7171 cmdwin_result = Ctrl_C; | |
7172 EMSG(_("E199: Active window or buffer deleted")); | |
7173 } | |
7174 else | |
7175 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7176 # if defined(FEAT_EVAL) |
7 | 7177 /* autocmds may abort script processing */ |
7178 if (aborting() && cmdwin_result != K_IGNORE) | |
7179 cmdwin_result = Ctrl_C; | |
7180 # endif | |
7181 /* Set the new command line from the cmdline buffer. */ | |
7182 vim_free(ccline.cmdbuff); | |
510 | 7183 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7184 { |
510 | 7185 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7186 | |
7187 if (histtype == HIST_CMD) | |
7188 { | |
7189 /* Execute the command directly. */ | |
7190 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7191 cmdwin_result = CAR; | |
7192 } | |
7193 else | |
7194 { | |
7195 /* First need to cancel what we were doing. */ | |
7196 ccline.cmdbuff = NULL; | |
7197 stuffcharReadbuff(':'); | |
7198 stuffReadbuff((char_u *)p); | |
7199 stuffcharReadbuff(CAR); | |
7200 } | |
7 | 7201 } |
7202 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7203 { | |
7204 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7205 cmdwin_result = CAR; | |
7206 } | |
2839 | 7207 else if (cmdwin_result == Ctrl_C) |
7208 { | |
7209 /* :q or :close, don't execute any command | |
7210 * and don't modify the cmd window. */ | |
7211 ccline.cmdbuff = NULL; | |
7212 } | |
7 | 7213 else |
7214 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7215 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
|
7216 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7217 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
|
7218 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
|
7219 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
|
7220 ccline.cmdpos = 0; |
7 | 7221 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
|
7222 } |
7 | 7223 else |
7224 { | |
7225 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7226 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7227 ccline.cmdpos = curwin->w_cursor.col; | |
7228 if (ccline.cmdpos > ccline.cmdlen) | |
7229 ccline.cmdpos = ccline.cmdlen; | |
7230 if (cmdwin_result == K_IGNORE) | |
7231 { | |
7232 set_cmdspos_cursor(); | |
7233 redrawcmd(); | |
7234 } | |
7235 } | |
7236 | |
7237 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7238 block_autocmds(); |
6876 | 7239 # ifdef FEAT_CONCEAL |
7240 /* Avoid command-line window first character being concealed. */ | |
7241 curwin->w_p_cole = 0; | |
7242 # endif | |
7 | 7243 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7244 set_bufref(&bufref, curbuf); |
7 | 7245 win_goto(old_curwin); |
7246 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7247 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7248 /* 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
|
7249 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7250 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7251 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7252 |
7253 /* Restore window sizes. */ | |
7254 win_size_restore(&winsizes); | |
7255 | |
1410 | 7256 unblock_autocmds(); |
7 | 7257 } |
7258 | |
7259 ga_clear(&winsizes); | |
7260 restart_edit = save_restart_edit; | |
510 | 7261 # ifdef FEAT_RIGHTLEFT |
7262 cmdmsg_rl = save_cmdmsg_rl; | |
7263 # endif | |
7 | 7264 |
7265 State = save_State; | |
7266 # ifdef FEAT_MOUSE | |
7267 setmouse(); | |
7268 # endif | |
7269 | |
7270 return cmdwin_result; | |
7271 } | |
7272 #endif /* FEAT_CMDWIN */ | |
7273 | |
7274 /* | |
7275 * Used for commands that either take a simple command string argument, or: | |
7276 * cmd << endmarker | |
7277 * {script} | |
7278 * endmarker | |
7279 * Returns a pointer to allocated memory with {script} or NULL. | |
7280 */ | |
7281 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7282 script_get(exarg_T *eap, char_u *cmd) |
7 | 7283 { |
7284 char_u *theline; | |
7285 char *end_pattern = NULL; | |
7286 char dot[] = "."; | |
7287 garray_T ga; | |
7288 | |
7289 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7290 return NULL; | |
7291 | |
7292 ga_init2(&ga, 1, 0x400); | |
7293 | |
7294 if (cmd[2] != NUL) | |
7295 end_pattern = (char *)skipwhite(cmd + 2); | |
7296 else | |
7297 end_pattern = dot; | |
7298 | |
7299 for (;;) | |
7300 { | |
7301 theline = eap->getline( | |
7302 #ifdef FEAT_EVAL | |
75 | 7303 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7304 #endif |
7305 NUL, eap->cookie, 0); | |
7306 | |
7307 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7308 { |
7309 vim_free(theline); | |
7 | 7310 break; |
1694 | 7311 } |
7 | 7312 |
7313 ga_concat(&ga, theline); | |
7314 ga_append(&ga, '\n'); | |
7315 vim_free(theline); | |
7316 } | |
21 | 7317 ga_append(&ga, NUL); |
7 | 7318 |
7319 return (char_u *)ga.ga_data; | |
7320 } |