Mercurial > vim
annotate src/ex_getln.c @ 14309:15530de011bc v8.1.0170
patch 8.1.0170: invalid memory use with complicated pattern
commit https://github.com/vim/vim/commit/2338c32b53d20dc18540b1a20845bcd8a6371bff
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 8 19:07:19 2018 +0200
patch 8.1.0170: invalid memory use with complicated pattern
Problem: Invalid memory use with complicated pattern. (Andy Massimino)
Solution: Reallocate the list of listids when needed. (closes https://github.com/vim/vim/issues/3175)
Remove unnecessary function prototypes.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 08 Jul 2018 19:15:05 +0200 |
parents | c1fcfafa8d1a |
children | 5d9b450e7827 |
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 |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
144 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
145 static void set_search_match(pos_T *t); |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
146 #endif |
3164 | 147 |
12656
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 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
|
150 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
|
151 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 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
|
153 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
158 |
7 | 159 /* |
12664
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 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
|
161 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
162 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
|
163 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
|
164 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
169 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
|
170 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
171 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
172 #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
|
173 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 * 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
|
175 * 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
|
176 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
177 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 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
|
179 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
180 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
|
181 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 /* 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
|
183 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
|
184 && 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
|
185 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
186 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
|
187 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
188 #endif |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
189 |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 #ifdef FEAT_SEARCH_EXTRA |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
223 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
224 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
225 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
226 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
227 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
228 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
229 /* |
7 | 230 * getcmdline() - accept a command line starting with firstc. |
231 * | |
232 * firstc == ':' get ":" command line. | |
233 * firstc == '/' or '?' get search pattern | |
234 * firstc == '=' get expression | |
235 * firstc == '@' get text for input() function | |
236 * firstc == '>' get text for debug mode | |
237 * firstc == NUL get text for :insert command | |
238 * firstc == -1 like NUL, and break on CTRL-C | |
239 * | |
240 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
241 * command line. | |
242 * | |
243 * Careful: getcmdline() can be called recursively! | |
244 * | |
245 * Return pointer to allocated string if there is a commandline, NULL | |
246 * otherwise. | |
247 */ | |
248 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
249 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
250 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
251 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
|
252 int indent) /* indent for inside conditionals */ |
7 | 253 { |
254 int c; | |
255 int i; | |
256 int j; | |
257 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
258 int do_abbr; /* when TRUE check for abbr. */ | |
259 #ifdef FEAT_CMDHIST | |
260 char_u *lookfor = NULL; /* string to match */ | |
261 int hiscnt; /* current history line in use */ | |
262 int histype; /* history type to be used */ | |
263 #endif | |
264 #ifdef FEAT_SEARCH_EXTRA | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
265 pos_T search_start; /* where 'incsearch' starts searching */ |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
266 pos_T save_cursor; |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
267 viewstate_T init_viewstate; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
268 viewstate_T old_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
269 pos_T match_start = curwin->w_cursor; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
270 pos_T match_end; |
7 | 271 int did_incsearch = FALSE; |
272 int incsearch_postponed = FALSE; | |
273 #endif | |
274 int did_wild_list = FALSE; /* did wild_list() recently */ | |
275 int wim_index = 0; /* index in wim_flags[] */ | |
276 int res; | |
277 int save_msg_scroll = msg_scroll; | |
278 int save_State = State; /* remember State when called */ | |
279 int some_key_typed = FALSE; /* one of the keys was typed */ | |
280 #ifdef FEAT_MOUSE | |
281 /* mouse drag and release events are ignored, unless they are | |
282 * preceded with a mouse down event */ | |
283 int ignore_drag_release = TRUE; | |
284 #endif | |
285 #ifdef FEAT_EVAL | |
286 int break_ctrl_c = FALSE; | |
287 #endif | |
288 expand_T xpc; | |
289 long *b_im_ptr = NULL; | |
10861
7d82787b3020
patch 8.0.0320: warning for unused variable with small build
Christian Brabandt <cb@256bit.org>
parents:
10694
diff
changeset
|
290 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) || defined(FEAT_SEARCH_EXTRA) |
195 | 291 /* Everything that may work recursively should save and restore the |
292 * current command line in save_ccline. That includes update_screen(), a | |
293 * custom status line may invoke ":normal". */ | |
294 struct cmdline_info save_ccline; | |
295 #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
|
296 int cmdline_type; |
7 | 297 |
298 #ifdef FEAT_EVAL | |
299 if (firstc == -1) | |
300 { | |
301 firstc = NUL; | |
302 break_ctrl_c = TRUE; | |
303 } | |
304 #endif | |
305 #ifdef FEAT_RIGHTLEFT | |
306 /* start without Hebrew mapping for a command line */ | |
307 if (firstc == ':' || firstc == '=' || firstc == '>') | |
308 cmd_hkmap = 0; | |
309 #endif | |
310 | |
311 ccline.overstrike = FALSE; /* always start in insert mode */ | |
312 #ifdef FEAT_SEARCH_EXTRA | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
313 CLEAR_POS(&match_end); |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
314 save_cursor = curwin->w_cursor; /* may be restored later */ |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
315 search_start = curwin->w_cursor; |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
316 save_viewstate(&init_viewstate); |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
317 save_viewstate(&old_viewstate); |
7 | 318 #endif |
319 | |
320 /* | |
321 * set some variables for redrawcmd() | |
322 */ | |
323 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 324 ccline.cmdindent = (firstc > 0 ? indent : 0); |
325 | |
326 /* alloc initial ccline.cmdbuff */ | |
327 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 328 if (ccline.cmdbuff == NULL) |
329 return NULL; /* out of memory */ | |
330 ccline.cmdlen = ccline.cmdpos = 0; | |
331 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
|
332 sb_text_start_cmdline(); |
7 | 333 |
164 | 334 /* autoindent for :insert and :append */ |
335 if (firstc <= 0) | |
336 { | |
6929 | 337 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 338 ccline.cmdbuff[indent] = NUL; |
339 ccline.cmdpos = indent; | |
340 ccline.cmdspos = indent; | |
341 ccline.cmdlen = indent; | |
342 } | |
343 | |
7 | 344 ExpandInit(&xpc); |
1718 | 345 ccline.xpc = &xpc; |
7 | 346 |
347 #ifdef FEAT_RIGHTLEFT | |
348 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
349 && (firstc == '/' || firstc == '?')) | |
350 cmdmsg_rl = TRUE; | |
351 else | |
352 cmdmsg_rl = FALSE; | |
353 #endif | |
354 | |
355 redir_off = TRUE; /* don't redirect the typed command */ | |
356 if (!cmd_silent) | |
357 { | |
358 i = msg_scrolled; | |
359 msg_scrolled = 0; /* avoid wait_return message */ | |
360 gotocmdline(TRUE); | |
361 msg_scrolled += i; | |
362 redrawcmdprompt(); /* draw prompt or indent */ | |
363 set_cmdspos(); | |
364 } | |
365 xpc.xp_context = EXPAND_NOTHING; | |
366 xpc.xp_backslash = XP_BS_NONE; | |
632 | 367 #ifndef BACKSLASH_IN_FILENAME |
368 xpc.xp_shell = FALSE; | |
369 #endif | |
7 | 370 |
531 | 371 #if defined(FEAT_EVAL) |
372 if (ccline.input_fn) | |
373 { | |
374 xpc.xp_context = ccline.xp_context; | |
375 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 376 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 377 xpc.xp_arg = ccline.xp_arg; |
1322 | 378 # endif |
531 | 379 } |
380 #endif | |
381 | |
7 | 382 /* |
383 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
384 * doing ":@0" when register 0 doesn't contain a CR. | |
385 */ | |
386 msg_scroll = FALSE; | |
387 | |
388 State = CMDLINE; | |
389 | |
390 if (firstc == '/' || firstc == '?' || firstc == '@') | |
391 { | |
392 /* Use ":lmap" mappings for search pattern and input(). */ | |
393 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
394 b_im_ptr = &curbuf->b_p_iminsert; | |
395 else | |
396 b_im_ptr = &curbuf->b_p_imsearch; | |
397 if (*b_im_ptr == B_IMODE_LMAP) | |
398 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
399 #ifdef HAVE_INPUT_METHOD |
7 | 400 im_set_active(*b_im_ptr == B_IMODE_IM); |
401 #endif | |
402 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
403 #ifdef HAVE_INPUT_METHOD |
7 | 404 else if (p_imcmdline) |
405 im_set_active(TRUE); | |
406 #endif | |
407 | |
408 #ifdef FEAT_MOUSE | |
409 setmouse(); | |
410 #endif | |
411 #ifdef CURSOR_SHAPE | |
412 ui_cursor_shape(); /* may show different cursor shape */ | |
413 #endif | |
414 | |
571 | 415 /* When inside an autocommand for writing "exiting" may be set and |
416 * terminal mode set to cooked. Need to set raw mode here then. */ | |
417 settmode(TMODE_RAW); | |
418 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
419 /* 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
|
420 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
|
421 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
|
422 |
7 | 423 #ifdef FEAT_CMDHIST |
424 init_history(); | |
425 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
426 histype = hist_char2type(firstc); | |
427 #endif | |
428 | |
429 #ifdef FEAT_DIGRAPHS | |
1868 | 430 do_digraph(-1); /* init digraph typeahead */ |
7 | 431 #endif |
432 | |
5993 | 433 /* If something above caused an error, reset the flags, we do want to type |
434 * and execute commands. Display may be messed up a bit. */ | |
435 if (did_emsg) | |
436 redrawcmd(); | |
437 did_emsg = FALSE; | |
438 got_int = FALSE; | |
439 | |
7 | 440 /* |
441 * Collect the command string, handling editing keys. | |
442 */ | |
443 for (;;) | |
444 { | |
972 | 445 redir_off = TRUE; /* Don't redirect the typed command. |
446 Repeated, because a ":redir" inside | |
447 completion may switch it on. */ | |
7 | 448 #ifdef USE_ON_FLY_SCROLL |
449 dont_scroll = FALSE; /* allow scrolling here */ | |
450 #endif | |
451 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
452 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 |
7 | 457 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 458 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
459 /* 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
|
460 * anything, such as stop completion. */ |
1472 | 461 do |
462 { | |
463 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
|
464 } while (c == K_IGNORE || c == K_NOP); |
1472 | 465 |
7 | 466 if (KeyTyped) |
467 { | |
468 some_key_typed = TRUE; | |
469 #ifdef FEAT_RIGHTLEFT | |
470 if (cmd_hkmap) | |
471 c = hkmap(c); | |
472 # ifdef FEAT_FKMAP | |
473 if (cmd_fkmap) | |
474 c = cmdl_fkmap(c); | |
475 # endif | |
476 if (cmdmsg_rl && !KeyStuffed) | |
477 { | |
478 /* Invert horizontal movements and operations. Only when | |
479 * typed by the user directly, not when the result of a | |
480 * mapping. */ | |
481 switch (c) | |
482 { | |
483 case K_RIGHT: c = K_LEFT; break; | |
484 case K_S_RIGHT: c = K_S_LEFT; break; | |
485 case K_C_RIGHT: c = K_C_LEFT; break; | |
486 case K_LEFT: c = K_RIGHT; break; | |
487 case K_S_LEFT: c = K_S_RIGHT; break; | |
488 case K_C_LEFT: c = K_C_RIGHT; break; | |
489 } | |
490 } | |
491 #endif | |
492 } | |
493 | |
494 /* | |
495 * Ignore got_int when CTRL-C was typed here. | |
496 * Don't ignore it in :global, we really need to break then, e.g., for | |
497 * ":g/pat/normal /pat" (without the <CR>). | |
498 * Don't ignore it for the input() function. | |
499 */ | |
500 if ((c == Ctrl_C | |
501 #ifdef UNIX | |
502 || c == intr_char | |
503 #endif | |
504 ) | |
505 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
506 && firstc != '@' | |
507 #endif | |
508 #ifdef FEAT_EVAL | |
509 && !break_ctrl_c | |
510 #endif | |
511 && !global_busy) | |
512 got_int = FALSE; | |
513 | |
514 #ifdef FEAT_CMDHIST | |
515 /* free old command line when finished moving around in the history | |
516 * list */ | |
517 if (lookfor != NULL | |
180 | 518 && c != K_S_DOWN && c != K_S_UP |
230 | 519 && c != K_DOWN && c != K_UP |
7 | 520 && c != K_PAGEDOWN && c != K_PAGEUP |
521 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 522 && c != K_LEFT && c != K_RIGHT |
7 | 523 && (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
|
524 VIM_CLEAR(lookfor); |
7 | 525 #endif |
526 | |
527 /* | |
1718 | 528 * When there are matching completions to select <S-Tab> works like |
529 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 530 */ |
1718 | 531 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 532 c = Ctrl_P; |
533 | |
534 #ifdef FEAT_WILDMENU | |
535 /* Special translations for 'wildmenu' */ | |
536 if (did_wild_list && p_wmnu) | |
537 { | |
230 | 538 if (c == K_LEFT) |
7 | 539 c = Ctrl_P; |
230 | 540 else if (c == K_RIGHT) |
7 | 541 c = Ctrl_N; |
542 } | |
543 /* Hitting CR after "emenu Name.": complete submenu */ | |
544 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
545 && ccline.cmdpos > 1 | |
546 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
547 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
548 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
549 c = K_DOWN; | |
550 #endif | |
551 | |
552 /* free expanded names when finished walking through matches */ | |
553 if (xpc.xp_numfiles != -1 | |
554 && !(c == p_wc && KeyTyped) && c != p_wcm | |
555 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
556 && c != Ctrl_L) | |
557 { | |
558 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
559 did_wild_list = FALSE; | |
560 #ifdef FEAT_WILDMENU | |
230 | 561 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 562 #endif |
563 xpc.xp_context = EXPAND_NOTHING; | |
564 wim_index = 0; | |
565 #ifdef FEAT_WILDMENU | |
566 if (p_wmnu && wild_menu_showing != 0) | |
567 { | |
568 int skt = KeyTyped; | |
532 | 569 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 570 |
571 if (ccline.input_fn) | |
572 RedrawingDisabled = 0; | |
7 | 573 |
574 if (wild_menu_showing == WM_SCROLLED) | |
575 { | |
576 /* Entered command line, move it up */ | |
577 cmdline_row--; | |
578 redrawcmd(); | |
579 } | |
580 else if (save_p_ls != -1) | |
581 { | |
582 /* restore 'laststatus' and 'winminheight' */ | |
583 p_ls = save_p_ls; | |
584 p_wmh = save_p_wmh; | |
585 last_status(FALSE); | |
195 | 586 save_cmdline(&save_ccline); |
7 | 587 update_screen(VALID); /* redraw the screen NOW */ |
195 | 588 restore_cmdline(&save_ccline); |
7 | 589 redrawcmd(); |
590 save_p_ls = -1; | |
591 } | |
592 else | |
593 { | |
594 win_redraw_last_status(topframe); | |
595 redraw_statuslines(); | |
596 } | |
532 | 597 KeyTyped = skt; |
598 wild_menu_showing = 0; | |
531 | 599 if (ccline.input_fn) |
600 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 601 } |
602 #endif | |
603 } | |
604 | |
605 #ifdef FEAT_WILDMENU | |
606 /* Special translations for 'wildmenu' */ | |
607 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
608 { | |
609 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 610 if (c == K_DOWN && ccline.cmdpos > 0 |
611 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 612 c = p_wc; |
230 | 613 else if (c == K_UP) |
7 | 614 { |
615 /* Hitting <Up>: Remove one submenu name in front of the | |
616 * cursor */ | |
617 int found = FALSE; | |
618 | |
619 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
620 i = 0; | |
621 while (--j > 0) | |
622 { | |
623 /* check for start of menu name */ | |
624 if (ccline.cmdbuff[j] == ' ' | |
625 && ccline.cmdbuff[j - 1] != '\\') | |
626 { | |
627 i = j + 1; | |
628 break; | |
629 } | |
630 /* check for start of submenu name */ | |
631 if (ccline.cmdbuff[j] == '.' | |
632 && ccline.cmdbuff[j - 1] != '\\') | |
633 { | |
634 if (found) | |
635 { | |
636 i = j + 1; | |
637 break; | |
638 } | |
639 else | |
640 found = TRUE; | |
641 } | |
642 } | |
643 if (i > 0) | |
644 cmdline_del(i); | |
645 c = p_wc; | |
646 xpc.xp_context = EXPAND_NOTHING; | |
647 } | |
648 } | |
714 | 649 if ((xpc.xp_context == EXPAND_FILES |
1621 | 650 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 651 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 652 { |
653 char_u upseg[5]; | |
654 | |
655 upseg[0] = PATHSEP; | |
656 upseg[1] = '.'; | |
657 upseg[2] = '.'; | |
658 upseg[3] = PATHSEP; | |
659 upseg[4] = NUL; | |
660 | |
1318 | 661 if (c == K_DOWN |
662 && ccline.cmdpos > 0 | |
663 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
664 && (ccline.cmdpos < 3 | |
665 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 666 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
667 { | |
668 /* go down a directory */ | |
669 c = p_wc; | |
670 } | |
230 | 671 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 672 { |
673 /* If in a direct ancestor, strip off one ../ to go down */ | |
674 int found = FALSE; | |
675 | |
676 j = ccline.cmdpos; | |
677 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
678 while (--j > i) | |
679 { | |
39 | 680 #ifdef FEAT_MBYTE |
681 if (has_mbyte) | |
682 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
683 #endif | |
7 | 684 if (vim_ispathsep(ccline.cmdbuff[j])) |
685 { | |
686 found = TRUE; | |
687 break; | |
688 } | |
689 } | |
690 if (found | |
691 && ccline.cmdbuff[j - 1] == '.' | |
692 && ccline.cmdbuff[j - 2] == '.' | |
693 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
694 { | |
695 cmdline_del(j - 2); | |
696 c = p_wc; | |
697 } | |
698 } | |
230 | 699 else if (c == K_UP) |
7 | 700 { |
701 /* go up a directory */ | |
702 int found = FALSE; | |
703 | |
704 j = ccline.cmdpos - 1; | |
705 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
706 while (--j > i) | |
707 { | |
708 #ifdef FEAT_MBYTE | |
709 if (has_mbyte) | |
710 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
711 #endif | |
712 if (vim_ispathsep(ccline.cmdbuff[j]) | |
713 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
714 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
715 ccline.cmdbuff[j + 1]) == NULL |
7 | 716 #endif |
717 ) | |
718 { | |
719 if (found) | |
720 { | |
721 i = j + 1; | |
722 break; | |
723 } | |
724 else | |
725 found = TRUE; | |
726 } | |
727 } | |
728 | |
729 if (!found) | |
730 j = i; | |
731 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
732 j += 4; | |
733 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
734 && j == i) | |
735 j += 3; | |
736 else | |
737 j = 0; | |
738 if (j > 0) | |
739 { | |
740 /* TODO this is only for DOS/UNIX systems - need to put in | |
741 * machine-specific stuff here and in upseg init */ | |
742 cmdline_del(j); | |
743 put_on_cmdline(upseg + 1, 3, FALSE); | |
744 } | |
745 else if (ccline.cmdpos > i) | |
746 cmdline_del(i); | |
3204 | 747 |
748 /* Now complete in the new directory. Set KeyTyped in case the | |
749 * Up key came from a mapping. */ | |
7 | 750 c = p_wc; |
3204 | 751 KeyTyped = TRUE; |
7 | 752 } |
753 } | |
754 | |
755 #endif /* FEAT_WILDMENU */ | |
756 | |
757 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
758 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
759 if (c == Ctrl_BSL) | |
760 { | |
761 ++no_mapping; | |
762 ++allow_keys; | |
1389 | 763 c = plain_vgetc(); |
7 | 764 --no_mapping; |
765 --allow_keys; | |
3859 | 766 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
767 * is in a mapping. */ | |
768 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
769 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 770 { |
771 vungetc(c); | |
772 c = Ctrl_BSL; | |
773 } | |
774 #ifdef FEAT_EVAL | |
775 else if (c == 'e') | |
776 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
777 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
778 int len; |
7 | 779 |
780 /* | |
781 * Replace the command line with the result of an expression. | |
625 | 782 * Need to save and restore the current command line, to be |
783 * able to enter a new one... | |
7 | 784 */ |
785 if (ccline.cmdpos == ccline.cmdlen) | |
786 new_cmdpos = 99999; /* keep it at the end */ | |
787 else | |
788 new_cmdpos = ccline.cmdpos; | |
95 | 789 |
790 save_cmdline(&save_ccline); | |
7 | 791 c = get_expr_register(); |
95 | 792 restore_cmdline(&save_ccline); |
7 | 793 if (c == '=') |
794 { | |
634 | 795 /* Need to save and restore ccline. And set "textlock" |
632 | 796 * to avoid nasty things like going to another buffer when |
797 * evaluating an expression. */ | |
95 | 798 save_cmdline(&save_ccline); |
634 | 799 ++textlock; |
7 | 800 p = get_expr_line(); |
634 | 801 --textlock; |
95 | 802 restore_cmdline(&save_ccline); |
2617 | 803 |
804 if (p != NULL) | |
7 | 805 { |
2617 | 806 len = (int)STRLEN(p); |
807 if (realloc_cmdbuff(len + 1) == OK) | |
808 { | |
809 ccline.cmdlen = len; | |
810 STRCPY(ccline.cmdbuff, p); | |
811 vim_free(p); | |
812 | |
813 /* Restore the cursor or use the position set with | |
814 * set_cmdline_pos(). */ | |
815 if (new_cmdpos > ccline.cmdlen) | |
816 ccline.cmdpos = ccline.cmdlen; | |
817 else | |
818 ccline.cmdpos = new_cmdpos; | |
819 | |
820 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
821 redrawcmd(); | |
822 goto cmdline_changed; | |
823 } | |
7 | 824 } |
825 } | |
826 beep_flush(); | |
2636 | 827 got_int = FALSE; /* don't abandon the command line */ |
828 did_emsg = FALSE; | |
829 emsg_on_display = FALSE; | |
830 redrawcmd(); | |
831 goto cmdline_not_changed; | |
7 | 832 } |
833 #endif | |
834 else | |
835 { | |
836 if (c == Ctrl_G && p_im && restart_edit == 0) | |
837 restart_edit = 'a'; | |
838 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
839 in history */ | |
840 goto returncmd; /* back to Normal mode */ | |
841 } | |
842 } | |
843 | |
844 #ifdef FEAT_CMDWIN | |
845 if (c == cedit_key || c == K_CMDWIN) | |
846 { | |
6211 | 847 if (ex_normal_busy == 0 && got_int == FALSE) |
848 { | |
849 /* | |
850 * Open a window to edit the command line (and history). | |
851 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
852 c = open_cmdwin(); |
6211 | 853 some_key_typed = TRUE; |
854 } | |
7 | 855 } |
856 # ifdef FEAT_DIGRAPHS | |
857 else | |
858 # endif | |
859 #endif | |
860 #ifdef FEAT_DIGRAPHS | |
861 c = do_digraph(c); | |
862 #endif | |
863 | |
864 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
865 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
866 { | |
168 | 867 /* In Ex mode a backslash escapes a newline. */ |
868 if (exmode_active | |
869 && c != ESC | |
1318 | 870 && ccline.cmdpos == ccline.cmdlen |
168 | 871 && ccline.cmdpos > 0 |
872 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
873 { | |
874 if (c == K_KENTER) | |
875 c = '\n'; | |
876 } | |
877 else | |
7 | 878 { |
168 | 879 gotesc = FALSE; /* Might have typed ESC previously, don't |
880 truncate the cmdline now. */ | |
881 if (ccheck_abbr(c + ABBR_OFF)) | |
882 goto cmdline_changed; | |
883 if (!cmd_silent) | |
884 { | |
885 windgoto(msg_row, 0); | |
886 out_flush(); | |
887 } | |
888 break; | |
7 | 889 } |
890 } | |
891 | |
892 /* | |
893 * Completion for 'wildchar' or 'wildcharm' key. | |
894 * - hitting <ESC> twice means: abandon command line. | |
895 * - wildcard expansion is only done when the 'wildchar' key is really | |
896 * typed, not when it comes from a macro | |
897 */ | |
898 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
899 { | |
900 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
901 { | |
902 /* if 'wildmode' contains "list" may still need to list */ | |
903 if (xpc.xp_numfiles > 1 | |
904 && !did_wild_list | |
905 && (wim_flags[wim_index] & WIM_LIST)) | |
906 { | |
907 (void)showmatches(&xpc, FALSE); | |
908 redrawcmd(); | |
909 did_wild_list = TRUE; | |
910 } | |
911 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 912 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
913 firstc != '@'); | |
7 | 914 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 915 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
916 firstc != '@'); | |
7 | 917 else |
918 res = OK; /* don't insert 'wildchar' now */ | |
919 } | |
920 else /* typed p_wc first time */ | |
921 { | |
922 wim_index = 0; | |
923 j = ccline.cmdpos; | |
924 /* if 'wildmode' first contains "longest", get longest | |
925 * common part */ | |
926 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 927 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
928 firstc != '@'); | |
7 | 929 else |
3961 | 930 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
931 firstc != '@'); | |
7 | 932 |
933 /* if interrupted while completing, behave like it failed */ | |
934 if (got_int) | |
935 { | |
936 (void)vpeekc(); /* remove <C-C> from input stream */ | |
937 got_int = FALSE; /* don't abandon the command line */ | |
938 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
939 #ifdef FEAT_WILDMENU | |
940 xpc.xp_context = EXPAND_NOTHING; | |
941 #endif | |
942 goto cmdline_changed; | |
943 } | |
944 | |
945 /* when more than one match, and 'wildmode' first contains | |
946 * "list", or no change and 'wildmode' contains "longest,list", | |
947 * list all matches */ | |
948 if (res == OK && xpc.xp_numfiles > 1) | |
949 { | |
950 /* a "longest" that didn't do anything is skipped (but not | |
951 * "list:longest") */ | |
952 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
953 wim_index = 1; | |
954 if ((wim_flags[wim_index] & WIM_LIST) | |
955 #ifdef FEAT_WILDMENU | |
956 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
957 #endif | |
958 ) | |
959 { | |
960 if (!(wim_flags[0] & WIM_LONGEST)) | |
961 { | |
962 #ifdef FEAT_WILDMENU | |
963 int p_wmnu_save = p_wmnu; | |
964 p_wmnu = 0; | |
965 #endif | |
3961 | 966 /* remove match */ |
967 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 968 #ifdef FEAT_WILDMENU |
969 p_wmnu = p_wmnu_save; | |
970 #endif | |
971 } | |
972 #ifdef FEAT_WILDMENU | |
973 (void)showmatches(&xpc, p_wmnu | |
974 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
975 #else | |
976 (void)showmatches(&xpc, FALSE); | |
977 #endif | |
978 redrawcmd(); | |
979 did_wild_list = TRUE; | |
980 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 981 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
982 firstc != '@'); | |
7 | 983 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 984 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
985 firstc != '@'); | |
7 | 986 } |
987 else | |
6949 | 988 vim_beep(BO_WILD); |
7 | 989 } |
990 #ifdef FEAT_WILDMENU | |
991 else if (xpc.xp_numfiles == -1) | |
992 xpc.xp_context = EXPAND_NOTHING; | |
993 #endif | |
994 } | |
995 if (wim_index < 3) | |
996 ++wim_index; | |
997 if (c == ESC) | |
998 gotesc = TRUE; | |
999 if (res == OK) | |
1000 goto cmdline_changed; | |
1001 } | |
1002 | |
1003 gotesc = FALSE; | |
1004 | |
1005 /* <S-Tab> goes to last match, in a clumsy way */ | |
1006 if (c == K_S_TAB && KeyTyped) | |
1007 { | |
3961 | 1008 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1009 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1010 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1011 goto cmdline_changed; |
1012 } | |
1013 | |
1014 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1015 c = NL; | |
1016 | |
1017 do_abbr = TRUE; /* default: check for abbreviation */ | |
1018 | |
1019 /* | |
1020 * Big switch for a typed command line character. | |
1021 */ | |
1022 switch (c) | |
1023 { | |
1024 case K_BS: | |
1025 case Ctrl_H: | |
1026 case K_DEL: | |
1027 case K_KDEL: | |
1028 case Ctrl_W: | |
1029 #ifdef FEAT_FKMAP | |
1030 if (cmd_fkmap && c == K_BS) | |
1031 c = K_DEL; | |
1032 #endif | |
1033 if (c == K_KDEL) | |
1034 c = K_DEL; | |
1035 | |
1036 /* | |
1037 * delete current character is the same as backspace on next | |
1038 * character, except at end of line | |
1039 */ | |
1040 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1041 ++ccline.cmdpos; | |
1042 #ifdef FEAT_MBYTE | |
1043 if (has_mbyte && c == K_DEL) | |
1044 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1045 ccline.cmdbuff + ccline.cmdpos); | |
1046 #endif | |
1047 if (ccline.cmdpos > 0) | |
1048 { | |
1049 char_u *p; | |
1050 | |
1051 j = ccline.cmdpos; | |
1052 p = ccline.cmdbuff + j; | |
1053 #ifdef FEAT_MBYTE | |
1054 if (has_mbyte) | |
1055 { | |
1056 p = mb_prevptr(ccline.cmdbuff, p); | |
1057 if (c == Ctrl_W) | |
1058 { | |
1059 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1060 p = mb_prevptr(ccline.cmdbuff, p); | |
1061 i = mb_get_class(p); | |
1062 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1063 p = mb_prevptr(ccline.cmdbuff, p); | |
1064 if (mb_get_class(p) != i) | |
474 | 1065 p += (*mb_ptr2len)(p); |
7 | 1066 } |
1067 } | |
1068 else | |
1069 #endif | |
1070 if (c == Ctrl_W) | |
1071 { | |
1072 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1073 --p; | |
1074 i = vim_iswordc(p[-1]); | |
1075 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1076 && vim_iswordc(p[-1]) == i) | |
1077 --p; | |
1078 } | |
1079 else | |
1080 --p; | |
1081 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1082 ccline.cmdlen -= j - ccline.cmdpos; | |
1083 i = ccline.cmdpos; | |
1084 while (i < ccline.cmdlen) | |
1085 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1086 | |
1087 /* Truncate at the end, required for multi-byte chars. */ | |
1088 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1089 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1090 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1091 { |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1092 search_start = save_cursor; |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1093 /* 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
|
1094 * won't be restored at the wrong position */ |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
1095 old_viewstate = init_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1096 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1097 #endif |
7 | 1098 redrawcmd(); |
1099 } | |
1100 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1101 && ccline.cmdprompt == NULL && indent == 0) | |
1102 { | |
1103 /* In ex and debug mode it doesn't make sense to return. */ | |
1104 if (exmode_active | |
1105 #ifdef FEAT_EVAL | |
1106 || ccline.cmdfirstc == '>' | |
1107 #endif | |
1108 ) | |
1109 goto cmdline_not_changed; | |
1110 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1111 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1112 if (!cmd_silent) |
1113 { | |
1114 #ifdef FEAT_RIGHTLEFT | |
1115 if (cmdmsg_rl) | |
1116 msg_col = Columns; | |
1117 else | |
1118 #endif | |
1119 msg_col = 0; | |
1120 msg_putchar(' '); /* delete ':' */ | |
1121 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1122 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1123 if (ccline.cmdlen == 0) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1124 search_start = save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1125 #endif |
7 | 1126 redraw_cmdline = TRUE; |
1127 goto returncmd; /* back to cmd mode */ | |
1128 } | |
1129 goto cmdline_changed; | |
1130 | |
1131 case K_INS: | |
1132 case K_KINS: | |
1133 #ifdef FEAT_FKMAP | |
1134 /* if Farsi mode set, we are in reverse insert mode - | |
1135 Do not change the mode */ | |
1136 if (cmd_fkmap) | |
1137 beep_flush(); | |
1138 else | |
1139 #endif | |
1140 ccline.overstrike = !ccline.overstrike; | |
1141 #ifdef CURSOR_SHAPE | |
1142 ui_cursor_shape(); /* may show different cursor shape */ | |
1143 #endif | |
1144 goto cmdline_not_changed; | |
1145 | |
1146 case Ctrl_HAT: | |
782 | 1147 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1148 { |
1149 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1150 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1151 #ifdef HAVE_INPUT_METHOD |
7 | 1152 im_set_active(FALSE); /* Disable input method */ |
1153 #endif | |
1154 if (b_im_ptr != NULL) | |
1155 { | |
1156 if (State & LANGMAP) | |
1157 *b_im_ptr = B_IMODE_LMAP; | |
1158 else | |
1159 *b_im_ptr = B_IMODE_NONE; | |
1160 } | |
1161 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1162 #ifdef HAVE_INPUT_METHOD |
7 | 1163 else |
1164 { | |
1165 /* There are no ":lmap" mappings, toggle IM. When | |
1166 * 'imdisable' is set don't try getting the status, it's | |
1167 * always off. */ | |
1168 if ((p_imdisable && b_im_ptr != NULL) | |
1169 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1170 { | |
1171 im_set_active(FALSE); /* Disable input method */ | |
1172 if (b_im_ptr != NULL) | |
1173 *b_im_ptr = B_IMODE_NONE; | |
1174 } | |
1175 else | |
1176 { | |
1177 im_set_active(TRUE); /* Enable input method */ | |
1178 if (b_im_ptr != NULL) | |
1179 *b_im_ptr = B_IMODE_IM; | |
1180 } | |
1181 } | |
1182 #endif | |
1183 if (b_im_ptr != NULL) | |
1184 { | |
1185 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1186 set_iminsert_global(); | |
1187 else | |
1188 set_imsearch_global(); | |
1189 } | |
1190 #ifdef CURSOR_SHAPE | |
1191 ui_cursor_shape(); /* may show different cursor shape */ | |
1192 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1193 #if defined(FEAT_KEYMAP) |
7 | 1194 /* Show/unshow value of 'keymap' in status lines later. */ |
1195 status_redraw_curbuf(); | |
1196 #endif | |
1197 goto cmdline_not_changed; | |
1198 | |
1199 /* case '@': only in very old vi */ | |
1200 case Ctrl_U: | |
1201 /* delete all characters left of the cursor */ | |
1202 j = ccline.cmdpos; | |
1203 ccline.cmdlen -= j; | |
1204 i = ccline.cmdpos = 0; | |
1205 while (i < ccline.cmdlen) | |
1206 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1207 /* Truncate at the end, required for multi-byte chars. */ | |
1208 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1209 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1210 if (ccline.cmdlen == 0) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1211 search_start = save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1212 #endif |
7 | 1213 redrawcmd(); |
1214 goto cmdline_changed; | |
1215 | |
1216 #ifdef FEAT_CLIPBOARD | |
1217 case Ctrl_Y: | |
1218 /* Copy the modeless selection, if there is one. */ | |
1219 if (clip_star.state != SELECT_CLEARED) | |
1220 { | |
1221 if (clip_star.state == SELECT_DONE) | |
1222 clip_copy_modeless_selection(TRUE); | |
1223 goto cmdline_not_changed; | |
1224 } | |
1225 break; | |
1226 #endif | |
1227 | |
1228 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1229 case Ctrl_C: | |
571 | 1230 /* In exmode it doesn't make sense to return. Except when |
161 | 1231 * ":normal" runs out of characters. */ |
1232 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1233 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1234 goto cmdline_not_changed; |
1235 | |
1236 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1237 putting it in history */ | |
1238 goto returncmd; /* back to cmd mode */ | |
1239 | |
1240 case Ctrl_R: /* insert register */ | |
1241 #ifdef USE_ON_FLY_SCROLL | |
1242 dont_scroll = TRUE; /* disallow scrolling here */ | |
1243 #endif | |
1244 putcmdline('"', TRUE); | |
1245 ++no_mapping; | |
1389 | 1246 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1247 if (i == Ctrl_O) |
1248 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1249 if (i == Ctrl_R) | |
1389 | 1250 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
|
1251 extra_char = NUL; |
7 | 1252 --no_mapping; |
1253 #ifdef FEAT_EVAL | |
1254 /* | |
1255 * Insert the result of an expression. | |
1256 * Need to save the current command line, to be able to enter | |
1257 * a new one... | |
1258 */ | |
1259 new_cmdpos = -1; | |
1260 if (c == '=') | |
1261 { | |
1262 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1263 { | |
1264 beep_flush(); | |
1265 c = ESC; | |
1266 } | |
1267 else | |
1268 { | |
95 | 1269 save_cmdline(&save_ccline); |
7 | 1270 c = get_expr_register(); |
95 | 1271 restore_cmdline(&save_ccline); |
7 | 1272 } |
1273 } | |
1274 #endif | |
1275 if (c != ESC) /* use ESC to cancel inserting register */ | |
1276 { | |
1015 | 1277 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1278 |
613 | 1279 #ifdef FEAT_EVAL |
606 | 1280 /* When there was a serious error abort getting the |
1281 * command line. */ | |
1282 if (aborting()) | |
1283 { | |
1284 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1285 putting it in history */ | |
1286 goto returncmd; /* back to cmd mode */ | |
1287 } | |
613 | 1288 #endif |
7 | 1289 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1290 #ifdef FEAT_EVAL | |
1291 if (new_cmdpos >= 0) | |
1292 { | |
1293 /* set_cmdline_pos() was used */ | |
1294 if (new_cmdpos > ccline.cmdlen) | |
1295 ccline.cmdpos = ccline.cmdlen; | |
1296 else | |
1297 ccline.cmdpos = new_cmdpos; | |
1298 } | |
1299 #endif | |
1300 } | |
1301 redrawcmd(); | |
1302 goto cmdline_changed; | |
1303 | |
1304 case Ctrl_D: | |
1305 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1306 break; /* Use ^D as normal char instead */ | |
1307 | |
1308 redrawcmd(); | |
1309 continue; /* don't do incremental search now */ | |
1310 | |
1311 case K_RIGHT: | |
1312 case K_S_RIGHT: | |
1313 case K_C_RIGHT: | |
1314 do | |
1315 { | |
1316 if (ccline.cmdpos >= ccline.cmdlen) | |
1317 break; | |
1318 i = cmdline_charsize(ccline.cmdpos); | |
1319 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1320 break; | |
1321 ccline.cmdspos += i; | |
1322 #ifdef FEAT_MBYTE | |
1323 if (has_mbyte) | |
474 | 1324 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1325 + ccline.cmdpos); |
1326 else | |
1327 #endif | |
1328 ++ccline.cmdpos; | |
1329 } | |
180 | 1330 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1331 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1332 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1333 #ifdef FEAT_MBYTE | |
1334 if (has_mbyte) | |
1335 set_cmdspos_cursor(); | |
1336 #endif | |
1337 goto cmdline_not_changed; | |
1338 | |
1339 case K_LEFT: | |
1340 case K_S_LEFT: | |
1341 case K_C_LEFT: | |
1456 | 1342 if (ccline.cmdpos == 0) |
1343 goto cmdline_not_changed; | |
7 | 1344 do |
1345 { | |
1346 --ccline.cmdpos; | |
1347 #ifdef FEAT_MBYTE | |
1348 if (has_mbyte) /* move to first byte of char */ | |
1349 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1350 ccline.cmdbuff + ccline.cmdpos); | |
1351 #endif | |
1352 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1353 } | |
1456 | 1354 while (ccline.cmdpos > 0 |
1355 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1356 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1357 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1358 #ifdef FEAT_MBYTE | |
1359 if (has_mbyte) | |
1360 set_cmdspos_cursor(); | |
1361 #endif | |
1362 goto cmdline_not_changed; | |
1363 | |
1364 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
|
1365 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1366 goto cmdline_not_changed; |
7 | 1367 |
625 | 1368 #ifdef FEAT_GUI_W32 |
1369 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1370 * cancelled. */ | |
1371 case K_F4: | |
1372 if (mod_mask == MOD_MASK_ALT) | |
1373 { | |
1374 redrawcmd(); /* somehow the cmdline is cleared */ | |
1375 goto cmdline_not_changed; | |
1376 } | |
1377 break; | |
1378 #endif | |
1379 | |
7 | 1380 #ifdef FEAT_MOUSE |
1381 case K_MIDDLEDRAG: | |
1382 case K_MIDDLERELEASE: | |
1383 goto cmdline_not_changed; /* Ignore mouse */ | |
1384 | |
1385 case K_MIDDLEMOUSE: | |
1386 # ifdef FEAT_GUI | |
1387 /* When GUI is active, also paste when 'mouse' is empty */ | |
1388 if (!gui.in_use) | |
1389 # endif | |
1390 if (!mouse_has(MOUSE_COMMAND)) | |
1391 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1392 # ifdef FEAT_CLIPBOARD |
7 | 1393 if (clip_star.available) |
1015 | 1394 cmdline_paste('*', TRUE, TRUE); |
7 | 1395 else |
692 | 1396 # endif |
1015 | 1397 cmdline_paste(0, TRUE, TRUE); |
7 | 1398 redrawcmd(); |
1399 goto cmdline_changed; | |
1400 | |
692 | 1401 # ifdef FEAT_DND |
7 | 1402 case K_DROP: |
1015 | 1403 cmdline_paste('~', TRUE, FALSE); |
7 | 1404 redrawcmd(); |
1405 goto cmdline_changed; | |
692 | 1406 # endif |
7 | 1407 |
1408 case K_LEFTDRAG: | |
1409 case K_LEFTRELEASE: | |
1410 case K_RIGHTDRAG: | |
1411 case K_RIGHTRELEASE: | |
1412 /* Ignore drag and release events when the button-down wasn't | |
1413 * seen before. */ | |
1414 if (ignore_drag_release) | |
1415 goto cmdline_not_changed; | |
1416 /* FALLTHROUGH */ | |
1417 case K_LEFTMOUSE: | |
1418 case K_RIGHTMOUSE: | |
1419 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1420 ignore_drag_release = TRUE; | |
1421 else | |
1422 ignore_drag_release = FALSE; | |
1423 # ifdef FEAT_GUI | |
1424 /* When GUI is active, also move when 'mouse' is empty */ | |
1425 if (!gui.in_use) | |
1426 # endif | |
1427 if (!mouse_has(MOUSE_COMMAND)) | |
1428 goto cmdline_not_changed; /* Ignore mouse */ | |
1429 # ifdef FEAT_CLIPBOARD | |
1430 if (mouse_row < cmdline_row && clip_star.available) | |
1431 { | |
1432 int button, is_click, is_drag; | |
1433 | |
1434 /* | |
1435 * Handle modeless selection. | |
1436 */ | |
1437 button = get_mouse_button(KEY2TERMCAP1(c), | |
1438 &is_click, &is_drag); | |
1439 if (mouse_model_popup() && button == MOUSE_LEFT | |
1440 && (mod_mask & MOD_MASK_SHIFT)) | |
1441 { | |
1442 /* Translate shift-left to right button. */ | |
1443 button = MOUSE_RIGHT; | |
1444 mod_mask &= ~MOD_MASK_SHIFT; | |
1445 } | |
1446 clip_modeless(button, is_click, is_drag); | |
1447 goto cmdline_not_changed; | |
1448 } | |
1449 # endif | |
1450 | |
1451 set_cmdspos(); | |
1452 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1453 ++ccline.cmdpos) | |
1454 { | |
1455 i = cmdline_charsize(ccline.cmdpos); | |
1456 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1457 && mouse_col < ccline.cmdspos % Columns + i) | |
1458 break; | |
692 | 1459 # ifdef FEAT_MBYTE |
7 | 1460 if (has_mbyte) |
1461 { | |
1462 /* Count ">" for double-wide char that doesn't fit. */ | |
1463 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1464 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1465 + ccline.cmdpos) - 1; |
1466 } | |
692 | 1467 # endif |
7 | 1468 ccline.cmdspos += i; |
1469 } | |
1470 goto cmdline_not_changed; | |
1471 | |
1472 /* Mouse scroll wheel: ignored here */ | |
1473 case K_MOUSEDOWN: | |
1474 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1475 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1476 case K_MOUSERIGHT: |
7 | 1477 /* Alternate buttons ignored here */ |
1478 case K_X1MOUSE: | |
1479 case K_X1DRAG: | |
1480 case K_X1RELEASE: | |
1481 case K_X2MOUSE: | |
1482 case K_X2DRAG: | |
1483 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1484 case K_MOUSEMOVE: |
7 | 1485 goto cmdline_not_changed; |
1486 | |
1487 #endif /* FEAT_MOUSE */ | |
1488 | |
1489 #ifdef FEAT_GUI | |
1490 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1491 case K_LEFTRELEASE_NM: | |
1492 goto cmdline_not_changed; | |
1493 | |
1494 case K_VER_SCROLLBAR: | |
540 | 1495 if (msg_scrolled == 0) |
7 | 1496 { |
1497 gui_do_scroll(); | |
1498 redrawcmd(); | |
1499 } | |
1500 goto cmdline_not_changed; | |
1501 | |
1502 case K_HOR_SCROLLBAR: | |
540 | 1503 if (msg_scrolled == 0) |
7 | 1504 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1505 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1506 redrawcmd(); |
1507 } | |
1508 goto cmdline_not_changed; | |
1509 #endif | |
692 | 1510 #ifdef FEAT_GUI_TABLINE |
1511 case K_TABLINE: | |
1512 case K_TABMENU: | |
1513 /* Don't want to change any tabs here. Make sure the same tab | |
1514 * is still selected. */ | |
1515 if (gui_use_tabline()) | |
1516 gui_mch_set_curtab(tabpage_index(curtab)); | |
1517 goto cmdline_not_changed; | |
1518 #endif | |
1519 | |
7 | 1520 case K_SELECT: /* end of Select mode mapping - ignore */ |
1521 goto cmdline_not_changed; | |
1522 | |
1523 case Ctrl_B: /* begin of command line */ | |
1524 case K_HOME: | |
1525 case K_KHOME: | |
1526 case K_S_HOME: | |
1527 case K_C_HOME: | |
1528 ccline.cmdpos = 0; | |
1529 set_cmdspos(); | |
1530 goto cmdline_not_changed; | |
1531 | |
1532 case Ctrl_E: /* end of command line */ | |
1533 case K_END: | |
1534 case K_KEND: | |
1535 case K_S_END: | |
1536 case K_C_END: | |
1537 ccline.cmdpos = ccline.cmdlen; | |
1538 set_cmdspos_cursor(); | |
1539 goto cmdline_not_changed; | |
1540 | |
1541 case Ctrl_A: /* all matches */ | |
3961 | 1542 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1543 break; |
1544 goto cmdline_changed; | |
1545 | |
772 | 1546 case Ctrl_L: |
1547 #ifdef FEAT_SEARCH_EXTRA | |
1548 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?')) | |
1549 { | |
1550 /* Add a character from under the cursor for 'incsearch' */ | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1551 if (did_incsearch) |
772 | 1552 { |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1553 curwin->w_cursor = match_end; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
1554 if (!EQUAL_POS(curwin->w_cursor, search_start)) |
1039 | 1555 { |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1556 c = gchar_cursor(); |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1557 /* If 'ignorecase' and 'smartcase' are set and the |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1558 * command line has no uppercase characters, convert |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1559 * the character to lowercase */ |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1560 if (p_ic && p_scs |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1561 && !pat_has_uppercase(ccline.cmdbuff)) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1562 c = MB_TOLOWER(c); |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1563 if (c != NUL) |
1039 | 1564 { |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1565 if (c == firstc || vim_strchr((char_u *)( |
11613
7428a08c2f68
patch 8.0.0689: ~ character not escaped when extending search pattern
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
1566 p_magic ? "\\~^$.*[" : "\\^$"), c) |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1567 != NULL) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1568 { |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1569 /* put a backslash before special |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1570 * characters */ |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1571 stuffcharReadbuff(c); |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1572 c = '\\'; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1573 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1574 break; |
1039 | 1575 } |
1576 } | |
772 | 1577 } |
1578 goto cmdline_not_changed; | |
1579 } | |
1580 #endif | |
1581 | |
1582 /* completion: longest common part */ | |
3961 | 1583 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 1584 break; |
1585 goto cmdline_changed; | |
1586 | |
1587 case Ctrl_N: /* next match */ | |
1588 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
1589 if (xpc.xp_numfiles > 0) |
7 | 1590 { |
3961 | 1591 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
1592 0, firstc != '@') == FAIL) | |
7 | 1593 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1594 goto cmdline_not_changed; |
7 | 1595 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
1596 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1597 /* FALLTHROUGH */ |
7 | 1598 case K_UP: |
1599 case K_DOWN: | |
1600 case K_S_UP: | |
1601 case K_S_DOWN: | |
1602 case K_PAGEUP: | |
1603 case K_KPAGEUP: | |
1604 case K_PAGEDOWN: | |
1605 case K_KPAGEDOWN: | |
1606 if (hislen == 0 || firstc == NUL) /* no history */ | |
1607 goto cmdline_not_changed; | |
1608 | |
1609 i = hiscnt; | |
1610 | |
1611 /* save current command string so it can be restored later */ | |
1612 if (lookfor == NULL) | |
1613 { | |
1614 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
1615 goto cmdline_not_changed; | |
1616 lookfor[ccline.cmdpos] = NUL; | |
1617 } | |
1618 | |
1619 j = (int)STRLEN(lookfor); | |
1620 for (;;) | |
1621 { | |
1622 /* one step backwards */ | |
230 | 1623 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 1624 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 1625 { |
1626 if (hiscnt == hislen) /* first time */ | |
1627 hiscnt = hisidx[histype]; | |
1628 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
1629 hiscnt = hislen - 1; | |
1630 else if (hiscnt != hisidx[histype] + 1) | |
1631 --hiscnt; | |
1632 else /* at top of list */ | |
1633 { | |
1634 hiscnt = i; | |
1635 break; | |
1636 } | |
1637 } | |
1638 else /* one step forwards */ | |
1639 { | |
1640 /* on last entry, clear the line */ | |
1641 if (hiscnt == hisidx[histype]) | |
1642 { | |
1643 hiscnt = hislen; | |
1644 break; | |
1645 } | |
1646 | |
1647 /* not on a history line, nothing to do */ | |
1648 if (hiscnt == hislen) | |
1649 break; | |
1650 if (hiscnt == hislen - 1) /* wrap around */ | |
1651 hiscnt = 0; | |
1652 else | |
1653 ++hiscnt; | |
1654 } | |
1655 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
1656 { | |
1657 hiscnt = i; | |
1658 break; | |
1659 } | |
230 | 1660 if ((c != K_UP && c != K_DOWN) |
180 | 1661 || hiscnt == i |
7 | 1662 || STRNCMP(history[histype][hiscnt].hisstr, |
1663 lookfor, (size_t)j) == 0) | |
1664 break; | |
1665 } | |
1666 | |
1667 if (hiscnt != i) /* jumped to other entry */ | |
1668 { | |
1669 char_u *p; | |
1670 int len; | |
1671 int old_firstc; | |
1672 | |
1673 vim_free(ccline.cmdbuff); | |
1718 | 1674 xpc.xp_context = EXPAND_NOTHING; |
7 | 1675 if (hiscnt == hislen) |
1676 p = lookfor; /* back to the old one */ | |
1677 else | |
1678 p = history[histype][hiscnt].hisstr; | |
1679 | |
1680 if (histype == HIST_SEARCH | |
1681 && p != lookfor | |
1682 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
1683 { | |
1684 /* Correct for the separator character used when | |
1685 * adding the history entry vs the one used now. | |
1686 * First loop: count length. | |
1687 * Second loop: copy the characters. */ | |
1688 for (i = 0; i <= 1; ++i) | |
1689 { | |
1690 len = 0; | |
1691 for (j = 0; p[j] != NUL; ++j) | |
1692 { | |
1693 /* Replace old sep with new sep, unless it is | |
1694 * escaped. */ | |
1695 if (p[j] == old_firstc | |
1696 && (j == 0 || p[j - 1] != '\\')) | |
1697 { | |
1698 if (i > 0) | |
1699 ccline.cmdbuff[len] = firstc; | |
1700 } | |
1701 else | |
1702 { | |
1703 /* Escape new sep, unless it is already | |
1704 * escaped. */ | |
1705 if (p[j] == firstc | |
1706 && (j == 0 || p[j - 1] != '\\')) | |
1707 { | |
1708 if (i > 0) | |
1709 ccline.cmdbuff[len] = '\\'; | |
1710 ++len; | |
1711 } | |
1712 if (i > 0) | |
1713 ccline.cmdbuff[len] = p[j]; | |
1714 } | |
1715 ++len; | |
1716 } | |
1717 if (i == 0) | |
1718 { | |
1719 alloc_cmdbuff(len); | |
1720 if (ccline.cmdbuff == NULL) | |
1721 goto returncmd; | |
1722 } | |
1723 } | |
1724 ccline.cmdbuff[len] = NUL; | |
1725 } | |
1726 else | |
1727 { | |
1728 alloc_cmdbuff((int)STRLEN(p)); | |
1729 if (ccline.cmdbuff == NULL) | |
1730 goto returncmd; | |
1731 STRCPY(ccline.cmdbuff, p); | |
1732 } | |
1733 | |
1734 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
1735 redrawcmd(); | |
1736 goto cmdline_changed; | |
1737 } | |
1738 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1739 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1740 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1741 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
1742 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1743 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1744 case Ctrl_T: /* previous match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1745 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?')) |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1746 { |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1747 pos_T t; |
12855
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1748 char_u *pat; |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1749 int search_flags = SEARCH_NOOF; |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1750 |
12744
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1751 if (ccline.cmdlen == 0) |
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1752 goto cmdline_not_changed; |
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1753 |
12855
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1754 if (firstc == ccline.cmdbuff[0]) |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1755 pat = last_search_pattern(); |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1756 else |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1757 pat = ccline.cmdbuff; |
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1758 |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1759 save_last_search_pattern(); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1760 cursor_off(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1761 out_flush(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1762 if (c == Ctrl_G) |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1763 { |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1764 t = match_end; |
12744
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1765 if (LT_POS(match_start, match_end)) |
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1766 /* start searching at the end of the match |
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1767 * not at the beginning of the next column */ |
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1768 (void)decl(&t); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1769 search_flags += SEARCH_COL; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1770 } |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1771 else |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1772 t = match_start; |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1773 if (!p_hls) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1774 search_flags += SEARCH_KEEP; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1775 ++emsg_off; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1776 i = searchit(curwin, curbuf, &t, |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1777 c == Ctrl_G ? FORWARD : BACKWARD, |
12855
3c09e451af3a
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Christian Brabandt <cb@256bit.org>
parents:
12744
diff
changeset
|
1778 pat, count, search_flags, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
1779 RE_SEARCH, 0, NULL, NULL); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1780 --emsg_off; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1781 if (i) |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1782 { |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1783 search_start = match_start; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1784 match_end = t; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1785 match_start = t; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1786 if (c == Ctrl_T && firstc == '/') |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1787 { |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1788 /* move just before the current match, so that |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1789 * when nv_search finishes the cursor will be |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1790 * put back on the match */ |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1791 search_start = t; |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1792 (void)decl(&search_start); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1793 } |
11619
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1794 else if (c == Ctrl_G && firstc == '?') |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1795 { |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1796 /* move just after the current match, so that |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1797 * when nv_search finishes the cursor will be |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1798 * put back on the match */ |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1799 search_start = t; |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1800 (void)incl(&search_start); |
80af4916eadc
patch 8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction
Christian Brabandt <cb@256bit.org>
parents:
11613
diff
changeset
|
1801 } |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
1802 if (LT_POS(t, search_start) && c == Ctrl_G) |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1803 { |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1804 /* wrap around */ |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1805 search_start = t; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1806 if (firstc == '?') |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1807 (void)incl(&search_start); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1808 else |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1809 (void)decl(&search_start); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1810 } |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1811 |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1812 set_search_match(&match_end); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1813 curwin->w_cursor = match_start; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1814 changed_cline_bef_curs(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1815 update_topline(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1816 validate_cursor(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1817 highlight_match = TRUE; |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
1818 save_viewstate(&old_viewstate); |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1819 update_screen(NOT_VALID); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1820 redrawcmdline(); |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1821 } |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1822 else |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1823 vim_beep(BO_ERROR); |
13041
5f3aff09d8f8
patch 8.0.1396: memory leak when CTRL-G in search command line fails
Christian Brabandt <cb@256bit.org>
parents:
13035
diff
changeset
|
1824 restore_last_search_pattern(); |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
1825 goto cmdline_not_changed; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1826 } |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
1827 break; |
7 | 1828 #endif |
1829 | |
1830 case Ctrl_V: | |
1831 case Ctrl_Q: | |
1832 #ifdef FEAT_MOUSE | |
1833 ignore_drag_release = TRUE; | |
1834 #endif | |
1835 putcmdline('^', TRUE); | |
1836 c = get_literal(); /* get next (two) character(s) */ | |
1837 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
|
1838 extra_char = NUL; |
7 | 1839 #ifdef FEAT_MBYTE |
1840 /* may need to remove ^ when composing char was typed */ | |
1841 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
1842 { | |
1843 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
1844 msg_putchar(' '); | |
1845 cursorcmd(); | |
1846 } | |
1847 #endif | |
1848 break; | |
1849 | |
1850 #ifdef FEAT_DIGRAPHS | |
1851 case Ctrl_K: | |
1852 #ifdef FEAT_MOUSE | |
1853 ignore_drag_release = TRUE; | |
1854 #endif | |
1855 putcmdline('?', TRUE); | |
1856 #ifdef USE_ON_FLY_SCROLL | |
1857 dont_scroll = TRUE; /* disallow scrolling here */ | |
1858 #endif | |
1859 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
|
1860 extra_char = NUL; |
7 | 1861 if (c != NUL) |
1862 break; | |
1863 | |
1864 redrawcmd(); | |
1865 goto cmdline_not_changed; | |
1866 #endif /* FEAT_DIGRAPHS */ | |
1867 | |
1868 #ifdef FEAT_RIGHTLEFT | |
1869 case Ctrl__: /* CTRL-_: switch language mode */ | |
1870 if (!p_ari) | |
1871 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
1872 # ifdef FEAT_FKMAP |
7 | 1873 if (p_altkeymap) |
1874 { | |
1875 cmd_fkmap = !cmd_fkmap; | |
1876 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
1877 ccline.overstrike = FALSE; | |
1878 } | |
1879 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
1880 # endif |
7 | 1881 cmd_hkmap = !cmd_hkmap; |
1882 goto cmdline_not_changed; | |
1883 #endif | |
1884 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
1885 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
|
1886 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
|
1887 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
|
1888 |
7 | 1889 default: |
1890 #ifdef UNIX | |
1891 if (c == intr_char) | |
1892 { | |
1893 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1894 putting it in history */ | |
1895 goto returncmd; /* back to Normal mode */ | |
1896 } | |
1897 #endif | |
1898 /* | |
1899 * Normal character with no special meaning. Just set mod_mask | |
1900 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
1901 * the string <S-Space>. This should only happen after ^V. | |
1902 */ | |
1903 if (!IS_SPECIAL(c)) | |
1904 mod_mask = 0x0; | |
1905 break; | |
1906 } | |
1907 /* | |
1908 * End of switch on command line character. | |
1909 * We come here if we have a normal character. | |
1910 */ | |
1911 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
1912 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 1913 #ifdef FEAT_MBYTE |
1914 /* Add ABBR_OFF for characters above 0x100, this is | |
1915 * what check_abbr() expects. */ | |
1916 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
1917 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
1918 c) || c == Ctrl_RSB)) |
7 | 1919 goto cmdline_changed; |
1920 | |
1921 /* | |
1922 * put the character in the command line | |
1923 */ | |
1924 if (IS_SPECIAL(c) || mod_mask != 0) | |
1925 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
1926 else | |
1927 { | |
1928 #ifdef FEAT_MBYTE | |
1929 if (has_mbyte) | |
1930 { | |
1931 j = (*mb_char2bytes)(c, IObuff); | |
1932 IObuff[j] = NUL; /* exclude composing chars */ | |
1933 put_on_cmdline(IObuff, j, TRUE); | |
1934 } | |
1935 else | |
1936 #endif | |
1937 { | |
1938 IObuff[0] = c; | |
1939 put_on_cmdline(IObuff, 1, TRUE); | |
1940 } | |
1941 } | |
1942 goto cmdline_changed; | |
1943 | |
1944 /* | |
1945 * This part implements incremental searches for "/" and "?" | |
1946 * Jump to cmdline_not_changed when a character has been read but the command | |
1947 * line did not change. Then we only search and redraw if something changed in | |
1948 * the past. | |
1949 * Jump to cmdline_changed when the command line did change. | |
1950 * (Sorry for the goto's, I know it is ugly). | |
1951 */ | |
1952 cmdline_not_changed: | |
1953 #ifdef FEAT_SEARCH_EXTRA | |
1954 if (!incsearch_postponed) | |
1955 continue; | |
1956 #endif | |
1957 | |
1958 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
|
1959 /* 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
|
1960 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
|
1961 |
7 | 1962 #ifdef FEAT_SEARCH_EXTRA |
1963 /* | |
1964 * 'incsearch' highlighting. | |
1965 */ | |
1966 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?')) | |
1967 { | |
772 | 1968 pos_T end_pos; |
1521 | 1969 #ifdef FEAT_RELTIME |
1970 proftime_T tm; | |
1971 #endif | |
772 | 1972 |
7 | 1973 /* if there is a character waiting, search and redraw later */ |
1974 if (char_avail()) | |
1975 { | |
1976 incsearch_postponed = TRUE; | |
1977 continue; | |
1978 } | |
1979 incsearch_postponed = FALSE; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1980 curwin->w_cursor = search_start; /* start at old position */ |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1981 save_last_search_pattern(); |
7 | 1982 |
1983 /* If there is no command line, don't do anything */ | |
1984 if (ccline.cmdlen == 0) | |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1985 { |
7 | 1986 i = 0; |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13790
diff
changeset
|
1987 set_no_hlsearch(TRUE); /* turn off previous highlight */ |
12744
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
1988 redraw_all_later(SOME_VALID); |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1989 } |
7 | 1990 else |
1991 { | |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1992 int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; |
7 | 1993 cursor_off(); /* so the user knows we're busy */ |
1994 out_flush(); | |
1995 ++emsg_off; /* So it doesn't beep if bad expr */ | |
1521 | 1996 #ifdef FEAT_RELTIME |
1997 /* Set the time limit to half a second. */ | |
1998 profile_setlimit(500L, &tm); | |
1999 #endif | |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2000 if (!p_hls) |
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2001 search_flags += SEARCH_KEEP; |
7 | 2002 i = do_search(NULL, firstc, ccline.cmdbuff, count, |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2003 search_flags, |
1521 | 2004 #ifdef FEAT_RELTIME |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
2005 &tm, NULL |
1521 | 2006 #else |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
2007 NULL, NULL |
1521 | 2008 #endif |
2009 ); | |
7 | 2010 --emsg_off; |
2011 /* if interrupted while searching, behave like it failed */ | |
2012 if (got_int) | |
2013 { | |
2014 (void)vpeekc(); /* remove <C-C> from input stream */ | |
2015 got_int = FALSE; /* don't abandon the command line */ | |
2016 i = 0; | |
2017 } | |
2018 else if (char_avail()) | |
2019 /* cancelled searching because a char was typed */ | |
2020 incsearch_postponed = TRUE; | |
2021 } | |
772 | 2022 if (i != 0) |
7 | 2023 highlight_match = TRUE; /* highlight position */ |
2024 else | |
2025 highlight_match = FALSE; /* remove highlight */ | |
2026 | |
2027 /* first restore the old curwin values, so the screen is | |
2028 * positioned in the same way as the actual search command */ | |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
2029 restore_viewstate(&old_viewstate); |
7 | 2030 changed_cline_bef_curs(); |
2031 update_topline(); | |
2032 | |
2033 if (i != 0) | |
2034 { | |
481 | 2035 pos_T save_pos = curwin->w_cursor; |
2036 | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2037 match_start = curwin->w_cursor; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2038 set_search_match(&curwin->w_cursor); |
7 | 2039 validate_cursor(); |
772 | 2040 end_pos = curwin->w_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2041 match_end = end_pos; |
481 | 2042 curwin->w_cursor = save_pos; |
7 | 2043 } |
798 | 2044 else |
2045 end_pos = curwin->w_cursor; /* shutup gcc 4 */ | |
772 | 2046 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
2047 /* Disable 'hlsearch' highlighting if the pattern matches |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
2048 * everything. Avoids a flash when typing "foo\|". */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
2049 if (empty_pattern(ccline.cmdbuff)) |
13792
0e9b2971d7c3
patch 8.0.1768: SET_NO_HLSEARCH() used in a wrong way
Christian Brabandt <cb@256bit.org>
parents:
13790
diff
changeset
|
2050 set_no_hlsearch(TRUE); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
2051 |
7 | 2052 validate_cursor(); |
979 | 2053 /* May redraw the status line to show the cursor position. */ |
2054 if (p_ru && curwin->w_status_height > 0) | |
2055 curwin->w_redr_status = TRUE; | |
7 | 2056 |
195 | 2057 save_cmdline(&save_ccline); |
743 | 2058 update_screen(SOME_VALID); |
195 | 2059 restore_cmdline(&save_ccline); |
12720
37c384802df4
patch 8.0.1238: incremental search only shows one match
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2060 restore_last_search_pattern(); |
195 | 2061 |
772 | 2062 /* Leave it at the end to make CTRL-R CTRL-W work. */ |
2063 if (i != 0) | |
2064 curwin->w_cursor = end_pos; | |
2065 | |
7 | 2066 msg_starthere(); |
2067 redrawcmdline(); | |
2068 did_incsearch = TRUE; | |
2069 } | |
2070 #else /* FEAT_SEARCH_EXTRA */ | |
2071 ; | |
2072 #endif | |
2073 | |
2074 #ifdef FEAT_RIGHTLEFT | |
2075 if (cmdmsg_rl | |
2076 # ifdef FEAT_ARABIC | |
534 | 2077 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2078 # endif |
2079 ) | |
2080 /* Always redraw the whole command line to fix shaping and | |
3374 | 2081 * right-left typing. Not efficient, but it works. |
2082 * Do it only when there are no characters left to read | |
2083 * to avoid useless intermediate redraws. */ | |
2084 if (vpeekc() == NUL) | |
2085 redrawcmd(); | |
7 | 2086 #endif |
2087 } | |
2088 | |
2089 returncmd: | |
2090 | |
2091 #ifdef FEAT_RIGHTLEFT | |
2092 cmdmsg_rl = FALSE; | |
2093 #endif | |
2094 | |
2095 #ifdef FEAT_FKMAP | |
2096 cmd_fkmap = 0; | |
2097 #endif | |
2098 | |
2099 ExpandCleanup(&xpc); | |
1718 | 2100 ccline.xpc = NULL; |
7 | 2101 |
2102 #ifdef FEAT_SEARCH_EXTRA | |
2103 if (did_incsearch) | |
2104 { | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2105 if (gotesc) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2106 curwin->w_cursor = save_cursor; |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2107 else |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2108 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
2109 if (!EQUAL_POS(save_cursor, search_start)) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2110 { |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2111 /* put the '" mark at the original position */ |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2112 curwin->w_cursor = save_cursor; |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2113 setpcmark(); |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2114 } |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2115 curwin->w_cursor = search_start; |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
2116 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
2117 restore_viewstate(&old_viewstate); |
7 | 2118 highlight_match = FALSE; |
2119 validate_cursor(); /* needed for TAB */ | |
12744
0c704288ced4
patch 8.0.1250: 'hlsearch' highlighting not removed after incsearch
Christian Brabandt <cb@256bit.org>
parents:
12720
diff
changeset
|
2120 redraw_all_later(SOME_VALID); |
7 | 2121 } |
2122 #endif | |
2123 | |
2124 if (ccline.cmdbuff != NULL) | |
2125 { | |
2126 /* | |
2127 * Put line in history buffer (":" and "=" only when it was typed). | |
2128 */ | |
2129 #ifdef FEAT_CMDHIST | |
2130 if (ccline.cmdlen && firstc != NUL | |
2131 && (some_key_typed || histype == HIST_SEARCH)) | |
2132 { | |
2133 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2134 histype == HIST_SEARCH ? firstc : NUL); | |
2135 if (firstc == ':') | |
2136 { | |
2137 vim_free(new_last_cmdline); | |
2138 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2139 } | |
2140 } | |
2141 #endif | |
2142 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2143 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
|
2144 abandon_cmdline(); |
7 | 2145 } |
2146 | |
2147 /* | |
2148 * If the screen was shifted up, redraw the whole screen (later). | |
2149 * If the line is too long, clear it, so ruler and shown command do | |
2150 * not get printed in the middle of it. | |
2151 */ | |
2152 msg_check(); | |
2153 msg_scroll = save_msg_scroll; | |
2154 redir_off = FALSE; | |
2155 | |
2156 /* When the command line was typed, no need for a wait-return prompt. */ | |
2157 if (some_key_typed) | |
2158 need_wait_return = FALSE; | |
2159 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2160 /* 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
|
2161 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
|
2162 |
7 | 2163 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2164 #ifdef HAVE_INPUT_METHOD |
7 | 2165 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2166 im_save_status(b_im_ptr); | |
2167 im_set_active(FALSE); | |
2168 #endif | |
2169 #ifdef FEAT_MOUSE | |
2170 setmouse(); | |
2171 #endif | |
2172 #ifdef CURSOR_SHAPE | |
2173 ui_cursor_shape(); /* may show different cursor shape */ | |
2174 #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
|
2175 sb_text_end_cmdline(); |
7 | 2176 |
95 | 2177 { |
2178 char_u *p = ccline.cmdbuff; | |
2179 | |
2180 /* Make ccline empty, getcmdline() may try to use it. */ | |
2181 ccline.cmdbuff = NULL; | |
2182 return p; | |
2183 } | |
7 | 2184 } |
2185 | |
2186 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2187 /* | |
2188 * Get a command line with a prompt. | |
2189 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2190 * f_input() when evaluating an expression from CTRL-R =). | |
2191 * Returns the command line in allocated memory, or NULL. | |
2192 */ | |
2193 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2194 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2195 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2196 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2197 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2198 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2199 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2200 { |
2201 char_u *s; | |
2202 struct cmdline_info save_ccline; | |
2203 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
|
2204 int msg_silent_save = msg_silent; |
7 | 2205 |
95 | 2206 save_cmdline(&save_ccline); |
7 | 2207 ccline.cmdprompt = prompt; |
2208 ccline.cmdattr = attr; | |
531 | 2209 # ifdef FEAT_EVAL |
2210 ccline.xp_context = xp_context; | |
2211 ccline.xp_arg = xp_arg; | |
2212 ccline.input_fn = (firstc == '@'); | |
2213 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2214 msg_silent = 0; |
7 | 2215 s = getcmdline(firstc, 1L, 0); |
95 | 2216 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2217 msg_silent = msg_silent_save; |
3020 | 2218 /* Restore msg_col, the prompt from input() may have changed it. |
2219 * But only if called recursively and the commandline is therefore being | |
2220 * restored to an old one; if not, the input() prompt stays on the screen, | |
2221 * so we need its modified msg_col left intact. */ | |
2222 if (ccline.cmdbuff != NULL) | |
2223 msg_col = msg_col_save; | |
7 | 2224 |
2225 return s; | |
2226 } | |
2227 #endif | |
2228 | |
632 | 2229 /* |
634 | 2230 * Return TRUE when the text must not be changed and we can't switch to |
2231 * another window or buffer. Used when editing the command line, evaluating | |
2232 * 'balloonexpr', etc. | |
632 | 2233 */ |
2234 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2235 text_locked(void) |
632 | 2236 { |
2237 #ifdef FEAT_CMDWIN | |
2238 if (cmdwin_type != 0) | |
2239 return TRUE; | |
2240 #endif | |
634 | 2241 return textlock != 0; |
632 | 2242 } |
2243 | |
2244 /* | |
2245 * Give an error message for a command that isn't allowed while the cmdline | |
2246 * window is open or editing the cmdline in another way. | |
2247 */ | |
2248 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2249 text_locked_msg(void) |
632 | 2250 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2251 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2252 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2253 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2254 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2255 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2256 { |
632 | 2257 #ifdef FEAT_CMDWIN |
2258 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2259 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2260 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2261 return e_secure; |
632 | 2262 } |
2263 | |
819 | 2264 /* |
1834 | 2265 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2266 * and give an error message. | |
819 | 2267 */ |
2268 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2269 curbuf_locked(void) |
819 | 2270 { |
2271 if (curbuf_lock > 0) | |
2272 { | |
2273 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2274 return TRUE; | |
2275 } | |
1834 | 2276 return allbuf_locked(); |
2277 } | |
2278 | |
2279 /* | |
2280 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2281 * message. | |
2282 */ | |
2283 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2284 allbuf_locked(void) |
1834 | 2285 { |
2286 if (allbuf_lock > 0) | |
2287 { | |
2288 EMSG(_("E811: Not allowed to change buffer information now")); | |
2289 return TRUE; | |
2290 } | |
819 | 2291 return FALSE; |
2292 } | |
2293 | |
7 | 2294 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2295 cmdline_charsize(int idx) |
7 | 2296 { |
2297 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2298 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2299 return 1; | |
2300 #endif | |
2301 return ptr2cells(ccline.cmdbuff + idx); | |
2302 } | |
2303 | |
2304 /* | |
2305 * Compute the offset of the cursor on the command line for the prompt and | |
2306 * indent. | |
2307 */ | |
2308 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2309 set_cmdspos(void) |
7 | 2310 { |
531 | 2311 if (ccline.cmdfirstc != NUL) |
7 | 2312 ccline.cmdspos = 1 + ccline.cmdindent; |
2313 else | |
2314 ccline.cmdspos = 0 + ccline.cmdindent; | |
2315 } | |
2316 | |
2317 /* | |
2318 * Compute the screen position for the cursor on the command line. | |
2319 */ | |
2320 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2321 set_cmdspos_cursor(void) |
7 | 2322 { |
2323 int i, m, c; | |
2324 | |
2325 set_cmdspos(); | |
2326 if (KeyTyped) | |
534 | 2327 { |
7 | 2328 m = Columns * Rows; |
534 | 2329 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2330 m = MAXCOL; | |
2331 } | |
7 | 2332 else |
2333 m = MAXCOL; | |
2334 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2335 { | |
2336 c = cmdline_charsize(i); | |
2337 #ifdef FEAT_MBYTE | |
2338 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2339 if (has_mbyte) | |
2340 correct_cmdspos(i, c); | |
2341 #endif | |
1612 | 2342 /* If the cmdline doesn't fit, show cursor on last visible char. |
2343 * Don't move the cursor itself, so we can still append. */ | |
7 | 2344 if ((ccline.cmdspos += c) >= m) |
2345 { | |
2346 ccline.cmdspos -= c; | |
2347 break; | |
2348 } | |
2349 #ifdef FEAT_MBYTE | |
2350 if (has_mbyte) | |
474 | 2351 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2352 #endif |
2353 } | |
2354 } | |
2355 | |
2356 #ifdef FEAT_MBYTE | |
2357 /* | |
2358 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2359 * character that doesn't fit, so that a ">" must be displayed. | |
2360 */ | |
2361 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2362 correct_cmdspos(int idx, int cells) |
7 | 2363 { |
474 | 2364 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2365 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2366 && ccline.cmdspos % Columns + cells > Columns) | |
2367 ccline.cmdspos++; | |
2368 } | |
2369 #endif | |
2370 | |
2371 /* | |
2372 * Get an Ex command line for the ":" command. | |
2373 */ | |
2374 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2375 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2376 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2377 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2378 int indent) /* indent for inside conditionals */ |
7 | 2379 { |
2380 /* When executing a register, remove ':' that's in front of each line. */ | |
2381 if (exec_from_reg && vpeekc() == ':') | |
2382 (void)vgetc(); | |
2383 return getcmdline(c, 1L, indent); | |
2384 } | |
2385 | |
2386 /* | |
2387 * Get an Ex command line for Ex mode. | |
2388 * In Ex mode we only use the OS supplied line editing features and no | |
2389 * mappings or abbreviations. | |
168 | 2390 * Returns a string in allocated memory or NULL. |
7 | 2391 */ |
2392 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2393 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2394 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2395 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2396 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2397 int indent) /* indent for inside conditionals */ |
7 | 2398 { |
168 | 2399 garray_T line_ga; |
2400 char_u *pend; | |
2401 int startcol = 0; | |
1329 | 2402 int c1 = 0; |
168 | 2403 int escaped = FALSE; /* CTRL-V typed */ |
2404 int vcol = 0; | |
2405 char_u *p; | |
1329 | 2406 int prev_char; |
5966 | 2407 int len; |
7 | 2408 |
2409 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2410 * confuses the system function that computes tabstops. */ | |
2411 cursor_on(); | |
2412 | |
2413 /* always start in column 0; write a newline if necessary */ | |
2414 compute_cmdrow(); | |
168 | 2415 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2416 msg_putchar('\n'); |
168 | 2417 if (promptc == ':') |
7 | 2418 { |
164 | 2419 /* indent that is only displayed, not in the line itself */ |
168 | 2420 if (p_prompt) |
2421 msg_putchar(':'); | |
7 | 2422 while (indent-- > 0) |
2423 msg_putchar(' '); | |
2424 startcol = msg_col; | |
2425 } | |
2426 | |
2427 ga_init2(&line_ga, 1, 30); | |
2428 | |
164 | 2429 /* autoindent for :insert and :append is in the line itself */ |
168 | 2430 if (promptc <= 0) |
164 | 2431 { |
2432 vcol = indent; | |
2433 while (indent >= 8) | |
2434 { | |
2435 ga_append(&line_ga, TAB); | |
2436 msg_puts((char_u *)" "); | |
2437 indent -= 8; | |
2438 } | |
2439 while (indent-- > 0) | |
2440 { | |
2441 ga_append(&line_ga, ' '); | |
2442 msg_putchar(' '); | |
2443 } | |
2444 } | |
168 | 2445 ++no_mapping; |
2446 ++allow_keys; | |
164 | 2447 |
7 | 2448 /* |
2449 * Get the line, one character at a time. | |
2450 */ | |
2451 got_int = FALSE; | |
168 | 2452 while (!got_int) |
7 | 2453 { |
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
|
2454 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
|
2455 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
|
2456 |
7 | 2457 if (ga_grow(&line_ga, 40) == FAIL) |
2458 break; | |
2459 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2460 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2461 * 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
|
2462 */ |
1329 | 2463 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
|
2464 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2465 /* 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
|
2466 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
|
2467 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
|
2468 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2469 c1 = vgetc(); |
7 | 2470 |
2471 /* | |
168 | 2472 * Handle line editing. |
2473 * Previously this was left to the system, putting the terminal in | |
2474 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2475 */ |
168 | 2476 if (got_int) |
2477 { | |
2478 msg_putchar('\n'); | |
2479 break; | |
2480 } | |
2481 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2482 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
|
2483 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2484 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
|
2485 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
|
2486 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2487 |
168 | 2488 if (!escaped) |
7 | 2489 { |
168 | 2490 /* CR typed means "enter", which is NL */ |
2491 if (c1 == '\r') | |
2492 c1 = '\n'; | |
2493 | |
2494 if (c1 == BS || c1 == K_BS | |
2495 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2496 { |
168 | 2497 if (line_ga.ga_len > 0) |
2498 { | |
5966 | 2499 #ifdef FEAT_MBYTE |
2500 if (has_mbyte) | |
2501 { | |
2502 p = (char_u *)line_ga.ga_data; | |
2503 p[line_ga.ga_len] = NUL; | |
2504 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2505 line_ga.ga_len -= len; | |
2506 } | |
2507 else | |
2508 #endif | |
2509 --line_ga.ga_len; | |
168 | 2510 goto redraw; |
2511 } | |
2512 continue; | |
7 | 2513 } |
2514 | |
168 | 2515 if (c1 == Ctrl_U) |
7 | 2516 { |
168 | 2517 msg_col = startcol; |
2518 msg_clr_eos(); | |
2519 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
|
2520 goto redraw; |
168 | 2521 } |
2522 | |
2523 if (c1 == Ctrl_T) | |
2524 { | |
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
|
2525 sw = get_sw_value(curbuf); |
168 | 2526 p = (char_u *)line_ga.ga_data; |
2527 p[line_ga.ga_len] = NUL; | |
5995 | 2528 indent = get_indent_str(p, 8, FALSE); |
3740 | 2529 indent += sw - indent % sw; |
168 | 2530 add_indent: |
5995 | 2531 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2532 { |
7009 | 2533 (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
|
2534 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
|
2535 s = skipwhite(p); |
168 | 2536 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2537 *s = ' '; | |
2538 ++line_ga.ga_len; | |
7 | 2539 } |
168 | 2540 redraw: |
2541 /* redraw the line */ | |
2542 msg_col = startcol; | |
2543 vcol = 0; | |
5966 | 2544 p = (char_u *)line_ga.ga_data; |
2545 p[line_ga.ga_len] = NUL; | |
2546 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2547 { |
168 | 2548 if (*p == TAB) |
7 | 2549 { |
168 | 2550 do |
7 | 2551 { |
168 | 2552 msg_putchar(' '); |
2553 } while (++vcol % 8); | |
5966 | 2554 ++p; |
7 | 2555 } |
168 | 2556 else |
164 | 2557 { |
5966 | 2558 len = MB_PTR2LEN(p); |
2559 msg_outtrans_len(p, len); | |
2560 vcol += ptr2cells(p); | |
2561 p += len; | |
7 | 2562 } |
2563 } | |
168 | 2564 msg_clr_eos(); |
1329 | 2565 windgoto(msg_row, msg_col); |
168 | 2566 continue; |
2567 } | |
2568 | |
2569 if (c1 == Ctrl_D) | |
2570 { | |
2571 /* Delete one shiftwidth. */ | |
2572 p = (char_u *)line_ga.ga_data; | |
2573 if (prev_char == '0' || prev_char == '^') | |
7 | 2574 { |
168 | 2575 if (prev_char == '^') |
2576 ex_keep_indent = TRUE; | |
2577 indent = 0; | |
2578 p[--line_ga.ga_len] = NUL; | |
7 | 2579 } |
2580 else | |
2581 { | |
168 | 2582 p[line_ga.ga_len] = NUL; |
5995 | 2583 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
|
2584 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
|
2585 { |
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
|
2586 --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
|
2587 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
|
2588 } |
168 | 2589 } |
5995 | 2590 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2591 { |
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
|
2592 s = skipwhite(p); |
168 | 2593 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2594 --line_ga.ga_len; | |
7 | 2595 } |
168 | 2596 goto add_indent; |
2597 } | |
2598 | |
2599 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2600 { | |
2601 escaped = TRUE; | |
2602 continue; | |
7 | 2603 } |
168 | 2604 |
2605 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2606 if (IS_SPECIAL(c1)) | |
2607 continue; | |
7 | 2608 } |
168 | 2609 |
2610 if (IS_SPECIAL(c1)) | |
2611 c1 = '?'; | |
5966 | 2612 #ifdef FEAT_MBYTE |
2613 if (has_mbyte) | |
2614 len = (*mb_char2bytes)(c1, | |
2615 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2616 else | |
2617 #endif | |
2618 { | |
2619 len = 1; | |
2620 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2621 } | |
168 | 2622 if (c1 == '\n') |
2623 msg_putchar('\n'); | |
2624 else if (c1 == TAB) | |
2625 { | |
2626 /* Don't use chartabsize(), 'ts' can be different */ | |
2627 do | |
2628 { | |
2629 msg_putchar(' '); | |
2630 } while (++vcol % 8); | |
2631 } | |
7 | 2632 else |
2633 { | |
168 | 2634 msg_outtrans_len( |
5966 | 2635 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2636 vcol += char2cells(c1); |
7 | 2637 } |
5966 | 2638 line_ga.ga_len += len; |
168 | 2639 escaped = FALSE; |
2640 | |
2641 windgoto(msg_row, msg_col); | |
164 | 2642 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2643 |
2590 | 2644 /* We are done when a NL is entered, but not when it comes after an |
2645 * odd number of backslashes, that results in a NUL. */ | |
2646 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2647 { |
2590 | 2648 int bcount = 0; |
2649 | |
2650 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2651 ++bcount; | |
2652 | |
2653 if (bcount > 0) | |
2654 { | |
2655 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2656 * "\NL", etc. */ | |
2657 line_ga.ga_len -= (bcount + 1) / 2; | |
2658 pend -= (bcount + 1) / 2; | |
2659 pend[-1] = '\n'; | |
2660 } | |
2661 | |
2662 if ((bcount & 1) == 0) | |
2663 { | |
2664 --line_ga.ga_len; | |
2665 --pend; | |
2666 *pend = NUL; | |
2667 break; | |
2668 } | |
7 | 2669 } |
2670 } | |
2671 | |
168 | 2672 --no_mapping; |
2673 --allow_keys; | |
2674 | |
7 | 2675 /* make following messages go to the next line */ |
2676 msg_didout = FALSE; | |
2677 msg_col = 0; | |
2678 if (msg_row < Rows - 1) | |
2679 ++msg_row; | |
2680 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2681 | |
2682 if (got_int) | |
2683 ga_clear(&line_ga); | |
2684 | |
2685 return (char_u *)line_ga.ga_data; | |
2686 } | |
2687 | |
502 | 2688 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2689 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2690 /* |
2691 * Return TRUE if ccline.overstrike is on. | |
2692 */ | |
2693 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2694 cmdline_overstrike(void) |
7 | 2695 { |
2696 return ccline.overstrike; | |
2697 } | |
2698 | |
2699 /* | |
2700 * Return TRUE if the cursor is at the end of the cmdline. | |
2701 */ | |
2702 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2703 cmdline_at_end(void) |
7 | 2704 { |
2705 return (ccline.cmdpos >= ccline.cmdlen); | |
2706 } | |
2707 #endif | |
2708 | |
574 | 2709 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2710 /* |
2711 * Return the virtual column number at the current cursor position. | |
2712 * This is used by the IM code to obtain the start of the preedit string. | |
2713 */ | |
2714 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2715 cmdline_getvcol_cursor(void) |
7 | 2716 { |
2717 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2718 return MAXCOL; | |
2719 | |
2720 # ifdef FEAT_MBYTE | |
2721 if (has_mbyte) | |
2722 { | |
2723 colnr_T col; | |
2724 int i = 0; | |
2725 | |
2726 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2727 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2728 |
2729 return col; | |
2730 } | |
2731 else | |
2732 # endif | |
2733 return ccline.cmdpos; | |
2734 } | |
2735 #endif | |
2736 | |
2737 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2738 /* | |
2739 * If part of the command line is an IM preedit string, redraw it with | |
2740 * IM feedback attributes. The cursor position is restored after drawing. | |
2741 */ | |
2742 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2743 redrawcmd_preedit(void) |
7 | 2744 { |
2745 if ((State & CMDLINE) | |
2746 && xic != NULL | |
976 | 2747 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2748 && !p_imdisable |
2749 && im_is_preediting()) | |
2750 { | |
2751 int cmdpos = 0; | |
2752 int cmdspos; | |
2753 int old_row; | |
2754 int old_col; | |
2755 colnr_T col; | |
2756 | |
2757 old_row = msg_row; | |
2758 old_col = msg_col; | |
531 | 2759 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2760 |
2761 # ifdef FEAT_MBYTE | |
2762 if (has_mbyte) | |
2763 { | |
2764 for (col = 0; col < preedit_start_col | |
2765 && cmdpos < ccline.cmdlen; ++col) | |
2766 { | |
2767 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2768 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2769 } |
2770 } | |
2771 else | |
2772 # endif | |
2773 { | |
2774 cmdspos += preedit_start_col; | |
2775 cmdpos += preedit_start_col; | |
2776 } | |
2777 | |
2778 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2779 msg_col = cmdspos % (int)Columns; | |
2780 if (msg_row >= Rows) | |
2781 msg_row = Rows - 1; | |
2782 | |
2783 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
2784 { | |
2785 int char_len; | |
2786 int char_attr; | |
2787 | |
2788 char_attr = im_get_feedback_attr(col); | |
2789 if (char_attr < 0) | |
2790 break; /* end of preedit string */ | |
2791 | |
2792 # ifdef FEAT_MBYTE | |
2793 if (has_mbyte) | |
474 | 2794 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2795 else |
2796 # endif | |
2797 char_len = 1; | |
2798 | |
2799 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
2800 cmdpos += char_len; | |
2801 } | |
2802 | |
2803 msg_row = old_row; | |
2804 msg_col = old_col; | |
2805 } | |
2806 } | |
2807 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
2808 | |
2809 /* | |
2810 * Allocate a new command line buffer. | |
2811 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
2812 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
2813 */ | |
2814 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2815 alloc_cmdbuff(int len) |
7 | 2816 { |
2817 /* | |
2818 * give some extra space to avoid having to allocate all the time | |
2819 */ | |
2820 if (len < 80) | |
2821 len = 100; | |
2822 else | |
2823 len += 20; | |
2824 | |
2825 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
2826 ccline.cmdbufflen = len; | |
2827 } | |
2828 | |
2829 /* | |
2830 * Re-allocate the command line to length len + something extra. | |
2831 * return FAIL for failure, OK otherwise | |
2832 */ | |
2833 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2834 realloc_cmdbuff(int len) |
7 | 2835 { |
2836 char_u *p; | |
2837 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
2838 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
2839 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
|
2840 |
7 | 2841 p = ccline.cmdbuff; |
2842 alloc_cmdbuff(len); /* will get some more */ | |
2843 if (ccline.cmdbuff == NULL) /* out of memory */ | |
2844 { | |
2845 ccline.cmdbuff = p; /* keep the old one */ | |
2846 return FAIL; | |
2847 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
2848 /* 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
|
2849 * 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
|
2850 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
|
2851 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 2852 vim_free(p); |
1718 | 2853 |
2854 if (ccline.xpc != NULL | |
2855 && ccline.xpc->xp_pattern != NULL | |
2856 && ccline.xpc->xp_context != EXPAND_NOTHING | |
2857 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
2858 { | |
1754 | 2859 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 2860 |
2861 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
2862 * to point into the newly allocated memory. */ | |
2863 if (i >= 0 && i <= ccline.cmdlen) | |
2864 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
2865 } | |
2866 | |
7 | 2867 return OK; |
2868 } | |
2869 | |
359 | 2870 #if defined(FEAT_ARABIC) || defined(PROTO) |
2871 static char_u *arshape_buf = NULL; | |
2872 | |
2873 # if defined(EXITFREE) || defined(PROTO) | |
2874 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2875 free_cmdline_buf(void) |
359 | 2876 { |
2877 vim_free(arshape_buf); | |
2878 } | |
2879 # endif | |
2880 #endif | |
2881 | |
7 | 2882 /* |
2883 * Draw part of the cmdline at the current cursor position. But draw stars | |
2884 * when cmdline_star is TRUE. | |
2885 */ | |
2886 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2887 draw_cmdline(int start, int len) |
7 | 2888 { |
2889 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2890 int i; | |
2891 | |
2892 if (cmdline_star > 0) | |
2893 for (i = 0; i < len; ++i) | |
2894 { | |
2895 msg_putchar('*'); | |
2896 # ifdef FEAT_MBYTE | |
2897 if (has_mbyte) | |
474 | 2898 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 2899 # endif |
2900 } | |
2901 else | |
2902 #endif | |
2903 #ifdef FEAT_ARABIC | |
2904 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
2905 { | |
2906 static int buflen = 0; | |
2907 char_u *p; | |
2908 int j; | |
2909 int newlen = 0; | |
2910 int mb_l; | |
719 | 2911 int pc, pc1 = 0; |
7 | 2912 int prev_c = 0; |
2913 int prev_c1 = 0; | |
714 | 2914 int u8c; |
2915 int u8cc[MAX_MCO]; | |
7 | 2916 int nc = 0; |
2917 | |
2918 /* | |
2919 * Do arabic shaping into a temporary buffer. This is very | |
2920 * inefficient! | |
2921 */ | |
507 | 2922 if (len * 2 + 2 > buflen) |
7 | 2923 { |
2924 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
2925 * alloc()/free() calls. */ | |
359 | 2926 vim_free(arshape_buf); |
507 | 2927 buflen = len * 2 + 2; |
359 | 2928 arshape_buf = alloc(buflen); |
2929 if (arshape_buf == NULL) | |
7 | 2930 return; /* out of memory */ |
2931 } | |
2932 | |
507 | 2933 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
2934 { | |
2935 /* Prepend a space to draw the leading composing char on. */ | |
2936 arshape_buf[0] = ' '; | |
2937 newlen = 1; | |
2938 } | |
2939 | |
7 | 2940 for (j = start; j < start + len; j += mb_l) |
2941 { | |
2942 p = ccline.cmdbuff + j; | |
714 | 2943 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 2944 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 2945 if (ARABIC_CHAR(u8c)) |
2946 { | |
2947 /* Do Arabic shaping. */ | |
2948 if (cmdmsg_rl) | |
2949 { | |
2950 /* displaying from right to left */ | |
2951 pc = prev_c; | |
2952 pc1 = prev_c1; | |
714 | 2953 prev_c1 = u8cc[0]; |
7 | 2954 if (j + mb_l >= start + len) |
2955 nc = NUL; | |
2956 else | |
2957 nc = utf_ptr2char(p + mb_l); | |
2958 } | |
2959 else | |
2960 { | |
2961 /* displaying from left to right */ | |
2962 if (j + mb_l >= start + len) | |
2963 pc = NUL; | |
2964 else | |
714 | 2965 { |
2966 int pcc[MAX_MCO]; | |
2967 | |
2968 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 2969 start + len - j - mb_l); |
714 | 2970 pc1 = pcc[0]; |
2971 } | |
7 | 2972 nc = prev_c; |
2973 } | |
2974 prev_c = u8c; | |
2975 | |
714 | 2976 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 2977 |
359 | 2978 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 2979 if (u8cc[0] != 0) |
7 | 2980 { |
714 | 2981 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
2982 if (u8cc[1] != 0) | |
2983 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 2984 arshape_buf + newlen); |
7 | 2985 } |
2986 } | |
2987 else | |
2988 { | |
2989 prev_c = u8c; | |
359 | 2990 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 2991 newlen += mb_l; |
2992 } | |
2993 } | |
2994 | |
359 | 2995 msg_outtrans_len(arshape_buf, newlen); |
7 | 2996 } |
2997 else | |
2998 #endif | |
2999 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3000 } | |
3001 | |
3002 /* | |
3003 * Put a character on the command line. Shifts the following text to the | |
3004 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3005 * "c" must be printable (fit in one display cell)! | |
3006 */ | |
3007 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3008 putcmdline(int c, int shift) |
7 | 3009 { |
3010 if (cmd_silent) | |
3011 return; | |
3012 msg_no_more = TRUE; | |
3013 msg_putchar(c); | |
3014 if (shift) | |
3015 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3016 msg_no_more = FALSE; | |
3017 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3018 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3019 extra_char_shift = shift; |
7 | 3020 } |
3021 | |
3022 /* | |
3023 * Undo a putcmdline(c, FALSE). | |
3024 */ | |
3025 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3026 unputcmdline(void) |
7 | 3027 { |
3028 if (cmd_silent) | |
3029 return; | |
3030 msg_no_more = TRUE; | |
3031 if (ccline.cmdlen == ccline.cmdpos) | |
3032 msg_putchar(' '); | |
3558 | 3033 #ifdef FEAT_MBYTE |
3034 else if (has_mbyte) | |
3035 draw_cmdline(ccline.cmdpos, | |
3036 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3037 #endif | |
7 | 3038 else |
3039 draw_cmdline(ccline.cmdpos, 1); | |
3040 msg_no_more = FALSE; | |
3041 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3042 extra_char = NUL; |
7 | 3043 } |
3044 | |
3045 /* | |
3046 * Put the given string, of the given length, onto the command line. | |
3047 * If len is -1, then STRLEN() is used to calculate the length. | |
3048 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3049 * part will be redrawn, otherwise it will not. If this function is called | |
3050 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3051 * called afterwards. | |
3052 */ | |
3053 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3054 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3055 { |
3056 int retval; | |
3057 int i; | |
3058 int m; | |
3059 int c; | |
3060 | |
3061 if (len < 0) | |
3062 len = (int)STRLEN(str); | |
3063 | |
3064 /* Check if ccline.cmdbuff needs to be longer */ | |
3065 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
|
3066 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3067 else |
3068 retval = OK; | |
3069 if (retval == OK) | |
3070 { | |
3071 if (!ccline.overstrike) | |
3072 { | |
3073 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3074 ccline.cmdbuff + ccline.cmdpos, | |
3075 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3076 ccline.cmdlen += len; | |
3077 } | |
3078 else | |
3079 { | |
3080 #ifdef FEAT_MBYTE | |
3081 if (has_mbyte) | |
3082 { | |
3083 /* Count nr of characters in the new string. */ | |
3084 m = 0; | |
474 | 3085 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3086 ++m; |
3087 /* Count nr of bytes in cmdline that are overwritten by these | |
3088 * characters. */ | |
3089 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3090 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3091 --m; |
3092 if (i < ccline.cmdlen) | |
3093 { | |
3094 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3095 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3096 ccline.cmdlen += ccline.cmdpos + len - i; | |
3097 } | |
3098 else | |
3099 ccline.cmdlen = ccline.cmdpos + len; | |
3100 } | |
3101 else | |
3102 #endif | |
3103 if (ccline.cmdpos + len > ccline.cmdlen) | |
3104 ccline.cmdlen = ccline.cmdpos + len; | |
3105 } | |
3106 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3107 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3108 | |
3109 #ifdef FEAT_MBYTE | |
3110 if (enc_utf8) | |
3111 { | |
3112 /* When the inserted text starts with a composing character, | |
3113 * backup to the character before it. There could be two of them. | |
3114 */ | |
3115 i = 0; | |
3116 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3117 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3118 { | |
3119 i = (*mb_head_off)(ccline.cmdbuff, | |
3120 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3121 ccline.cmdpos -= i; | |
3122 len += i; | |
3123 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3124 } | |
3125 # ifdef FEAT_ARABIC | |
3126 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3127 { | |
3128 /* Check the previous character for Arabic combining pair. */ | |
3129 i = (*mb_head_off)(ccline.cmdbuff, | |
3130 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3131 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3132 + ccline.cmdpos - i), c)) | |
3133 { | |
3134 ccline.cmdpos -= i; | |
3135 len += i; | |
3136 } | |
3137 else | |
3138 i = 0; | |
3139 } | |
3140 # endif | |
3141 if (i != 0) | |
3142 { | |
3143 /* Also backup the cursor position. */ | |
3144 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3145 ccline.cmdspos -= i; | |
3146 msg_col -= i; | |
3147 if (msg_col < 0) | |
3148 { | |
3149 msg_col += Columns; | |
3150 --msg_row; | |
3151 } | |
3152 } | |
3153 } | |
3154 #endif | |
3155 | |
3156 if (redraw && !cmd_silent) | |
3157 { | |
3158 msg_no_more = TRUE; | |
3159 i = cmdline_row; | |
3114 | 3160 cursorcmd(); |
7 | 3161 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3162 /* Avoid clearing the rest of the line too often. */ | |
3163 if (cmdline_row != i || ccline.overstrike) | |
3164 msg_clr_eos(); | |
3165 msg_no_more = FALSE; | |
3166 } | |
3167 #ifdef FEAT_FKMAP | |
3168 /* | |
3169 * If we are in Farsi command mode, the character input must be in | |
3170 * Insert mode. So do not advance the cmdpos. | |
3171 */ | |
3172 if (!cmd_fkmap) | |
3173 #endif | |
3174 { | |
3175 if (KeyTyped) | |
534 | 3176 { |
7 | 3177 m = Columns * Rows; |
534 | 3178 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3179 m = MAXCOL; | |
3180 } | |
7 | 3181 else |
3182 m = MAXCOL; | |
3183 for (i = 0; i < len; ++i) | |
3184 { | |
3185 c = cmdline_charsize(ccline.cmdpos); | |
3186 #ifdef FEAT_MBYTE | |
3187 /* count ">" for a double-wide char that doesn't fit. */ | |
3188 if (has_mbyte) | |
3189 correct_cmdspos(ccline.cmdpos, c); | |
3190 #endif | |
1612 | 3191 /* Stop cursor at the end of the screen, but do increment the |
3192 * insert position, so that entering a very long command | |
3193 * works, even though you can't see it. */ | |
3194 if (ccline.cmdspos + c < m) | |
3195 ccline.cmdspos += c; | |
7 | 3196 #ifdef FEAT_MBYTE |
3197 if (has_mbyte) | |
3198 { | |
474 | 3199 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3200 if (c > len - i - 1) |
3201 c = len - i - 1; | |
3202 ccline.cmdpos += c; | |
3203 i += c; | |
3204 } | |
3205 #endif | |
3206 ++ccline.cmdpos; | |
3207 } | |
3208 } | |
3209 } | |
3210 if (redraw) | |
3211 msg_check(); | |
3212 return retval; | |
3213 } | |
3214 | |
95 | 3215 static struct cmdline_info prev_ccline; |
3216 static int prev_ccline_used = FALSE; | |
3217 | |
3218 /* | |
3219 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3220 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3221 * available globally in prev_ccline. | |
3222 */ | |
3223 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3224 save_cmdline(struct cmdline_info *ccp) |
95 | 3225 { |
3226 if (!prev_ccline_used) | |
3227 { | |
3228 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3229 prev_ccline_used = TRUE; | |
3230 } | |
3231 *ccp = prev_ccline; | |
3232 prev_ccline = ccline; | |
3233 ccline.cmdbuff = NULL; | |
3234 ccline.cmdprompt = NULL; | |
1718 | 3235 ccline.xpc = NULL; |
95 | 3236 } |
3237 | |
3238 /* | |
1214 | 3239 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3240 */ |
3241 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3242 restore_cmdline(struct cmdline_info *ccp) |
95 | 3243 { |
3244 ccline = prev_ccline; | |
3245 prev_ccline = *ccp; | |
3246 } | |
3247 | |
849 | 3248 #if defined(FEAT_EVAL) || defined(PROTO) |
3249 /* | |
3250 * Save the command line into allocated memory. Returns a pointer to be | |
3251 * passed to restore_cmdline_alloc() later. | |
3252 * Returns NULL when failed. | |
3253 */ | |
3254 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3255 save_cmdline_alloc(void) |
849 | 3256 { |
3257 struct cmdline_info *p; | |
3258 | |
3259 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3260 if (p != NULL) | |
3261 save_cmdline(p); | |
3262 return (char_u *)p; | |
3263 } | |
3264 | |
3265 /* | |
3266 * Restore the command line from the return value of save_cmdline_alloc(). | |
3267 */ | |
3268 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3269 restore_cmdline_alloc(char_u *p) |
849 | 3270 { |
3271 if (p != NULL) | |
3272 { | |
3273 restore_cmdline((struct cmdline_info *)p); | |
3274 vim_free(p); | |
3275 } | |
3276 } | |
3277 #endif | |
3278 | |
15 | 3279 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3280 * 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
|
3281 * Used by CTRL-R command in command-line mode. |
15 | 3282 * insert_reg() can't be used here, because special characters from the |
3283 * register contents will be interpreted as commands. | |
3284 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3285 * Return FAIL for failure, OK otherwise. |
15 | 3286 */ |
3287 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3288 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3289 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3290 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
|
3291 int remcr) /* remove trailing CR */ |
15 | 3292 { |
3293 long i; | |
3294 char_u *arg; | |
772 | 3295 char_u *p; |
15 | 3296 int allocated; |
3297 struct cmdline_info save_ccline; | |
3298 | |
3299 /* check for valid regname; also accept special characters for CTRL-R in | |
3300 * the command line */ | |
3301 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
|
3302 && 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
|
3303 && !valid_yank_reg(regname, FALSE)) |
15 | 3304 return FAIL; |
3305 | |
3306 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3307 * CTRL-C to break the loop. */ | |
3308 line_breakcheck(); | |
3309 if (got_int) | |
3310 return FAIL; | |
3311 | |
3312 #ifdef FEAT_CLIPBOARD | |
3313 regname = may_get_selection(regname); | |
3314 #endif | |
3315 | |
634 | 3316 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3317 * things like going to another buffer when evaluating an expression. */ |
95 | 3318 save_cmdline(&save_ccline); |
634 | 3319 ++textlock; |
15 | 3320 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3321 --textlock; |
95 | 3322 restore_cmdline(&save_ccline); |
15 | 3323 |
3324 if (i) | |
3325 { | |
3326 /* Got the value of a special register in "arg". */ | |
3327 if (arg == NULL) | |
3328 return FAIL; | |
772 | 3329 |
3330 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3331 * part of the word. */ | |
3332 p = arg; | |
3333 if (p_is && regname == Ctrl_W) | |
3334 { | |
3335 char_u *w; | |
3336 int len; | |
3337 | |
3338 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3339 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3340 { |
3341 #ifdef FEAT_MBYTE | |
3342 if (has_mbyte) | |
3343 { | |
3344 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3345 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3346 break; | |
3347 w -= len; | |
3348 } | |
3349 else | |
3350 #endif | |
3351 { | |
3352 if (!vim_iswordc(w[-1])) | |
3353 break; | |
3354 --w; | |
3355 } | |
3356 } | |
2937 | 3357 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3358 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3359 p += len; | |
3360 } | |
3361 | |
3362 cmdline_paste_str(p, literally); | |
15 | 3363 if (allocated) |
3364 vim_free(arg); | |
3365 return OK; | |
3366 } | |
3367 | |
1015 | 3368 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3369 } |
3370 | |
3371 /* | |
3372 * Put a string on the command line. | |
3373 * When "literally" is TRUE, insert literally. | |
3374 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3375 * line. | |
3376 */ | |
3377 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3378 cmdline_paste_str(char_u *s, int literally) |
15 | 3379 { |
3380 int c, cv; | |
3381 | |
3382 if (literally) | |
3383 put_on_cmdline(s, -1, TRUE); | |
3384 else | |
3385 while (*s != NUL) | |
3386 { | |
3387 cv = *s; | |
3388 if (cv == Ctrl_V && s[1]) | |
3389 ++s; | |
3390 #ifdef FEAT_MBYTE | |
3391 if (has_mbyte) | |
1606 | 3392 c = mb_cptr2char_adv(&s); |
15 | 3393 else |
3394 #endif | |
3395 c = *s++; | |
3628 | 3396 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3397 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3398 #ifdef UNIX |
3399 || c == intr_char | |
3400 #endif | |
3401 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3402 stuffcharReadbuff(Ctrl_V); | |
3403 stuffcharReadbuff(c); | |
3404 } | |
3405 } | |
3406 | |
7 | 3407 #ifdef FEAT_WILDMENU |
3408 /* | |
3409 * Delete characters on the command line, from "from" to the current | |
3410 * position. | |
3411 */ | |
3412 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3413 cmdline_del(int from) |
7 | 3414 { |
3415 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3416 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3417 ccline.cmdlen -= ccline.cmdpos - from; | |
3418 ccline.cmdpos = from; | |
3419 } | |
3420 #endif | |
3421 | |
3422 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3423 * 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
|
3424 * 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
|
3425 * overwritten. |
7 | 3426 */ |
3427 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3428 redrawcmdline(void) |
7 | 3429 { |
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
|
3430 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
|
3431 } |
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
|
3432 |
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
|
3433 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
|
3434 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
|
3435 { |
7 | 3436 if (cmd_silent) |
3437 return; | |
3438 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
|
3439 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
|
3440 compute_cmdrow(); |
7 | 3441 redrawcmd(); |
3442 cursorcmd(); | |
3443 } | |
3444 | |
3445 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3446 redrawcmdprompt(void) |
7 | 3447 { |
3448 int i; | |
3449 | |
3450 if (cmd_silent) | |
3451 return; | |
531 | 3452 if (ccline.cmdfirstc != NUL) |
7 | 3453 msg_putchar(ccline.cmdfirstc); |
3454 if (ccline.cmdprompt != NULL) | |
3455 { | |
3456 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3457 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3458 /* do the reverse of set_cmdspos() */ | |
531 | 3459 if (ccline.cmdfirstc != NUL) |
7 | 3460 --ccline.cmdindent; |
3461 } | |
3462 else | |
3463 for (i = ccline.cmdindent; i > 0; --i) | |
3464 msg_putchar(' '); | |
3465 } | |
3466 | |
3467 /* | |
3468 * Redraw what is currently on the command line. | |
3469 */ | |
3470 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3471 redrawcmd(void) |
7 | 3472 { |
3473 if (cmd_silent) | |
3474 return; | |
3475 | |
683 | 3476 /* when 'incsearch' is set there may be no command line while redrawing */ |
3477 if (ccline.cmdbuff == NULL) | |
3478 { | |
3479 windgoto(cmdline_row, 0); | |
3480 msg_clr_eos(); | |
3481 return; | |
3482 } | |
3483 | |
7 | 3484 msg_start(); |
3485 redrawcmdprompt(); | |
3486 | |
3487 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3488 msg_no_more = TRUE; | |
3489 draw_cmdline(0, ccline.cmdlen); | |
3490 msg_clr_eos(); | |
3491 msg_no_more = FALSE; | |
3492 | |
3493 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
|
3494 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
|
3495 putcmdline(extra_char, extra_char_shift); |
7 | 3496 |
3497 /* | |
3498 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3499 * in cmdline mode we can reset them now. | |
3500 */ | |
3501 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3502 | |
3503 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3504 * in cmdline mode */ | |
3505 skip_redraw = FALSE; | |
3506 } | |
3507 | |
3508 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3509 compute_cmdrow(void) |
7 | 3510 { |
540 | 3511 if (exmode_active || msg_scrolled != 0) |
7 | 3512 cmdline_row = Rows - 1; |
3513 else | |
3514 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
|
3515 + lastwin->w_status_height; |
7 | 3516 } |
3517 | |
3518 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3519 cursorcmd(void) |
7 | 3520 { |
3521 if (cmd_silent) | |
3522 return; | |
3523 | |
3524 #ifdef FEAT_RIGHTLEFT | |
3525 if (cmdmsg_rl) | |
3526 { | |
3527 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3528 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3529 if (msg_row <= 0) | |
3530 msg_row = Rows - 1; | |
3531 } | |
3532 else | |
3533 #endif | |
3534 { | |
3535 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3536 msg_col = ccline.cmdspos % (int)Columns; | |
3537 if (msg_row >= Rows) | |
3538 msg_row = Rows - 1; | |
3539 } | |
3540 | |
3541 windgoto(msg_row, msg_col); | |
3542 #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
|
3543 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
|
3544 redrawcmd_preedit(); |
7 | 3545 #endif |
3546 #ifdef MCH_CURSOR_SHAPE | |
3547 mch_update_cursor(); | |
3548 #endif | |
3549 } | |
3550 | |
3551 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3552 gotocmdline(int clr) |
7 | 3553 { |
3554 msg_start(); | |
3555 #ifdef FEAT_RIGHTLEFT | |
3556 if (cmdmsg_rl) | |
3557 msg_col = Columns - 1; | |
3558 else | |
3559 #endif | |
3560 msg_col = 0; /* always start in column 0 */ | |
3561 if (clr) /* clear the bottom line(s) */ | |
3562 msg_clr_eos(); /* will reset clear_cmdline */ | |
3563 windgoto(cmdline_row, 0); | |
3564 } | |
3565 | |
3566 /* | |
3567 * Check the word in front of the cursor for an abbreviation. | |
3568 * Called when the non-id character "c" has been entered. | |
3569 * When an abbreviation is recognized it is removed from the text with | |
3570 * backspaces and the replacement string is inserted, followed by "c". | |
3571 */ | |
3572 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3573 ccheck_abbr(int c) |
7 | 3574 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3575 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3576 |
7 | 3577 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3578 return FALSE; | |
3579 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3580 /* 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
|
3581 * 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
|
3582 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
|
3583 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3584 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
|
3585 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3586 && 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
|
3587 && 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
|
3588 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3589 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3590 /* 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
|
3591 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3592 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3593 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3594 } |
3595 | |
3164 | 3596 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3597 static int | |
3598 #ifdef __BORLANDC__ | |
3599 _RTLENTRYF | |
3600 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3601 sort_func_compare(const void *s1, const void *s2) |
3164 | 3602 { |
3603 char_u *p1 = *(char_u **)s1; | |
3604 char_u *p2 = *(char_u **)s2; | |
3605 | |
3606 if (*p1 != '<' && *p2 == '<') return -1; | |
3607 if (*p1 == '<' && *p2 != '<') return 1; | |
3608 return STRCMP(p1, p2); | |
3609 } | |
3610 #endif | |
3611 | |
7 | 3612 /* |
3613 * Return FAIL if this is not an appropriate context in which to do | |
3614 * completion of anything, return OK if it is (even if there are no matches). | |
3615 * For the caller, this means that the character is just passed through like a | |
3616 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3617 */ | |
3618 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3619 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3620 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3621 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3622 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3623 int escape) /* if TRUE, escape the returned matches */ |
7 | 3624 { |
3625 int i, j; | |
3626 char_u *p1; | |
3627 char_u *p2; | |
3628 int difflen; | |
3629 int v; | |
3630 | |
3631 if (xp->xp_numfiles == -1) | |
3632 { | |
3633 set_expand_context(xp); | |
3634 cmd_showtail = expand_showtail(xp); | |
3635 } | |
3636 | |
3637 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3638 { | |
3639 beep_flush(); | |
3640 return OK; /* Something illegal on command line */ | |
3641 } | |
3642 if (xp->xp_context == EXPAND_NOTHING) | |
3643 { | |
3644 /* Caller can use the character as a normal char instead */ | |
3645 return FAIL; | |
3646 } | |
3647 | |
3648 MSG_PUTS("..."); /* show that we are busy */ | |
3649 out_flush(); | |
3650 | |
3651 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3652 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3653 |
3654 if (type == WILD_NEXT || type == WILD_PREV) | |
3655 { | |
3656 /* | |
3657 * Get next/previous match for a previous expanded pattern. | |
3658 */ | |
3659 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3660 } | |
3661 else | |
3662 { | |
3663 /* | |
3664 * Translate string into pattern and expand it. | |
3665 */ | |
1965 | 3666 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3667 xp->xp_context)) == NULL) | |
7 | 3668 p2 = NULL; |
3669 else | |
3670 { | |
2652 | 3671 int use_options = options | |
3961 | 3672 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3673 if (escape) | |
3674 use_options |= WILD_ESCAPE; | |
2652 | 3675 |
3676 if (p_wic) | |
3677 use_options += WILD_ICASE; | |
1965 | 3678 p2 = ExpandOne(xp, p1, |
3679 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3680 use_options, type); |
7 | 3681 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3682 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3683 if (p2 != NULL && type == WILD_LONGEST) |
3684 { | |
1965 | 3685 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3686 if (ccline.cmdbuff[i + j] == '*' |
3687 || ccline.cmdbuff[i + j] == '?') | |
3688 break; | |
3689 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
|
3690 VIM_CLEAR(p2); |
7 | 3691 } |
3692 } | |
3693 } | |
3694 | |
3695 if (p2 != NULL && !got_int) | |
3696 { | |
1965 | 3697 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
|
3698 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3699 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3700 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3701 xp->xp_pattern = ccline.cmdbuff + i; |
3702 } | |
3703 else | |
3704 v = OK; | |
3705 if (v == OK) | |
3706 { | |
323 | 3707 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3708 &ccline.cmdbuff[ccline.cmdpos], | |
3709 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3710 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3711 ccline.cmdlen += difflen; |
3712 ccline.cmdpos += difflen; | |
3713 } | |
3714 } | |
3715 vim_free(p2); | |
3716 | |
3717 redrawcmd(); | |
33 | 3718 cursorcmd(); |
7 | 3719 |
3720 /* When expanding a ":map" command and no matches are found, assume that | |
3721 * the key is supposed to be inserted literally */ | |
3722 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3723 return FAIL; | |
3724 | |
3725 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3726 beep_flush(); | |
3727 else if (xp->xp_numfiles == 1) | |
3728 /* free expanded pattern */ | |
3729 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3730 | |
3731 return OK; | |
3732 } | |
3733 | |
3734 /* | |
3735 * Do wildcard expansion on the string 'str'. | |
3736 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3737 * Return a pointer to allocated memory containing the new string. |
7 | 3738 * Return NULL for failure. |
3739 * | |
1412 | 3740 * "orig" is the originally expanded string, copied to allocated memory. It |
3741 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3742 * WILD_PREV "orig" should be NULL. | |
3743 * | |
838 | 3744 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3745 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3746 * |
3747 * mode = WILD_FREE: just free previously expanded matches | |
3748 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3749 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3750 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3751 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3752 * mode = WILD_ALL: return all matches concatenated | |
3753 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3754 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3755 * |
3756 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3757 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3758 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3759 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3760 * options = WILD_ADD_SLASH: add a slash after directory names | |
3761 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3762 * options = WILD_SILENT: don't print warning messages | |
3763 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3764 * options = WILD_ICASE: ignore case for files |
7 | 3765 * |
3766 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3767 */ | |
3768 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3769 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3770 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3771 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3772 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
|
3773 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3774 int mode) |
7 | 3775 { |
3776 char_u *ss = NULL; | |
3777 static int findex; | |
3778 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3779 int orig_saved = FALSE; |
7 | 3780 int i; |
3781 long_u len; | |
3782 int non_suf_match; /* number without matching suffix */ | |
3783 | |
3784 /* | |
3785 * first handle the case of using an old match | |
3786 */ | |
3787 if (mode == WILD_NEXT || mode == WILD_PREV) | |
3788 { | |
3789 if (xp->xp_numfiles > 0) | |
3790 { | |
3791 if (mode == WILD_PREV) | |
3792 { | |
3793 if (findex == -1) | |
3794 findex = xp->xp_numfiles; | |
3795 --findex; | |
3796 } | |
3797 else /* mode == WILD_NEXT */ | |
3798 ++findex; | |
3799 | |
3800 /* | |
3801 * When wrapping around, return the original string, set findex to | |
3802 * -1. | |
3803 */ | |
3804 if (findex < 0) | |
3805 { | |
3806 if (orig_save == NULL) | |
3807 findex = xp->xp_numfiles - 1; | |
3808 else | |
3809 findex = -1; | |
3810 } | |
3811 if (findex >= xp->xp_numfiles) | |
3812 { | |
3813 if (orig_save == NULL) | |
3814 findex = 0; | |
3815 else | |
3816 findex = -1; | |
3817 } | |
3818 #ifdef FEAT_WILDMENU | |
3819 if (p_wmnu) | |
3820 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
3821 findex, cmd_showtail); | |
3822 #endif | |
3823 if (findex == -1) | |
3824 return vim_strsave(orig_save); | |
3825 return vim_strsave(xp->xp_files[findex]); | |
3826 } | |
3827 else | |
3828 return NULL; | |
3829 } | |
3830 | |
1412 | 3831 /* free old names */ |
7 | 3832 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
3833 { | |
3834 FreeWild(xp->xp_numfiles, xp->xp_files); | |
3835 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
|
3836 VIM_CLEAR(orig_save); |
7 | 3837 } |
3838 findex = 0; | |
3839 | |
3840 if (mode == WILD_FREE) /* only release file name */ | |
3841 return NULL; | |
3842 | |
3843 if (xp->xp_numfiles == -1) | |
3844 { | |
3845 vim_free(orig_save); | |
3846 orig_save = orig; | |
1432 | 3847 orig_saved = TRUE; |
7 | 3848 |
3849 /* | |
3850 * Do the expansion. | |
3851 */ | |
3852 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
3853 options) == FAIL) | |
3854 { | |
3855 #ifdef FNAME_ILLEGAL | |
3856 /* Illegal file name has been silently skipped. But when there | |
3857 * are wildcards, the real problem is that there was no match, | |
3858 * causing the pattern to be added, which has illegal characters. | |
3859 */ | |
3860 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
3861 EMSG2(_(e_nomatch2), str); | |
3862 #endif | |
3863 } | |
3864 else if (xp->xp_numfiles == 0) | |
3865 { | |
3866 if (!(options & WILD_SILENT)) | |
3867 EMSG2(_(e_nomatch2), str); | |
3868 } | |
3869 else | |
3870 { | |
3871 /* Escape the matches for use on the command line. */ | |
3872 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
3873 | |
3874 /* | |
3875 * Check for matching suffixes in file names. | |
3876 */ | |
3398 | 3877 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
3878 && mode != WILD_LONGEST) | |
7 | 3879 { |
3880 if (xp->xp_numfiles) | |
3881 non_suf_match = xp->xp_numfiles; | |
3882 else | |
3883 non_suf_match = 1; | |
3884 if ((xp->xp_context == EXPAND_FILES | |
3885 || xp->xp_context == EXPAND_DIRECTORIES) | |
3886 && xp->xp_numfiles > 1) | |
3887 { | |
3888 /* | |
3889 * More than one match; check suffix. | |
3890 * The files will have been sorted on matching suffix in | |
3891 * expand_wildcards, only need to check the first two. | |
3892 */ | |
3893 non_suf_match = 0; | |
3894 for (i = 0; i < 2; ++i) | |
3895 if (match_suffix(xp->xp_files[i])) | |
3896 ++non_suf_match; | |
3897 } | |
3898 if (non_suf_match != 1) | |
3899 { | |
3900 /* Can we ever get here unless it's while expanding | |
3901 * interactively? If not, we can get rid of this all | |
3902 * together. Don't really want to wait for this message | |
3903 * (and possibly have to hit return to continue!). | |
3904 */ | |
3905 if (!(options & WILD_SILENT)) | |
3906 EMSG(_(e_toomany)); | |
3907 else if (!(options & WILD_NO_BEEP)) | |
3908 beep_flush(); | |
3909 } | |
3910 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
3911 ss = vim_strsave(xp->xp_files[0]); | |
3912 } | |
3913 } | |
3914 } | |
3915 | |
3916 /* Find longest common part */ | |
3917 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
3918 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3919 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3920 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3921 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3922 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 3923 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3924 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3925 if (has_mbyte) |
7 | 3926 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3927 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
|
3928 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
|
3929 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3930 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3931 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
3932 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
|
3933 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
|
3934 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3935 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3936 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3937 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
|
3938 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3939 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3940 ci = xp->xp_files[i][len]; |
4242 | 3941 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 3942 || xp->xp_context == EXPAND_FILES |
714 | 3943 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 3944 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 3945 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3946 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 3947 break; |
3948 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3949 else if (c0 != ci) |
7 | 3950 break; |
3951 } | |
3952 if (i < xp->xp_numfiles) | |
3953 { | |
3954 if (!(options & WILD_NO_BEEP)) | |
6949 | 3955 vim_beep(BO_WILD); |
7 | 3956 break; |
3957 } | |
3958 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
3959 |
7 | 3960 ss = alloc((unsigned)len + 1); |
3961 if (ss) | |
419 | 3962 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 3963 findex = -1; /* next p_wc gets first one */ |
3964 } | |
3965 | |
3966 /* Concatenate all matching names */ | |
3967 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
3968 { | |
3969 len = 0; | |
3970 for (i = 0; i < xp->xp_numfiles; ++i) | |
3971 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
3972 ss = lalloc(len, TRUE); | |
3973 if (ss != NULL) | |
3974 { | |
3975 *ss = NUL; | |
3976 for (i = 0; i < xp->xp_numfiles; ++i) | |
3977 { | |
3978 STRCAT(ss, xp->xp_files[i]); | |
3979 if (i != xp->xp_numfiles - 1) | |
3980 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
3981 } | |
3982 } | |
3983 } | |
3984 | |
3985 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
3986 ExpandCleanup(xp); | |
3987 | |
1412 | 3988 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 3989 if (!orig_saved) |
1412 | 3990 vim_free(orig); |
3991 | |
7 | 3992 return ss; |
3993 } | |
3994 | |
3995 /* | |
3996 * Prepare an expand structure for use. | |
3997 */ | |
3998 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3999 ExpandInit(expand_T *xp) |
7 | 4000 { |
1718 | 4001 xp->xp_pattern = NULL; |
1965 | 4002 xp->xp_pattern_len = 0; |
7 | 4003 xp->xp_backslash = XP_BS_NONE; |
632 | 4004 #ifndef BACKSLASH_IN_FILENAME |
4005 xp->xp_shell = FALSE; | |
4006 #endif | |
7 | 4007 xp->xp_numfiles = -1; |
4008 xp->xp_files = NULL; | |
632 | 4009 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4010 xp->xp_arg = NULL; | |
4011 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4012 xp->xp_line = NULL; |
7 | 4013 } |
4014 | |
4015 /* | |
4016 * Cleanup an expand structure after use. | |
4017 */ | |
4018 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4019 ExpandCleanup(expand_T *xp) |
7 | 4020 { |
4021 if (xp->xp_numfiles >= 0) | |
4022 { | |
4023 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4024 xp->xp_numfiles = -1; | |
4025 } | |
4026 } | |
4027 | |
4028 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4029 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4030 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4031 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4032 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4033 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4034 int options) |
7 | 4035 { |
4036 int i; | |
4037 char_u *p; | |
4038 | |
4039 /* | |
4040 * May change home directory back to "~" | |
4041 */ | |
4042 if (options & WILD_HOME_REPLACE) | |
4043 tilde_replace(str, numfiles, files); | |
4044 | |
4045 if (options & WILD_ESCAPE) | |
4046 { | |
4047 if (xp->xp_context == EXPAND_FILES | |
2778 | 4048 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4049 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4050 || xp->xp_context == EXPAND_BUFFERS |
4051 || xp->xp_context == EXPAND_DIRECTORIES) | |
4052 { | |
4053 /* | |
4054 * Insert a backslash into a file name before a space, \, %, # | |
4055 * and wildmatch characters, except '~'. | |
4056 */ | |
4057 for (i = 0; i < numfiles; ++i) | |
4058 { | |
4059 /* for ":set path=" we need to escape spaces twice */ | |
4060 if (xp->xp_backslash == XP_BS_THREE) | |
4061 { | |
4062 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4063 if (p != NULL) | |
4064 { | |
4065 vim_free(files[i]); | |
4066 files[i] = p; | |
719 | 4067 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4068 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4069 if (p != NULL) | |
4070 { | |
4071 vim_free(files[i]); | |
4072 files[i] = p; | |
4073 } | |
4074 #endif | |
4075 } | |
4076 } | |
1589 | 4077 #ifdef BACKSLASH_IN_FILENAME |
4078 p = vim_strsave_fnameescape(files[i], FALSE); | |
4079 #else | |
1586 | 4080 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4081 #endif |
7 | 4082 if (p != NULL) |
4083 { | |
4084 vim_free(files[i]); | |
4085 files[i] = p; | |
4086 } | |
4087 | |
4088 /* If 'str' starts with "\~", replace "~" at start of | |
4089 * files[i] with "\~". */ | |
4090 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4091 escape_fname(&files[i]); |
7 | 4092 } |
4093 xp->xp_backslash = XP_BS_NONE; | |
435 | 4094 |
4095 /* If the first file starts with a '+' escape it. Otherwise it | |
4096 * could be seen as "+cmd". */ | |
4097 if (*files[0] == '+') | |
4098 escape_fname(&files[0]); | |
7 | 4099 } |
4100 else if (xp->xp_context == EXPAND_TAGS) | |
4101 { | |
4102 /* | |
4103 * Insert a backslash before characters in a tag name that | |
4104 * would terminate the ":tag" command. | |
4105 */ | |
4106 for (i = 0; i < numfiles; ++i) | |
4107 { | |
4108 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4109 if (p != NULL) | |
4110 { | |
4111 vim_free(files[i]); | |
4112 files[i] = p; | |
4113 } | |
4114 } | |
4115 } | |
4116 } | |
4117 } | |
4118 | |
4119 /* | |
1586 | 4120 * Escape special characters in "fname" for when used as a file name argument |
4121 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4122 * Returns the result in allocated memory. | |
4123 */ | |
4124 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4125 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4126 { |
1685 | 4127 char_u *p; |
1586 | 4128 #ifdef BACKSLASH_IN_FILENAME |
4129 char_u buf[20]; | |
4130 int j = 0; | |
4131 | |
5481 | 4132 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4133 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4134 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4135 buf[j++] = *p; |
4136 buf[j] = NUL; | |
1700 | 4137 p = vim_strsave_escaped(fname, buf); |
1586 | 4138 #else |
1685 | 4139 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4140 if (shell && csh_like_shell() && p != NULL) | |
4141 { | |
4142 char_u *s; | |
4143 | |
4144 /* For csh and similar shells need to put two backslashes before '!'. | |
4145 * One is taken by Vim, one by the shell. */ | |
4146 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4147 vim_free(p); | |
4148 p = s; | |
4149 } | |
1700 | 4150 #endif |
4151 | |
4152 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4153 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4154 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4155 escape_fname(&p); |
4156 | |
1685 | 4157 return p; |
1586 | 4158 } |
4159 | |
4160 /* | |
435 | 4161 * Put a backslash before the file name in "pp", which is in allocated memory. |
4162 */ | |
4163 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4164 escape_fname(char_u **pp) |
435 | 4165 { |
4166 char_u *p; | |
4167 | |
4168 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4169 if (p != NULL) | |
4170 { | |
4171 p[0] = '\\'; | |
4172 STRCPY(p + 1, *pp); | |
4173 vim_free(*pp); | |
4174 *pp = p; | |
4175 } | |
4176 } | |
4177 | |
4178 /* | |
7 | 4179 * For each file name in files[num_files]: |
4180 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4181 */ | |
4182 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4183 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4184 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4185 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4186 char_u **files) |
7 | 4187 { |
4188 int i; | |
4189 char_u *p; | |
4190 | |
4191 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4192 { | |
4193 for (i = 0; i < num_files; ++i) | |
4194 { | |
4195 p = home_replace_save(NULL, files[i]); | |
4196 if (p != NULL) | |
4197 { | |
4198 vim_free(files[i]); | |
4199 files[i] = p; | |
4200 } | |
4201 } | |
4202 } | |
4203 } | |
4204 | |
4205 /* | |
4206 * Show all matches for completion on the command line. | |
4207 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4208 * be inserted like a normal character. | |
4209 */ | |
4210 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4211 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4212 { |
4213 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4214 int num_files; | |
4215 char_u **files_found; | |
4216 int i, j, k; | |
4217 int maxlen; | |
4218 int lines; | |
4219 int columns; | |
4220 char_u *p; | |
4221 int lastlen; | |
4222 int attr; | |
4223 int showtail; | |
4224 | |
4225 if (xp->xp_numfiles == -1) | |
4226 { | |
4227 set_expand_context(xp); | |
4228 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4229 &num_files, &files_found); | |
4230 showtail = expand_showtail(xp); | |
4231 if (i != EXPAND_OK) | |
4232 return i; | |
4233 | |
4234 } | |
4235 else | |
4236 { | |
4237 num_files = xp->xp_numfiles; | |
4238 files_found = xp->xp_files; | |
4239 showtail = cmd_showtail; | |
4240 } | |
4241 | |
4242 #ifdef FEAT_WILDMENU | |
4243 if (!wildmenu) | |
4244 { | |
4245 #endif | |
4246 msg_didany = FALSE; /* lines_left will be set */ | |
4247 msg_start(); /* prepare for paging */ | |
4248 msg_putchar('\n'); | |
4249 out_flush(); | |
4250 cmdline_row = msg_row; | |
4251 msg_didany = FALSE; /* lines_left will be set again */ | |
4252 msg_start(); /* prepare for paging */ | |
4253 #ifdef FEAT_WILDMENU | |
4254 } | |
4255 #endif | |
4256 | |
4257 if (got_int) | |
4258 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4259 #ifdef FEAT_WILDMENU | |
4260 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
|
4261 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4262 #endif |
4263 else | |
4264 { | |
4265 /* find the length of the longest file name */ | |
4266 maxlen = 0; | |
4267 for (i = 0; i < num_files; ++i) | |
4268 { | |
4269 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4270 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4271 || xp->xp_context == EXPAND_BUFFERS)) |
4272 { | |
4273 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4274 j = vim_strsize(NameBuff); | |
4275 } | |
4276 else | |
4277 j = vim_strsize(L_SHOWFILE(i)); | |
4278 if (j > maxlen) | |
4279 maxlen = j; | |
4280 } | |
4281 | |
4282 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4283 lines = num_files; | |
4284 else | |
4285 { | |
4286 /* compute the number of columns and lines for the listing */ | |
4287 maxlen += 2; /* two spaces between file names */ | |
4288 columns = ((int)Columns + 2) / maxlen; | |
4289 if (columns < 1) | |
4290 columns = 1; | |
4291 lines = (num_files + columns - 1) / columns; | |
4292 } | |
4293 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4294 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4295 |
4296 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4297 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4298 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4299 msg_clr_eos(); |
4300 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
|
4301 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4302 } |
4303 | |
4304 /* list the files line by line */ | |
4305 for (i = 0; i < lines; ++i) | |
4306 { | |
4307 lastlen = 999; | |
4308 for (k = i; k < num_files; k += lines) | |
4309 { | |
4310 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4311 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4312 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4313 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4314 msg_advance(maxlen + 1); | |
4315 msg_puts(p); | |
4316 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
|
4317 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4318 break; |
4319 } | |
4320 for (j = maxlen - lastlen; --j >= 0; ) | |
4321 msg_putchar(' '); | |
4322 if (xp->xp_context == EXPAND_FILES | |
714 | 4323 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4324 || xp->xp_context == EXPAND_BUFFERS) |
4325 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4326 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4327 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4328 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4329 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4330 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4331 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4332 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4333 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4334 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4335 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
|
4336 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4337 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4338 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4339 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4340 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4341 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4342 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4343 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4344 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4345 j = mch_isdir(files_found[k]); |
7 | 4346 if (showtail) |
4347 p = L_SHOWFILE(k); | |
4348 else | |
4349 { | |
4350 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4351 TRUE); | |
4352 p = NameBuff; | |
4353 } | |
4354 } | |
4355 else | |
4356 { | |
4357 j = FALSE; | |
4358 p = L_SHOWFILE(k); | |
4359 } | |
4360 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4361 } | |
4362 if (msg_col > 0) /* when not wrapped around */ | |
4363 { | |
4364 msg_clr_eos(); | |
4365 msg_putchar('\n'); | |
4366 } | |
4367 out_flush(); /* show one line at a time */ | |
4368 if (got_int) | |
4369 { | |
4370 got_int = FALSE; | |
4371 break; | |
4372 } | |
4373 } | |
4374 | |
4375 /* | |
4376 * we redraw the command below the lines that we have just listed | |
4377 * This is a bit tricky, but it saves a lot of screen updating. | |
4378 */ | |
4379 cmdline_row = msg_row; /* will put it back later */ | |
4380 } | |
4381 | |
4382 if (xp->xp_numfiles == -1) | |
4383 FreeWild(num_files, files_found); | |
4384 | |
4385 return EXPAND_OK; | |
4386 } | |
4387 | |
4388 /* | |
4389 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4390 * Find tail of file name path, but ignore trailing "/". | |
4391 */ | |
4392 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4393 sm_gettail(char_u *s) |
7 | 4394 { |
4395 char_u *p; | |
4396 char_u *t = s; | |
4397 int had_sep = FALSE; | |
4398 | |
4399 for (p = s; *p != NUL; ) | |
4400 { | |
4401 if (vim_ispathsep(*p) | |
4402 #ifdef BACKSLASH_IN_FILENAME | |
4403 && !rem_backslash(p) | |
4404 #endif | |
4405 ) | |
4406 had_sep = TRUE; | |
4407 else if (had_sep) | |
4408 { | |
4409 t = p; | |
4410 had_sep = FALSE; | |
4411 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4412 MB_PTR_ADV(p); |
7 | 4413 } |
4414 return t; | |
4415 } | |
4416 | |
4417 /* | |
4418 * Return TRUE if we only need to show the tail of completion matches. | |
4419 * When not completing file names or there is a wildcard in the path FALSE is | |
4420 * returned. | |
4421 */ | |
4422 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4423 expand_showtail(expand_T *xp) |
7 | 4424 { |
4425 char_u *s; | |
4426 char_u *end; | |
4427 | |
4428 /* When not completing file names a "/" may mean something different. */ | |
714 | 4429 if (xp->xp_context != EXPAND_FILES |
4430 && xp->xp_context != EXPAND_SHELLCMD | |
4431 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4432 return FALSE; |
4433 | |
4434 end = gettail(xp->xp_pattern); | |
4435 if (end == xp->xp_pattern) /* there is no path separator */ | |
4436 return FALSE; | |
4437 | |
4438 for (s = xp->xp_pattern; s < end; s++) | |
4439 { | |
4440 /* Skip escaped wildcards. Only when the backslash is not a path | |
4441 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4442 if (rem_backslash(s)) | |
4443 ++s; | |
4444 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4445 return FALSE; | |
4446 } | |
4447 return TRUE; | |
4448 } | |
4449 | |
4450 /* | |
4451 * Prepare a string for expansion. | |
4452 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4453 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4454 * When expanding other names: The string will be used with regcomp(). Copy |
4455 * the name into allocated memory and prepend "^". | |
4456 */ | |
4457 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4458 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4459 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4460 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4461 int context) /* EXPAND_FILES etc. */ |
7 | 4462 { |
4463 char_u *retval; | |
4464 int i, j; | |
4465 int new_len; | |
4466 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4467 int ends_in_star; |
7 | 4468 |
714 | 4469 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4470 && context != EXPAND_FILES_IN_PATH |
714 | 4471 && context != EXPAND_SHELLCMD |
4472 && context != EXPAND_DIRECTORIES) | |
7 | 4473 { |
4474 /* | |
4475 * Matching will be done internally (on something other than files). | |
4476 * So we convert the file-matching-type wildcards into our kind for | |
4477 * use with vim_regcomp(). First work out how long it will be: | |
4478 */ | |
4479 | |
4480 /* For help tags the translation is done in find_help_tags(). | |
4481 * For a tag pattern starting with "/" no translation is needed. */ | |
4482 if (context == EXPAND_HELP | |
4483 || context == EXPAND_COLORS | |
4484 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4485 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4486 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4487 || 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
|
4488 || ((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
|
4489 || 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
|
4490 && fname[0] == '/')) |
7 | 4491 retval = vim_strnsave(fname, len); |
4492 else | |
4493 { | |
4494 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4495 for (i = 0; i < len; i++) | |
4496 { | |
4497 if (fname[i] == '*' || fname[i] == '~') | |
4498 new_len++; /* '*' needs to be replaced by ".*" | |
4499 '~' needs to be replaced by "\~" */ | |
4500 | |
4501 /* Buffer names are like file names. "." should be literal */ | |
4502 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4503 new_len++; /* "." becomes "\." */ | |
4504 | |
4505 /* Custom expansion takes care of special things, match | |
4506 * backslashes literally (perhaps also for other types?) */ | |
634 | 4507 if ((context == EXPAND_USER_DEFINED |
4508 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4509 new_len++; /* '\' becomes "\\" */ |
4510 } | |
4511 retval = alloc(new_len); | |
4512 if (retval != NULL) | |
4513 { | |
4514 retval[0] = '^'; | |
4515 j = 1; | |
4516 for (i = 0; i < len; i++, j++) | |
4517 { | |
4518 /* Skip backslash. But why? At least keep it for custom | |
4519 * expansion. */ | |
4520 if (context != EXPAND_USER_DEFINED | |
407 | 4521 && context != EXPAND_USER_LIST |
4522 && fname[i] == '\\' | |
4523 && ++i == len) | |
7 | 4524 break; |
4525 | |
4526 switch (fname[i]) | |
4527 { | |
4528 case '*': retval[j++] = '.'; | |
4529 break; | |
4530 case '~': retval[j++] = '\\'; | |
4531 break; | |
4532 case '?': retval[j] = '.'; | |
4533 continue; | |
4534 case '.': if (context == EXPAND_BUFFERS) | |
4535 retval[j++] = '\\'; | |
4536 break; | |
407 | 4537 case '\\': if (context == EXPAND_USER_DEFINED |
4538 || context == EXPAND_USER_LIST) | |
7 | 4539 retval[j++] = '\\'; |
4540 break; | |
4541 } | |
4542 retval[j] = fname[i]; | |
4543 } | |
4544 retval[j] = NUL; | |
4545 } | |
4546 } | |
4547 } | |
4548 else | |
4549 { | |
4550 retval = alloc(len + 4); | |
4551 if (retval != NULL) | |
4552 { | |
419 | 4553 vim_strncpy(retval, fname, len); |
7 | 4554 |
4555 /* | |
831 | 4556 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4557 * * would become **, which walks the whole tree. | |
7 | 4558 * ~ would be at the start of the file name, but not the tail. |
4559 * $ could be anywhere in the tail. | |
4560 * ` could be anywhere in the file name. | |
1484 | 4561 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4562 */ |
4563 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4564 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
|
4565 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4566 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4567 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4568 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4569 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4570 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4571 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4572 #endif |
7 | 4573 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4574 && !ends_in_star |
7 | 4575 && vim_strchr(tail, '$') == NULL |
4576 && vim_strchr(retval, '`') == NULL) | |
4577 retval[len++] = '*'; | |
1484 | 4578 else if (len > 0 && retval[len - 1] == '$') |
4579 --len; | |
7 | 4580 retval[len] = NUL; |
4581 } | |
4582 } | |
4583 return retval; | |
4584 } | |
4585 | |
4586 /* | |
4587 * Must parse the command line so far to work out what context we are in. | |
4588 * Completion can then be done based on that context. | |
4589 * This routine sets the variables: | |
4590 * xp->xp_pattern The start of the pattern to be expanded within | |
4591 * the command line (ends at the cursor). | |
4592 * xp->xp_context The type of thing to expand. Will be one of: | |
4593 * | |
4594 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4595 * the command line, like an unknown command. Caller | |
4596 * should beep. | |
4597 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4598 * a normal char, rather than for completion. eg | |
4599 * :s/^I/ | |
4600 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4601 * it. | |
4602 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4603 * EXPAND_FILES After command with XFILE set, or after setting | |
4604 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4605 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4606 * when we know only directories are of interest. eg | |
4607 * :set dir=^I | |
714 | 4608 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4609 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4610 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4611 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4612 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4613 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4614 * EXPAND_EVENTS Complete event names | |
4615 * EXPAND_SYNTAX Complete :syntax command arguments | |
4616 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4617 * EXPAND_AUGROUP Complete autocommand group names | |
4618 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4619 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4620 * eg :unmap a^I , :cunab x^I | |
4621 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4622 * eg :call sub^I | |
4623 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4624 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4625 * names in expressions, eg :while s^I | |
4626 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4627 * EXPAND_USER Complete user names |
7 | 4628 */ |
4629 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4630 set_expand_context(expand_T *xp) |
7 | 4631 { |
168 | 4632 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4633 if (ccline.cmdfirstc != ':' |
4634 #ifdef FEAT_EVAL | |
168 | 4635 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4636 && !ccline.input_fn |
7 | 4637 #endif |
4638 ) | |
4639 { | |
4640 xp->xp_context = EXPAND_NOTHING; | |
4641 return; | |
4642 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4643 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4644 } |
4645 | |
4646 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4647 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4648 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4649 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
|
4650 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
|
4651 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4652 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4653 { |
4654 int old_char = NUL; | |
4655 char_u *nextcomm; | |
4656 | |
4657 /* | |
4658 * Avoid a UMR warning from Purify, only save the character if it has been | |
4659 * written before. | |
4660 */ | |
4661 if (col < len) | |
4662 old_char = str[col]; | |
4663 str[col] = NUL; | |
4664 nextcomm = str; | |
168 | 4665 |
4666 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4667 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4668 { |
4669 # ifdef FEAT_CMDL_COMPL | |
168 | 4670 /* pass CMD_SIZE because there is no real command */ |
4671 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4672 # endif |
4673 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4674 else if (use_ccline && ccline.input_fn) |
531 | 4675 { |
4676 xp->xp_context = ccline.xp_context; | |
4677 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4678 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4679 xp->xp_arg = ccline.xp_arg; |
1322 | 4680 # endif |
531 | 4681 } |
168 | 4682 else |
4683 #endif | |
4684 while (nextcomm != NULL) | |
4685 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4686 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4687 /* 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
|
4688 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4689 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4690 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4691 |
7 | 4692 str[col] = old_char; |
4693 } | |
4694 | |
4695 /* | |
4696 * Expand the command line "str" from context "xp". | |
4697 * "xp" must have been set by set_cmd_context(). | |
4698 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4699 * starts. | |
4700 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4701 * cursor. | |
4702 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4703 * key that triggered expansion literally. | |
4704 * Returns EXPAND_OK otherwise. | |
4705 */ | |
4706 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4707 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4708 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4709 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
|
4710 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4711 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4712 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4713 { |
4714 char_u *file_str = NULL; | |
2652 | 4715 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4716 |
4717 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4718 { | |
4719 beep_flush(); | |
4720 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4721 } | |
4722 if (xp->xp_context == EXPAND_NOTHING) | |
4723 { | |
4724 /* Caller can use the character as a normal char instead */ | |
4725 return EXPAND_NOTHING; | |
4726 } | |
4727 | |
4728 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4729 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4730 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4731 if (file_str == NULL) |
4732 return EXPAND_UNSUCCESSFUL; | |
4733 | |
2652 | 4734 if (p_wic) |
4735 options += WILD_ICASE; | |
4736 | |
7 | 4737 /* find all files that match the description */ |
2652 | 4738 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4739 { |
4740 *matchcount = 0; | |
4741 *matches = NULL; | |
4742 } | |
4743 vim_free(file_str); | |
4744 | |
4745 return EXPAND_OK; | |
4746 } | |
4747 | |
4748 #ifdef FEAT_MULTI_LANG | |
4749 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4750 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4751 * 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
|
4752 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4753 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4754 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4755 |
4756 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4757 cleanup_help_tags(int num_file, char_u **file) |
7 | 4758 { |
4759 int i, j; | |
4760 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4761 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4762 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4763 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4764 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
|
4765 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4766 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4767 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4768 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4769 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4770 *p = NUL; |
7 | 4771 |
4772 for (i = 0; i < num_file; ++i) | |
4773 { | |
4774 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
|
4775 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4776 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4777 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4778 { |
4779 /* Sorting on priority means the same item in another language may | |
4780 * be anywhere. Search all items for a match up to the "@en". */ | |
4781 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
|
4782 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
|
4783 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 4784 break; |
4785 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4786 /* item only exists with @en, remove it */ |
7 | 4787 file[i][len] = NUL; |
4788 } | |
4789 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4790 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4791 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4792 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
|
4793 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4794 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4795 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4796 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4797 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
|
4798 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4799 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4800 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4801 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4802 } |
7 | 4803 } |
4804 #endif | |
4805 | |
4806 /* | |
4807 * Do the expansion based on xp->xp_context and "pat". | |
4808 */ | |
4809 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4810 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4811 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4812 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4813 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4814 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4815 int options) /* EW_ flags */ |
7 | 4816 { |
4817 #ifdef FEAT_CMDL_COMPL | |
4818 regmatch_T regmatch; | |
4819 #endif | |
4820 int ret; | |
4821 int flags; | |
4822 | |
4823 flags = EW_DIR; /* include directories */ | |
4824 if (options & WILD_LIST_NOTFOUND) | |
4825 flags |= EW_NOTFOUND; | |
4826 if (options & WILD_ADD_SLASH) | |
4827 flags |= EW_ADDSLASH; | |
4828 if (options & WILD_KEEP_ALL) | |
4829 flags |= EW_KEEPALL; | |
4830 if (options & WILD_SILENT) | |
4831 flags |= EW_SILENT; | |
6659 | 4832 if (options & WILD_ALLLINKS) |
4833 flags |= EW_ALLLINKS; | |
7 | 4834 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4835 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4836 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4837 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 4838 { |
4839 /* | |
4840 * Expand file or directory names. | |
4841 */ | |
4842 int free_pat = FALSE; | |
4843 int i; | |
4844 | |
4845 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
4846 * space */ | |
4847 if (xp->xp_backslash != XP_BS_NONE) | |
4848 { | |
4849 free_pat = TRUE; | |
4850 pat = vim_strsave(pat); | |
4851 for (i = 0; pat[i]; ++i) | |
4852 if (pat[i] == '\\') | |
4853 { | |
4854 if (xp->xp_backslash == XP_BS_THREE | |
4855 && pat[i + 1] == '\\' | |
4856 && pat[i + 2] == '\\' | |
4857 && pat[i + 3] == ' ') | |
1621 | 4858 STRMOVE(pat + i, pat + i + 3); |
7 | 4859 if (xp->xp_backslash == XP_BS_ONE |
4860 && pat[i + 1] == ' ') | |
1621 | 4861 STRMOVE(pat + i, pat + i + 1); |
7 | 4862 } |
4863 } | |
4864 | |
4865 if (xp->xp_context == EXPAND_FILES) | |
4866 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4867 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
|
4868 flags |= (EW_FILE | EW_PATH); |
7 | 4869 else |
4870 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 4871 if (options & WILD_ICASE) |
4872 flags |= EW_ICASE; | |
4873 | |
2016 | 4874 /* Expand wildcards, supporting %:h and the like. */ |
4875 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 4876 if (free_pat) |
4877 vim_free(pat); | |
4878 return ret; | |
4879 } | |
4880 | |
4881 *file = (char_u **)""; | |
4882 *num_file = 0; | |
4883 if (xp->xp_context == EXPAND_HELP) | |
4884 { | |
1696 | 4885 /* With an empty argument we would get all the help tags, which is |
4886 * very slow. Get matches for "help" instead. */ | |
4887 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
4888 num_file, file, FALSE) == OK) | |
7 | 4889 { |
4890 #ifdef FEAT_MULTI_LANG | |
4891 cleanup_help_tags(*num_file, *file); | |
4892 #endif | |
4893 return OK; | |
4894 } | |
4895 return FAIL; | |
4896 } | |
4897 | |
4898 #ifndef FEAT_CMDL_COMPL | |
4899 return FAIL; | |
4900 #else | |
716 | 4901 if (xp->xp_context == EXPAND_SHELLCMD) |
4902 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 4903 if (xp->xp_context == EXPAND_OLD_SETTING) |
4904 return ExpandOldSetting(num_file, file); | |
4905 if (xp->xp_context == EXPAND_BUFFERS) | |
4906 return ExpandBufnames(pat, num_file, file, options); | |
4907 if (xp->xp_context == EXPAND_TAGS | |
4908 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4909 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
4910 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 4911 { |
4912 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
4913 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
|
4914 directories); |
2929 | 4915 } |
7 | 4916 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 4917 { |
3106 | 4918 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
4919 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 4920 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4921 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 4922 { |
4923 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
4924 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 4925 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4926 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 4927 { |
4928 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
|
4929 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 4930 } |
407 | 4931 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
4932 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 4933 return ExpandUserList(xp, num_file, file); |
407 | 4934 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4935 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4936 return ExpandPackAddDir(pat, num_file, file); |
7 | 4937 |
4938 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
4939 if (regmatch.regprog == NULL) | |
4940 return FAIL; | |
4941 | |
4942 /* set ignore-case according to p_ic, p_scs and pat */ | |
4943 regmatch.rm_ic = ignorecase(pat); | |
4944 | |
4945 if (xp->xp_context == EXPAND_SETTINGS | |
4946 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
4947 ret = ExpandSettings(xp, ®match, num_file, file); | |
4948 else if (xp->xp_context == EXPAND_MAPPINGS) | |
4949 ret = ExpandMappings(®match, num_file, file); | |
4950 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
4951 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
4952 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
4953 # endif | |
4954 else | |
4955 { | |
4956 static struct expgen | |
4957 { | |
4958 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4959 char_u *((*func)(expand_T *, int)); |
7 | 4960 int ic; |
2849 | 4961 int escaped; |
7 | 4962 } tab[] = |
4963 { | |
2849 | 4964 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
4965 {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
|
4966 {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
|
4967 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 4968 #ifdef FEAT_CMDHIST |
4969 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
4970 #endif | |
7 | 4971 #ifdef FEAT_USR_CMDS |
2849 | 4972 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 4973 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 4974 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
4975 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
4976 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 4977 #endif |
4978 #ifdef FEAT_EVAL | |
2849 | 4979 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
4980 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
4981 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
4982 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 4983 #endif |
4984 #ifdef FEAT_MENU | |
2849 | 4985 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
4986 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 4987 #endif |
4988 #ifdef FEAT_SYN_HL | |
2849 | 4989 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
4990 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
4991 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
4992 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
4993 #endif |
2849 | 4994 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
4995 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
4996 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 4997 #ifdef FEAT_CSCOPE |
2849 | 4998 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 4999 #endif |
1868 | 5000 #ifdef FEAT_SIGNS |
2849 | 5001 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5002 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5003 #ifdef FEAT_PROFILE |
2849 | 5004 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5005 #endif |
7 | 5006 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5007 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5008 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5009 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5010 #endif | |
5011 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5012 {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
|
5013 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5014 }; |
5015 int i; | |
5016 | |
5017 /* | |
5018 * Find a context in the table and call the ExpandGeneric() with the | |
5019 * right function to do the expansion. | |
5020 */ | |
5021 ret = FAIL; | |
1880 | 5022 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5023 if (xp->xp_context == tab[i].context) |
5024 { | |
5025 if (tab[i].ic) | |
5026 regmatch.rm_ic = TRUE; | |
2849 | 5027 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5028 tab[i].func, tab[i].escaped); |
7 | 5029 break; |
5030 } | |
5031 } | |
5032 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5033 vim_regfree(regmatch.regprog); |
7 | 5034 |
5035 return ret; | |
5036 #endif /* FEAT_CMDL_COMPL */ | |
5037 } | |
5038 | |
5039 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5040 /* | |
5041 * Expand a list of names. | |
5042 * | |
5043 * Generic function for command line completion. It calls a function to | |
5044 * obtain strings, one by one. The strings are matched against a regexp | |
5045 * program. Matching strings are copied into an array, which is returned. | |
5046 * | |
5047 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5048 */ | |
5049 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5050 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5051 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5052 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5053 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5054 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5055 char_u *((*func)(expand_T *, int)), |
7 | 5056 /* 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
|
5057 int escaped) |
7 | 5058 { |
5059 int i; | |
5060 int count = 0; | |
480 | 5061 int round; |
7 | 5062 char_u *str; |
5063 | |
5064 /* do this loop twice: | |
480 | 5065 * round == 0: count the number of matching names |
5066 * round == 1: copy the matching names into allocated memory | |
7 | 5067 */ |
480 | 5068 for (round = 0; round <= 1; ++round) |
7 | 5069 { |
5070 for (i = 0; ; ++i) | |
5071 { | |
5072 str = (*func)(xp, i); | |
5073 if (str == NULL) /* end of list */ | |
5074 break; | |
5075 if (*str == NUL) /* skip empty strings */ | |
5076 continue; | |
5077 | |
5078 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5079 { | |
480 | 5080 if (round) |
7 | 5081 { |
2849 | 5082 if (escaped) |
5083 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5084 else | |
5085 str = vim_strsave(str); | |
7 | 5086 (*file)[count] = str; |
5087 #ifdef FEAT_MENU | |
5088 if (func == get_menu_names && str != NULL) | |
5089 { | |
5090 /* test for separator added by get_menu_names() */ | |
5091 str += STRLEN(str) - 1; | |
5092 if (*str == '\001') | |
5093 *str = '.'; | |
5094 } | |
5095 #endif | |
5096 } | |
5097 ++count; | |
5098 } | |
5099 } | |
480 | 5100 if (round == 0) |
7 | 5101 { |
5102 if (count == 0) | |
5103 return OK; | |
5104 *num_file = count; | |
5105 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5106 if (*file == NULL) | |
5107 { | |
5108 *file = (char_u **)""; | |
5109 return FAIL; | |
5110 } | |
5111 count = 0; | |
5112 } | |
5113 } | |
480 | 5114 |
828 | 5115 /* Sort the results. Keep menu's in the specified order. */ |
5116 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5117 { |
5118 if (xp->xp_context == EXPAND_EXPRESSION | |
5119 || xp->xp_context == EXPAND_FUNCTIONS | |
5120 || xp->xp_context == EXPAND_USER_FUNC) | |
5121 /* <SNR> functions should be sorted to the end. */ | |
5122 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5123 sort_func_compare); | |
5124 else | |
5125 sort_strings(*file, *num_file); | |
5126 } | |
480 | 5127 |
1322 | 5128 #ifdef FEAT_CMDL_COMPL |
5129 /* Reset the variables used for special highlight names expansion, so that | |
5130 * they don't show up when getting normal highlight names by ID. */ | |
5131 reset_expand_highlight(); | |
5132 #endif | |
5133 | |
7 | 5134 return OK; |
5135 } | |
5136 | |
716 | 5137 /* |
5138 * Complete a shell command. | |
5139 * Returns FAIL or OK; | |
5140 */ | |
5141 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5142 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5143 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
|
5144 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
|
5145 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
|
5146 int flagsarg) /* EW_ flags */ |
716 | 5147 { |
5148 char_u *pat; | |
5149 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5150 char_u *path = NULL; |
716 | 5151 int mustfree = FALSE; |
5152 garray_T ga; | |
5153 char_u *buf = alloc(MAXPATHL); | |
5154 size_t l; | |
5155 char_u *s, *e; | |
5156 int flags = flagsarg; | |
5157 int ret; | |
6695 | 5158 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5159 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5160 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5161 hash_T hash; |
716 | 5162 |
5163 if (buf == NULL) | |
5164 return FAIL; | |
5165 | |
5166 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5167 * space */ | |
5168 pat = vim_strsave(filepat); | |
5169 for (i = 0; pat[i]; ++i) | |
5170 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5171 STRMOVE(pat + i, pat + i + 1); |
716 | 5172 |
6695 | 5173 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5174 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5175 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
|
5176 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5177 path = (char_u *)"."; |
5178 else | |
2630 | 5179 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5180 /* 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
|
5181 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5182 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5183 if (path == NULL) |
5184 path = (char_u *)""; | |
5185 } | |
716 | 5186 |
5187 /* | |
5188 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5189 * collect them in "ga". When "." is not in $PATH also expand for the |
5190 * current directory, to find "subdir/cmd". | |
716 | 5191 */ |
5192 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
|
5193 hash_init(&found_ht); |
6695 | 5194 for (s = path; ; s = e) |
716 | 5195 { |
6695 | 5196 if (*s == NUL) |
5197 { | |
5198 if (did_curdir) | |
5199 break; | |
5200 /* Find directories in the current directory, path is empty. */ | |
5201 did_curdir = TRUE; | |
5202 } | |
5203 else if (*s == '.') | |
5204 did_curdir = TRUE; | |
5205 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5206 #if defined(MSWIN) |
716 | 5207 e = vim_strchr(s, ';'); |
5208 #else | |
5209 e = vim_strchr(s, ':'); | |
5210 #endif | |
5211 if (e == NULL) | |
5212 e = s + STRLEN(s); | |
5213 | |
5214 l = e - s; | |
5215 if (l > MAXPATHL - 5) | |
5216 break; | |
5217 vim_strncpy(buf, s, l); | |
5218 add_pathsep(buf); | |
5219 l = STRLEN(buf); | |
5220 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5221 | |
5222 /* Expand matches in one directory of $PATH. */ | |
5223 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5224 if (ret == OK) | |
5225 { | |
5226 if (ga_grow(&ga, *num_file) == FAIL) | |
5227 FreeWild(*num_file, *file); | |
5228 else | |
5229 { | |
5230 for (i = 0; i < *num_file; ++i) | |
5231 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5232 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5233 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5234 if (STRLEN(name) > l) |
716 | 5235 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5236 // 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
|
5237 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5238 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
|
5239 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5240 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5241 // 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
|
5242 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5243 ((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
|
5244 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
|
5245 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5246 } |
716 | 5247 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5248 vim_free(name); |
716 | 5249 } |
5250 vim_free(*file); | |
5251 } | |
5252 } | |
5253 if (*e != NUL) | |
5254 ++e; | |
5255 } | |
5256 *file = ga.ga_data; | |
5257 *num_file = ga.ga_len; | |
5258 | |
5259 vim_free(buf); | |
5260 vim_free(pat); | |
5261 if (mustfree) | |
5262 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5263 hash_clear(&found_ht); |
716 | 5264 return OK; |
5265 } | |
5266 | |
5267 | |
7 | 5268 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5269 static void * call_user_expand_func(void *(*user_expand_func)(char_u *, int, typval_T *, int), expand_T *xp, int *num_file, char_u ***file); |
410 | 5270 |
7 | 5271 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5272 * 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
|
5273 * return the result (either a string or a List). |
7 | 5274 */ |
407 | 5275 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5276 call_user_expand_func( |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5277 void *(*user_expand_func)(char_u *, int, typval_T *, int), |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5278 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5279 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5280 char_u ***file) |
7 | 5281 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5282 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
|
5283 typval_T args[4]; |
7 | 5284 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
|
5285 char_u *pat = NULL; |
407 | 5286 void *ret; |
13 | 5287 struct cmdline_info save_ccline; |
7 | 5288 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5289 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5290 return NULL; |
7 | 5291 *num_file = 0; |
5292 *file = NULL; | |
5293 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5294 if (ccline.cmdbuff != NULL) |
1518 | 5295 { |
5296 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5297 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5298 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5299 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5300 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
|
5301 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5302 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
|
5303 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
|
5304 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
|
5305 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
|
5306 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
|
5307 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
|
5308 args[3].v_type = VAR_UNKNOWN; |
7 | 5309 |
13 | 5310 /* Save the cmdline, we don't know what the function may do. */ |
5311 save_ccline = ccline; | |
5312 ccline.cmdbuff = NULL; | |
5313 ccline.cmdprompt = NULL; | |
7 | 5314 current_SID = xp->xp_scriptID; |
13 | 5315 |
407 | 5316 ret = user_expand_func(xp->xp_arg, 3, args, FALSE); |
13 | 5317 |
5318 ccline = save_ccline; | |
7 | 5319 current_SID = save_current_SID; |
1518 | 5320 if (ccline.cmdbuff != NULL) |
5321 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5322 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5323 vim_free(pat); |
407 | 5324 return ret; |
5325 } | |
5326 | |
5327 /* | |
5328 * Expand names with a function defined by the user. | |
5329 */ | |
5330 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5331 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5332 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5333 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5334 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5335 char_u ***file) |
407 | 5336 { |
5337 char_u *retstr; | |
5338 char_u *s; | |
5339 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
|
5340 int keep; |
407 | 5341 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
|
5342 int skip; |
407 | 5343 |
5344 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5345 if (retstr == NULL) | |
7 | 5346 return FAIL; |
5347 | |
5348 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5349 for (s = retstr; *s != NUL; s = e) |
7 | 5350 { |
5351 e = vim_strchr(s, '\n'); | |
5352 if (e == NULL) | |
5353 e = s + STRLEN(s); | |
5354 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
|
5355 *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
|
5356 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5357 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
|
5358 *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
|
5359 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5360 if (!skip) |
7 | 5361 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5362 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
|
5363 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5364 ((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
|
5365 ++ga.ga_len; |
7 | 5366 } |
5367 | |
5368 if (*e != NUL) | |
5369 ++e; | |
5370 } | |
407 | 5371 vim_free(retstr); |
5372 *file = ga.ga_data; | |
5373 *num_file = ga.ga_len; | |
5374 return OK; | |
5375 } | |
5376 | |
5377 /* | |
5378 * Expand names with a list returned by a function defined by the user. | |
5379 */ | |
5380 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5381 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5382 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5383 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5384 char_u ***file) |
407 | 5385 { |
5386 list_T *retlist; | |
5387 listitem_T *li; | |
5388 garray_T ga; | |
5389 | |
5390 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5391 if (retlist == NULL) | |
5392 return FAIL; | |
5393 | |
5394 ga_init2(&ga, (int)sizeof(char *), 3); | |
5395 /* Loop over the items in the list. */ | |
5396 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5397 { | |
1917 | 5398 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5399 continue; /* Skip non-string items and empty strings */ | |
407 | 5400 |
5401 if (ga_grow(&ga, 1) == FAIL) | |
5402 break; | |
5403 | |
5404 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5405 vim_strsave(li->li_tv.vval.v_string); |
407 | 5406 ++ga.ga_len; |
5407 } | |
5408 list_unref(retlist); | |
5409 | |
7 | 5410 *file = ga.ga_data; |
5411 *num_file = ga.ga_len; | |
5412 return OK; | |
5413 } | |
5414 #endif | |
5415 | |
5416 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5417 * 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
|
5418 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5419 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5420 * 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
|
5421 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5422 * 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
|
5423 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5424 * "dirnames" is an array with one or more directory names. |
7 | 5425 */ |
5426 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5427 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5428 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5429 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5430 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5431 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5432 char *dirnames[]) |
7 | 5433 { |
5434 char_u *s; | |
5435 char_u *e; | |
5873 | 5436 char_u *match; |
7 | 5437 garray_T ga; |
2929 | 5438 int i; |
5439 int pat_len; | |
7 | 5440 |
5441 *num_file = 0; | |
5442 *file = NULL; | |
2931 | 5443 pat_len = (int)STRLEN(pat); |
2929 | 5444 ga_init2(&ga, (int)sizeof(char *), 10); |
5445 | |
5446 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5447 { |
2929 | 5448 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5449 if (s == NULL) | |
5450 { | |
5451 ga_clear_strings(&ga); | |
5452 return FAIL; | |
5453 } | |
5454 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5455 globpath(p_rtp, s, &ga, 0); |
2929 | 5456 vim_free(s); |
5873 | 5457 } |
5458 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5459 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5460 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
|
5461 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5462 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
|
5463 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5464 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5465 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5466 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5467 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5468 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
|
5469 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5470 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5471 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5472 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5473 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5474 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5475 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
|
5476 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5477 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
|
5478 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5479 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5480 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5481 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5482 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5483 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
|
5484 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5485 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5486 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5487 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5488 |
5873 | 5489 for (i = 0; i < ga.ga_len; ++i) |
5490 { | |
5491 match = ((char_u **)ga.ga_data)[i]; | |
5492 s = match; | |
5493 e = s + STRLEN(s); | |
5494 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5495 { |
5873 | 5496 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5497 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5498 if (s < match || vim_ispathsep(*s)) |
5499 break; | |
5500 ++s; | |
5501 *e = NUL; | |
5502 mch_memmove(match, s, e - s + 1); | |
7 | 5503 } |
5504 } | |
5873 | 5505 |
2929 | 5506 if (ga.ga_len == 0) |
3628 | 5507 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5508 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5509 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5510 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5511 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5512 |
7 | 5513 *file = ga.ga_data; |
5514 *num_file = ga.ga_len; | |
5515 return OK; | |
5516 } | |
5517 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5518 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5519 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5520 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5521 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5522 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5523 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5524 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5525 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5526 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5527 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5528 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5529 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5530 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5531 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5532 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5533 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5534 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5535 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5536 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5537 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5538 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
|
5539 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5540 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5541 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5542 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5543 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5544 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5545 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5546 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
|
5547 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5548 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5549 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5550 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
|
5551 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5552 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
|
5553 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5554 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5555 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
|
5556 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5557 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5558 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5559 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5560 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5561 /* 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
|
5562 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5563 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5564 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5565 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5566 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5567 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5568 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5569 |
7 | 5570 #endif |
5571 | |
5572 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5573 /* | |
5574 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5575 * Adds the matches to "ga". Caller must init "ga". |
7 | 5576 */ |
5873 | 5577 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5578 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5579 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5580 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5581 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5582 int expand_options) |
7 | 5583 { |
5584 expand_T xpc; | |
5585 char_u *buf; | |
5586 int i; | |
5587 int num_p; | |
5588 char_u **p; | |
5589 | |
5590 buf = alloc(MAXPATHL); | |
5591 if (buf == NULL) | |
5873 | 5592 return; |
7 | 5593 |
632 | 5594 ExpandInit(&xpc); |
7 | 5595 xpc.xp_context = EXPAND_FILES; |
632 | 5596 |
7 | 5597 /* Loop over all entries in {path}. */ |
5598 while (*path != NUL) | |
5599 { | |
5600 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5601 copy_option_part(&path, buf, MAXPATHL, ","); | |
5602 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5603 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5604 # 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
|
5605 /* 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
|
5606 * 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
|
5607 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
|
5608 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5609 # else |
7 | 5610 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
|
5611 # endif |
7 | 5612 STRCAT(buf, file); |
1754 | 5613 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5614 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5615 { |
1754 | 5616 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5617 |
5618 if (ga_grow(ga, num_p) == OK) | |
7 | 5619 { |
5620 for (i = 0; i < num_p; ++i) | |
5621 { | |
5873 | 5622 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5623 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5624 ++ga->ga_len; |
7 | 5625 } |
5626 } | |
5873 | 5627 |
7 | 5628 FreeWild(num_p, p); |
5629 } | |
5630 } | |
5631 } | |
5632 | |
5633 vim_free(buf); | |
5634 } | |
5635 | |
5636 #endif | |
5637 | |
5638 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5639 | |
5640 /********************************* | |
5641 * Command line history stuff * | |
5642 *********************************/ | |
5643 | |
5644 /* | |
5645 * Translate a history character to the associated type number. | |
5646 */ | |
5647 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5648 hist_char2type(int c) |
7 | 5649 { |
5650 if (c == ':') | |
5651 return HIST_CMD; | |
5652 if (c == '=') | |
5653 return HIST_EXPR; | |
5654 if (c == '@') | |
5655 return HIST_INPUT; | |
5656 if (c == '>') | |
5657 return HIST_DEBUG; | |
5658 return HIST_SEARCH; /* must be '?' or '/' */ | |
5659 } | |
5660 | |
5661 /* | |
5662 * Table of history names. | |
5663 * These names are used in :history and various hist...() functions. | |
5664 * It is sufficient to give the significant prefix of a history name. | |
5665 */ | |
5666 | |
5667 static char *(history_names[]) = | |
5668 { | |
5669 "cmd", | |
5670 "search", | |
5671 "expr", | |
5672 "input", | |
5673 "debug", | |
5674 NULL | |
5675 }; | |
5676 | |
3503 | 5677 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5678 /* | |
5679 * Function given to ExpandGeneric() to obtain the possible first | |
5680 * arguments of the ":history command. | |
5681 */ | |
5682 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5683 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5684 { |
5685 static char_u compl[2] = { NUL, NUL }; | |
5686 char *short_names = ":=@>?/"; | |
3529 | 5687 int short_names_count = (int)STRLEN(short_names); |
3503 | 5688 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5689 | |
5690 if (idx < short_names_count) | |
5691 { | |
5692 compl[0] = (char_u)short_names[idx]; | |
5693 return compl; | |
5694 } | |
5695 if (idx < short_names_count + history_name_count) | |
5696 return (char_u *)history_names[idx - short_names_count]; | |
5697 if (idx == short_names_count + history_name_count) | |
5698 return (char_u *)"all"; | |
5699 return NULL; | |
5700 } | |
5701 #endif | |
5702 | |
7 | 5703 /* |
5704 * init_history() - Initialize the command line history. | |
5705 * Also used to re-allocate the history when the size changes. | |
5706 */ | |
356 | 5707 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5708 init_history(void) |
7 | 5709 { |
5710 int newlen; /* new length of history table */ | |
5711 histentry_T *temp; | |
5712 int i; | |
5713 int j; | |
5714 int type; | |
5715 | |
5716 /* | |
5717 * If size of history table changed, reallocate it | |
5718 */ | |
5719 newlen = (int)p_hi; | |
5720 if (newlen != hislen) /* history length changed */ | |
5721 { | |
5722 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5723 { | |
5724 if (newlen) | |
5725 { | |
5726 temp = (histentry_T *)lalloc( | |
5727 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5728 if (temp == NULL) /* out of memory! */ | |
5729 { | |
5730 if (type == 0) /* first one: just keep the old length */ | |
5731 { | |
5732 newlen = hislen; | |
5733 break; | |
5734 } | |
5735 /* Already changed one table, now we can only have zero | |
5736 * length for all tables. */ | |
5737 newlen = 0; | |
5738 type = -1; | |
5739 continue; | |
5740 } | |
5741 } | |
5742 else | |
5743 temp = NULL; | |
5744 if (newlen == 0 || temp != NULL) | |
5745 { | |
5746 if (hisidx[type] < 0) /* there are no entries yet */ | |
5747 { | |
5748 for (i = 0; i < newlen; ++i) | |
4258 | 5749 clear_hist_entry(&temp[i]); |
7 | 5750 } |
5751 else if (newlen > hislen) /* array becomes bigger */ | |
5752 { | |
5753 for (i = 0; i <= hisidx[type]; ++i) | |
5754 temp[i] = history[type][i]; | |
5755 j = i; | |
5756 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5757 clear_hist_entry(&temp[i]); |
7 | 5758 for ( ; j < hislen; ++i, ++j) |
5759 temp[i] = history[type][j]; | |
5760 } | |
5761 else /* array becomes smaller or 0 */ | |
5762 { | |
5763 j = hisidx[type]; | |
5764 for (i = newlen - 1; ; --i) | |
5765 { | |
5766 if (i >= 0) /* copy newest entries */ | |
5767 temp[i] = history[type][j]; | |
5768 else /* remove older entries */ | |
5769 vim_free(history[type][j].hisstr); | |
5770 if (--j < 0) | |
5771 j = hislen - 1; | |
5772 if (j == hisidx[type]) | |
5773 break; | |
5774 } | |
5775 hisidx[type] = newlen - 1; | |
5776 } | |
5777 vim_free(history[type]); | |
5778 history[type] = temp; | |
5779 } | |
5780 } | |
5781 hislen = newlen; | |
5782 } | |
5783 } | |
5784 | |
4258 | 5785 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5786 clear_hist_entry(histentry_T *hisptr) |
4258 | 5787 { |
5788 hisptr->hisnum = 0; | |
5789 hisptr->viminfo = FALSE; | |
5790 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
5791 hisptr->time_set = 0; |
4258 | 5792 } |
5793 | |
7 | 5794 /* |
5795 * Check if command line 'str' is already in history. | |
5796 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
5797 */ | |
5798 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5799 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5800 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5801 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5802 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
|
5803 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5804 int writing) /* ignore entries read from viminfo */ |
7 | 5805 { |
5806 int i; | |
5807 int last_i = -1; | |
2986 | 5808 char_u *p; |
7 | 5809 |
5810 if (hisidx[type] < 0) | |
5811 return FALSE; | |
5812 i = hisidx[type]; | |
5813 do | |
5814 { | |
5815 if (history[type][i].hisstr == NULL) | |
5816 return FALSE; | |
2986 | 5817 |
5818 /* For search history, check that the separator character matches as | |
5819 * well. */ | |
5820 p = history[type][i].hisstr; | |
5821 if (STRCMP(str, p) == 0 | |
4285 | 5822 && !(writing && history[type][i].viminfo) |
2986 | 5823 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 5824 { |
5825 if (!move_to_front) | |
5826 return TRUE; | |
5827 last_i = i; | |
5828 break; | |
5829 } | |
5830 if (--i < 0) | |
5831 i = hislen - 1; | |
5832 } while (i != hisidx[type]); | |
5833 | |
5834 if (last_i >= 0) | |
5835 { | |
5836 str = history[type][i].hisstr; | |
5837 while (i != hisidx[type]) | |
5838 { | |
5839 if (++i >= hislen) | |
5840 i = 0; | |
5841 history[type][last_i] = history[type][i]; | |
5842 last_i = i; | |
5843 } | |
4258 | 5844 history[type][i].hisnum = ++hisnum[type]; |
5845 history[type][i].viminfo = FALSE; | |
7 | 5846 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
5847 history[type][i].time_set = vim_time(); |
7 | 5848 return TRUE; |
5849 } | |
5850 return FALSE; | |
5851 } | |
5852 | |
5853 /* | |
5854 * Convert history name (from table above) to its HIST_ equivalent. | |
5855 * When "name" is empty, return "cmd" history. | |
5856 * Returns -1 for unknown history name. | |
5857 */ | |
5858 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5859 get_histtype(char_u *name) |
7 | 5860 { |
5861 int i; | |
5862 int len = (int)STRLEN(name); | |
5863 | |
5864 /* No argument: use current history. */ | |
5865 if (len == 0) | |
5866 return hist_char2type(ccline.cmdfirstc); | |
5867 | |
5868 for (i = 0; history_names[i] != NULL; ++i) | |
5869 if (STRNICMP(name, history_names[i], len) == 0) | |
5870 return i; | |
5871 | |
5872 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
5873 return hist_char2type(name[0]); | |
5874 | |
5875 return -1; | |
5876 } | |
5877 | |
5878 static int last_maptick = -1; /* last seen maptick */ | |
5879 | |
5880 /* | |
5881 * Add the given string to the given history. If the string is already in the | |
5882 * history then it is moved to the front. "histype" may be one of he HIST_ | |
5883 * values. | |
5884 */ | |
5885 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5886 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5887 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5888 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5889 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
|
5890 int sep) /* separator character used (search hist) */ |
7 | 5891 { |
5892 histentry_T *hisptr; | |
5893 int len; | |
5894 | |
5895 if (hislen == 0) /* no history */ | |
5896 return; | |
5897 | |
5467 | 5898 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
5899 return; | |
5900 | |
7 | 5901 /* |
5902 * Searches inside the same mapping overwrite each other, so that only | |
5903 * the last line is kept. Be careful not to remove a line that was moved | |
5904 * down, only lines that were added. | |
5905 */ | |
5906 if (histype == HIST_SEARCH && in_map) | |
5907 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
5908 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 5909 { |
5910 /* Current line is from the same mapping, remove it */ | |
5911 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
5912 vim_free(hisptr->hisstr); | |
4258 | 5913 clear_hist_entry(hisptr); |
7 | 5914 --hisnum[histype]; |
5915 if (--hisidx[HIST_SEARCH] < 0) | |
5916 hisidx[HIST_SEARCH] = hislen - 1; | |
5917 } | |
5918 last_maptick = -1; | |
5919 } | |
4285 | 5920 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 5921 { |
5922 if (++hisidx[histype] == hislen) | |
5923 hisidx[histype] = 0; | |
5924 hisptr = &history[histype][hisidx[histype]]; | |
5925 vim_free(hisptr->hisstr); | |
5926 | |
5927 /* Store the separator after the NUL of the string. */ | |
835 | 5928 len = (int)STRLEN(new_entry); |
7 | 5929 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
5930 if (hisptr->hisstr != NULL) | |
5931 hisptr->hisstr[len + 1] = sep; | |
5932 | |
5933 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 5934 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
5935 hisptr->time_set = vim_time(); |
7 | 5936 if (histype == HIST_SEARCH && in_map) |
5937 last_maptick = maptick; | |
5938 } | |
5939 } | |
5940 | |
5941 #if defined(FEAT_EVAL) || defined(PROTO) | |
5942 | |
5943 /* | |
5944 * Get identifier of newest history entry. | |
5945 * "histype" may be one of the HIST_ values. | |
5946 */ | |
5947 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5948 get_history_idx(int histype) |
7 | 5949 { |
5950 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
5951 || hisidx[histype] < 0) | |
5952 return -1; | |
5953 | |
5954 return history[histype][hisidx[histype]].hisnum; | |
5955 } | |
5956 | |
531 | 5957 /* |
7 | 5958 * Calculate history index from a number: |
5959 * num > 0: seen as identifying number of a history entry | |
5960 * num < 0: relative position in history wrt newest entry | |
5961 * "histype" may be one of the HIST_ values. | |
5962 */ | |
5963 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5964 calc_hist_idx(int histype, int num) |
7 | 5965 { |
5966 int i; | |
5967 histentry_T *hist; | |
5968 int wrapped = FALSE; | |
5969 | |
5970 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
5971 || (i = hisidx[histype]) < 0 || num == 0) | |
5972 return -1; | |
5973 | |
5974 hist = history[histype]; | |
5975 if (num > 0) | |
5976 { | |
5977 while (hist[i].hisnum > num) | |
5978 if (--i < 0) | |
5979 { | |
5980 if (wrapped) | |
5981 break; | |
5982 i += hislen; | |
5983 wrapped = TRUE; | |
5984 } | |
5985 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
5986 return i; | |
5987 } | |
5988 else if (-num <= hislen) | |
5989 { | |
5990 i += num + 1; | |
5991 if (i < 0) | |
5992 i += hislen; | |
5993 if (hist[i].hisstr != NULL) | |
5994 return i; | |
5995 } | |
5996 return -1; | |
5997 } | |
5998 | |
5999 /* | |
6000 * Get a history entry by its index. | |
6001 * "histype" may be one of the HIST_ values. | |
6002 */ | |
6003 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6004 get_history_entry(int histype, int idx) |
7 | 6005 { |
6006 idx = calc_hist_idx(histype, idx); | |
6007 if (idx >= 0) | |
6008 return history[histype][idx].hisstr; | |
6009 else | |
6010 return (char_u *)""; | |
6011 } | |
6012 | |
6013 /* | |
6014 * Clear all entries of a history. | |
6015 * "histype" may be one of the HIST_ values. | |
6016 */ | |
6017 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6018 clr_history(int histype) |
7 | 6019 { |
6020 int i; | |
6021 histentry_T *hisptr; | |
6022 | |
6023 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6024 { | |
6025 hisptr = history[histype]; | |
6026 for (i = hislen; i--;) | |
6027 { | |
6028 vim_free(hisptr->hisstr); | |
4258 | 6029 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6030 hisptr++; |
7 | 6031 } |
6032 hisidx[histype] = -1; /* mark history as cleared */ | |
6033 hisnum[histype] = 0; /* reset identifier counter */ | |
6034 return OK; | |
6035 } | |
6036 return FAIL; | |
6037 } | |
6038 | |
6039 /* | |
6040 * Remove all entries matching {str} from a history. | |
6041 * "histype" may be one of the HIST_ values. | |
6042 */ | |
6043 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6044 del_history_entry(int histype, char_u *str) |
7 | 6045 { |
6046 regmatch_T regmatch; | |
6047 histentry_T *hisptr; | |
6048 int idx; | |
6049 int i; | |
6050 int last; | |
6051 int found = FALSE; | |
6052 | |
6053 regmatch.regprog = NULL; | |
6054 regmatch.rm_ic = FALSE; /* always match case */ | |
6055 if (hislen != 0 | |
6056 && histype >= 0 | |
6057 && histype < HIST_COUNT | |
6058 && *str != NUL | |
6059 && (idx = hisidx[histype]) >= 0 | |
6060 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6061 != NULL) | |
6062 { | |
6063 i = last = idx; | |
6064 do | |
6065 { | |
6066 hisptr = &history[histype][i]; | |
6067 if (hisptr->hisstr == NULL) | |
6068 break; | |
6069 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6070 { | |
6071 found = TRUE; | |
6072 vim_free(hisptr->hisstr); | |
4258 | 6073 clear_hist_entry(hisptr); |
7 | 6074 } |
6075 else | |
6076 { | |
6077 if (i != last) | |
6078 { | |
6079 history[histype][last] = *hisptr; | |
4258 | 6080 clear_hist_entry(hisptr); |
7 | 6081 } |
6082 if (--last < 0) | |
6083 last += hislen; | |
6084 } | |
6085 if (--i < 0) | |
6086 i += hislen; | |
6087 } while (i != idx); | |
6088 if (history[histype][idx].hisstr == NULL) | |
6089 hisidx[histype] = -1; | |
6090 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6091 vim_regfree(regmatch.regprog); |
7 | 6092 return found; |
6093 } | |
6094 | |
6095 /* | |
6096 * Remove an indexed entry from a history. | |
6097 * "histype" may be one of the HIST_ values. | |
6098 */ | |
6099 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6100 del_history_idx(int histype, int idx) |
7 | 6101 { |
6102 int i, j; | |
6103 | |
6104 i = calc_hist_idx(histype, idx); | |
6105 if (i < 0) | |
6106 return FALSE; | |
6107 idx = hisidx[histype]; | |
6108 vim_free(history[histype][i].hisstr); | |
6109 | |
6110 /* When deleting the last added search string in a mapping, reset | |
6111 * last_maptick, so that the last added search string isn't deleted again. | |
6112 */ | |
6113 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6114 last_maptick = -1; | |
6115 | |
6116 while (i != idx) | |
6117 { | |
6118 j = (i + 1) % hislen; | |
6119 history[histype][i] = history[histype][j]; | |
6120 i = j; | |
6121 } | |
4258 | 6122 clear_hist_entry(&history[histype][i]); |
7 | 6123 if (--i < 0) |
6124 i += hislen; | |
6125 hisidx[histype] = i; | |
6126 return TRUE; | |
6127 } | |
6128 | |
6129 #endif /* FEAT_EVAL */ | |
6130 | |
6131 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6132 /* | |
6133 * Very specific function to remove the value in ":set key=val" from the | |
6134 * history. | |
6135 */ | |
6136 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6137 remove_key_from_history(void) |
7 | 6138 { |
6139 char_u *p; | |
6140 int i; | |
6141 | |
6142 i = hisidx[HIST_CMD]; | |
6143 if (i < 0) | |
6144 return; | |
6145 p = history[HIST_CMD][i].hisstr; | |
6146 if (p != NULL) | |
6147 for ( ; *p; ++p) | |
6148 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6149 { | |
6150 p = vim_strchr(p + 3, '='); | |
6151 if (p == NULL) | |
6152 break; | |
6153 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6154 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6155 if (p[i] == '\\' && p[i + 1]) |
6156 ++i; | |
1621 | 6157 STRMOVE(p, p + i); |
7 | 6158 --p; |
6159 } | |
6160 } | |
6161 #endif | |
6162 | |
6163 #endif /* FEAT_CMDHIST */ | |
6164 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6165 #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
|
6166 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6167 * 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
|
6168 * 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
|
6169 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6170 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6171 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6172 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6173 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6174 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6175 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6176 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6177 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
|
6178 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6179 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6180 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6181 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6182 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6183 #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
|
6184 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6185 * 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
|
6186 * 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
|
6187 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6188 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6189 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6190 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6191 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6192 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
|
6193 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6194 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6195 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6196 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
|
6197 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6198 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6199 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6200 * 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
|
6201 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6202 * 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
|
6203 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6204 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6205 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6206 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6207 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6208 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
|
6209 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6210 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6211 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6212 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6213 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6214 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6215 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6216 * 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
|
6217 * 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
|
6218 * 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
|
6219 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6220 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6221 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6222 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6223 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6224 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
|
6225 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6226 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6227 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6228 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6229 /* 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
|
6230 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6231 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6232 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6233 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6234 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6235 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6236 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6237 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6238 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6239 #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
|
6240 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6241 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6242 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6243 * 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
|
6244 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6245 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6246 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6247 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6248 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6249 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
|
6250 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6251 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6252 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6253 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6254 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6255 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6256 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6257 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6258 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6259 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6260 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6261 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6262 |
7 | 6263 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6264 /* | |
6265 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6266 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6267 * Returns OK if parsed successfully, otherwise FAIL. | |
6268 */ | |
6269 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6270 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6271 { |
6272 int len; | |
6273 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6274 varnumber_T num; |
7 | 6275 |
6276 *str = skipwhite(*str); | |
6277 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6278 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6279 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6280 *str += len; |
6281 *num1 = (int)num; | |
6282 first = TRUE; | |
6283 } | |
6284 *str = skipwhite(*str); | |
6285 if (**str == ',') /* parse "to" part of range */ | |
6286 { | |
6287 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6288 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6289 if (len > 0) |
6290 { | |
6291 *num2 = (int)num; | |
6292 *str = skipwhite(*str + len); | |
6293 } | |
6294 else if (!first) /* no number given at all */ | |
6295 return FAIL; | |
6296 } | |
6297 else if (first) /* only one number given */ | |
6298 *num2 = *num1; | |
6299 return OK; | |
6300 } | |
6301 #endif | |
6302 | |
6303 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6304 /* | |
6305 * :history command - print a history | |
6306 */ | |
6307 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6308 ex_history(exarg_T *eap) |
7 | 6309 { |
6310 histentry_T *hist; | |
6311 int histype1 = HIST_CMD; | |
6312 int histype2 = HIST_CMD; | |
6313 int hisidx1 = 1; | |
6314 int hisidx2 = -1; | |
6315 int idx; | |
6316 int i, j, k; | |
6317 char_u *end; | |
6318 char_u *arg = eap->arg; | |
6319 | |
6320 if (hislen == 0) | |
6321 { | |
6322 MSG(_("'history' option is zero")); | |
6323 return; | |
6324 } | |
6325 | |
6326 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6327 { | |
6328 end = arg; | |
6329 while (ASCII_ISALPHA(*end) | |
6330 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6331 end++; | |
6332 i = *end; | |
6333 *end = NUL; | |
6334 histype1 = get_histtype(arg); | |
6335 if (histype1 == -1) | |
6336 { | |
1853 | 6337 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6338 { |
6339 histype1 = 0; | |
6340 histype2 = HIST_COUNT-1; | |
6341 } | |
6342 else | |
6343 { | |
6344 *end = i; | |
6345 EMSG(_(e_trailing)); | |
6346 return; | |
6347 } | |
6348 } | |
6349 else | |
6350 histype2 = histype1; | |
6351 *end = i; | |
6352 } | |
6353 else | |
6354 end = arg; | |
6355 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6356 { | |
6357 EMSG(_(e_trailing)); | |
6358 return; | |
6359 } | |
6360 | |
6361 for (; !got_int && histype1 <= histype2; ++histype1) | |
6362 { | |
6363 STRCPY(IObuff, "\n # "); | |
6364 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6365 MSG_PUTS_TITLE(IObuff); | |
6366 idx = hisidx[histype1]; | |
6367 hist = history[histype1]; | |
6368 j = hisidx1; | |
6369 k = hisidx2; | |
6370 if (j < 0) | |
6371 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6372 if (k < 0) | |
6373 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6374 if (idx >= 0 && j <= k) | |
6375 for (i = idx + 1; !got_int; ++i) | |
6376 { | |
6377 if (i == hislen) | |
6378 i = 0; | |
6379 if (hist[i].hisstr != NULL | |
6380 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6381 { | |
6382 msg_putchar('\n'); | |
6383 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6384 hist[i].hisnum); | |
6385 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6386 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6387 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6388 else |
6389 STRCAT(IObuff, hist[i].hisstr); | |
6390 msg_outtrans(IObuff); | |
6391 out_flush(); | |
6392 } | |
6393 if (i == idx) | |
6394 break; | |
6395 } | |
6396 } | |
6397 } | |
6398 #endif | |
6399 | |
6400 #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
|
6401 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6402 * 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
|
6403 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6404 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
|
6405 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6406 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
|
6407 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6408 static int viminfo_add_at_front = FALSE; |
6409 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6410 static int hist_type2char(int type, int use_question); |
7 | 6411 |
6412 /* | |
6413 * Translate a history type number to the associated character. | |
6414 */ | |
6415 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6416 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6417 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6418 int use_question) /* use '?' instead of '/' */ |
7 | 6419 { |
6420 if (type == HIST_CMD) | |
6421 return ':'; | |
6422 if (type == HIST_SEARCH) | |
6423 { | |
6424 if (use_question) | |
6425 return '?'; | |
6426 else | |
6427 return '/'; | |
6428 } | |
6429 if (type == HIST_EXPR) | |
6430 return '='; | |
6431 return '@'; | |
6432 } | |
6433 | |
6434 /* | |
6435 * Prepare for reading the history from the viminfo file. | |
6436 * This allocates history arrays to store the read history lines. | |
6437 */ | |
6438 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6439 prepare_viminfo_history(int asklen, int writing) |
7 | 6440 { |
6441 int i; | |
6442 int num; | |
6443 int type; | |
6444 int len; | |
6445 | |
6446 init_history(); | |
4285 | 6447 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6448 if (asklen > hislen) |
6449 asklen = hislen; | |
6450 | |
6451 for (type = 0; type < HIST_COUNT; ++type) | |
6452 { | |
4258 | 6453 /* Count the number of empty spaces in the history list. Entries read |
6454 * from viminfo previously are also considered empty. If there are | |
6455 * more spaces available than we request, then fill them up. */ | |
7 | 6456 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6457 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6458 num++; |
6459 len = asklen; | |
6460 if (num > len) | |
6461 len = num; | |
6462 if (len <= 0) | |
6463 viminfo_history[type] = NULL; | |
6464 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6465 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6466 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6467 if (viminfo_history[type] == NULL) |
6468 len = 0; | |
6469 viminfo_hislen[type] = len; | |
6470 viminfo_hisidx[type] = 0; | |
6471 } | |
6472 } | |
6473 | |
6474 /* | |
6475 * Accept a line from the viminfo, store it in the history array when it's | |
6476 * new. | |
6477 */ | |
6478 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6479 read_viminfo_history(vir_T *virp, int writing) |
7 | 6480 { |
6481 int type; | |
6482 long_u len; | |
6483 char_u *val; | |
6484 char_u *p; | |
6485 | |
6486 type = hist_char2type(virp->vir_line[0]); | |
6487 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6488 { | |
6489 val = viminfo_readstring(virp, 1, TRUE); | |
6490 if (val != NULL && *val != NUL) | |
6491 { | |
3316 | 6492 int sep = (*val == ' ' ? NUL : *val); |
6493 | |
7 | 6494 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6495 viminfo_add_at_front, sep, writing)) |
7 | 6496 { |
6497 /* Need to re-allocate to append the separator byte. */ | |
6498 len = STRLEN(val); | |
6499 p = lalloc(len + 2, TRUE); | |
6500 if (p != NULL) | |
6501 { | |
6502 if (type == HIST_SEARCH) | |
6503 { | |
6504 /* Search entry: Move the separator from the first | |
6505 * column to after the NUL. */ | |
6506 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6507 p[len] = sep; |
7 | 6508 } |
6509 else | |
6510 { | |
6511 /* Not a search entry: No separator in the viminfo | |
6512 * file, add a NUL separator. */ | |
6513 mch_memmove(p, val, (size_t)len + 1); | |
6514 p[len + 1] = NUL; | |
6515 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6516 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
|
6517 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
|
6518 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
|
6519 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
|
6520 viminfo_hisidx[type]++; |
7 | 6521 } |
6522 } | |
6523 } | |
6524 vim_free(val); | |
6525 } | |
6526 return viminfo_readline(virp); | |
6527 } | |
6528 | |
4285 | 6529 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6530 * 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
|
6531 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6532 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6533 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6534 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6535 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6536 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6537 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6538 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6539 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6540 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6541 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6542 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
|
6543 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6544 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6545 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6546 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6547 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6548 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6549 || (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
|
6550 || 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
|
6551 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6552 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6553 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6554 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6555 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6556 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
|
6557 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6558 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6559 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6560 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6561 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
|
6562 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6563 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6564 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6565 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6566 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
|
6567 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6568 /* 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
|
6569 * 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
|
6570 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
|
6571 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6572 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6573 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6574 && (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
|
6575 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6576 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6577 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6578 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6579 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6580 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6581 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6582 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6583 /* 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
|
6584 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6585 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6586 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6587 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6588 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6589 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6590 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6591 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
|
6592 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6593 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6594 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
|
6595 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6596 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6597 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
|
6598 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6599 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
|
6600 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6601 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6602 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6603 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6604 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6605 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6606 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6607 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6608 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6609 * 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
|
6610 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6611 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6612 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6613 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6614 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6615 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6616 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6617 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6618 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6619 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6620 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6621 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6622 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6623 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6624 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6625 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6626 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6627 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6628 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6629 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6630 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6631 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6632 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6633 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6634 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6635 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6636 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6637 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6638 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6639 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
|
6640 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6641 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6642 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
|
6643 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6644 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
|
6645 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6646 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6647 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6648 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6649 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6650 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
|
6651 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6652 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6653 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6654 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6655 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6656 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6657 #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
|
6658 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6659 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6660 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6661 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6662 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
|
6663 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6664 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6665 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6666 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6667 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
|
6668 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
|
6669 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6670 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6671 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6672 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6673 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6674 * 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
|
6675 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6676 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6677 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6678 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6679 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6680 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6681 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6682 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6683 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6684 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6685 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6686 /* 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
|
6687 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6688 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
|
6689 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
|
6690 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
|
6691 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6692 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6693 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6694 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6695 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6696 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
|
6697 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
|
6698 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6699 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6700 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6701 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6702 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6703 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6704 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
|
6705 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6706 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6707 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6708 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6709 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6710 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6711 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6712 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6713 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6714 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6715 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6716 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6717 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6718 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6719 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
|
6720 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6721 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6722 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
|
6723 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
|
6724 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6725 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6726 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6727 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6728 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6729 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6730 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6731 /* |
4285 | 6732 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6733 */ | |
7 | 6734 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6735 finish_viminfo_history(vir_T *virp) |
7 | 6736 { |
6737 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6738 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6739 |
6740 for (type = 0; type < HIST_COUNT; ++type) | |
6741 { | |
6742 if (history[type] == NULL) | |
4283 | 6743 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6744 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6745 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6746 merge_history(type); |
7 | 6747 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6748 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6749 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6750 VIM_CLEAR(viminfo_history[type]); |
4327 | 6751 viminfo_hisidx[type] = 0; |
7 | 6752 } |
6753 } | |
6754 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6755 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6756 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6757 * 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
|
6758 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6759 * 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
|
6760 */ |
7 | 6761 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 write_viminfo_history(FILE *fp, int merge) |
7 | 6763 { |
6764 int i; | |
6765 int type; | |
6766 int num_saved; | |
4283 | 6767 int round; |
7 | 6768 |
6769 init_history(); | |
6770 if (hislen == 0) | |
6771 return; | |
6772 for (type = 0; type < HIST_COUNT; ++type) | |
6773 { | |
6774 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6775 if (num_saved == 0) | |
6776 continue; | |
6777 if (num_saved < 0) /* Use default */ | |
6778 num_saved = hislen; | |
6779 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
6780 type == HIST_CMD ? _("Command Line") : | |
6781 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6782 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 _("Debug Line")); |
7 | 6785 if (num_saved > hislen) |
6786 num_saved = hislen; | |
4283 | 6787 |
6788 /* | |
6789 * Merge typed and viminfo history: | |
6790 * round 1: history of typed commands. | |
6791 * round 2: history from recently read viminfo. | |
6792 */ | |
6793 for (round = 1; round <= 2; ++round) | |
6794 { | |
4307 | 6795 if (round == 1) |
6796 /* start at newest entry, somewhere in the list */ | |
6797 i = hisidx[type]; | |
6798 else if (viminfo_hisidx[type] > 0) | |
6799 /* start at newest entry, first in the list */ | |
6800 i = 0; | |
6801 else | |
6802 /* empty list */ | |
6803 i = -1; | |
4283 | 6804 if (i >= 0) |
6805 while (num_saved > 0 | |
6806 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 6807 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6813 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6815 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6816 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6817 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6819 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6820 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6821 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6823 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6824 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6825 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6826 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6827 || !history[type][i].viminfo)) |
7 | 6828 { |
4283 | 6829 --num_saved; |
6830 fputc(hist_type2char(type, TRUE), fp); | |
6831 /* For the search history: put the separator in the | |
6832 * second column; use a space if there isn't one. */ | |
6833 if (type == HIST_SEARCH) | |
6834 { | |
6835 c = p[STRLEN(p) + 1]; | |
6836 putc(c == NUL ? ' ' : c, fp); | |
6837 } | |
6838 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6841 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6842 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6843 /* 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
|
6844 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6845 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6846 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6847 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6848 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6849 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
|
6850 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6851 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6852 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6853 } |
7 | 6854 } |
4283 | 6855 if (round == 1) |
6856 { | |
6857 /* Decrement index, loop around and stop when back at | |
6858 * the start. */ | |
6859 if (--i < 0) | |
6860 i = hislen - 1; | |
6861 if (i == hisidx[type]) | |
6862 break; | |
6863 } | |
6864 else | |
6865 { | |
6866 /* Increment index. Stop at the end in the while. */ | |
6867 ++i; | |
6868 } | |
7 | 6869 } |
4283 | 6870 } |
4285 | 6871 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 6872 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6873 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
|
6874 VIM_CLEAR(viminfo_history[type]); |
4311 | 6875 viminfo_hisidx[type] = 0; |
7 | 6876 } |
6877 } | |
6878 #endif /* FEAT_VIMINFO */ | |
6879 | |
6880 #if defined(FEAT_FKMAP) || defined(PROTO) | |
6881 /* | |
6882 * Write a character at the current cursor+offset position. | |
6883 * It is directly written into the command buffer block. | |
6884 */ | |
6885 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6886 cmd_pchar(int c, int offset) |
7 | 6887 { |
6888 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
6889 { | |
6890 EMSG(_("E198: cmd_pchar beyond the command length")); | |
6891 return; | |
6892 } | |
6893 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
6894 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
6895 } | |
6896 | |
6897 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6898 cmd_gchar(int offset) |
7 | 6899 { |
6900 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
6901 { | |
6902 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
6903 return NUL; | |
6904 } | |
6905 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
6906 } | |
6907 #endif | |
6908 | |
6909 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
6910 /* | |
6911 * Open a window on the current command line and history. Allow editing in | |
6912 * the window. Returns when the window is closed. | |
6913 * Returns: | |
6914 * CR if the command is to be executed | |
6915 * Ctrl_C if it is to be abandoned | |
6916 * K_IGNORE if editing continues | |
6917 */ | |
6918 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
|
6919 open_cmdwin(void) |
7 | 6920 { |
6921 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6922 bufref_T old_curbuf; |
7 | 6923 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6924 bufref_T bufref; |
7 | 6925 win_T *wp; |
6926 int i; | |
6927 linenr_T lnum; | |
6928 int histtype; | |
6929 garray_T winsizes; | |
6930 int save_restart_edit = restart_edit; | |
6931 int save_State = State; | |
6932 int save_exmode = exmode_active; | |
510 | 6933 #ifdef FEAT_RIGHTLEFT |
6934 int save_cmdmsg_rl = cmdmsg_rl; | |
6935 #endif | |
6145 | 6936 #ifdef FEAT_FOLDING |
6937 int save_KeyTyped; | |
6938 #endif | |
7 | 6939 |
6940 /* Can't do this recursively. Can't do it when typing a password. */ | |
6941 if (cmdwin_type != 0 | |
6942 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
6943 || cmdline_star > 0 | |
6944 # endif | |
6945 ) | |
6946 { | |
6947 beep_flush(); | |
6948 return K_IGNORE; | |
6949 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6950 set_bufref(&old_curbuf, curbuf); |
7 | 6951 |
6952 /* Save current window sizes. */ | |
6953 win_size_save(&winsizes); | |
6954 | |
6955 /* Don't execute autocommands while creating the window. */ | |
1410 | 6956 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
6957 |
683 | 6958 /* don't use a new tab page */ |
6959 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
|
6960 cmdmod.noswapfile = 1; |
683 | 6961 |
7 | 6962 /* Create a window for the command-line buffer. */ |
6963 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
6964 { | |
6965 beep_flush(); | |
1410 | 6966 unblock_autocmds(); |
7 | 6967 return K_IGNORE; |
6968 } | |
1831 | 6969 cmdwin_type = get_cmdline_type(); |
7 | 6970 |
6971 /* Create the command-line buffer empty. */ | |
1743 | 6972 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 6973 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 6974 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
6975 curbuf->b_p_ma = TRUE; | |
1865 | 6976 #ifdef FEAT_FOLDING |
6977 curwin->w_p_fen = FALSE; | |
6978 #endif | |
7 | 6979 # ifdef FEAT_RIGHTLEFT |
510 | 6980 curwin->w_p_rl = cmdmsg_rl; |
6981 cmdmsg_rl = FALSE; | |
7 | 6982 # endif |
2583 | 6983 RESET_BINDING(curwin); |
7 | 6984 |
6985 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 6986 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6987 /* 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
|
6988 ++curbuf_lock; |
7 | 6989 |
510 | 6990 /* Showing the prompt may have set need_wait_return, reset it. */ |
6991 need_wait_return = FALSE; | |
6992 | |
1831 | 6993 histtype = hist_char2type(cmdwin_type); |
7 | 6994 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
6995 { | |
6996 if (p_wc == TAB) | |
6997 { | |
6998 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
6999 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7000 } | |
7001 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7002 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7003 --curbuf_lock; |
7 | 7004 |
10 | 7005 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7006 * sets 'textwidth' to 78). */ | |
7007 curbuf->b_p_tw = 0; | |
7008 | |
7 | 7009 /* Fill the buffer with the history. */ |
7010 init_history(); | |
7011 if (hislen > 0) | |
7012 { | |
7013 i = hisidx[histtype]; | |
7014 if (i >= 0) | |
7015 { | |
7016 lnum = 0; | |
7017 do | |
7018 { | |
7019 if (++i == hislen) | |
7020 i = 0; | |
7021 if (history[histtype][i].hisstr != NULL) | |
7022 ml_append(lnum++, history[histtype][i].hisstr, | |
7023 (colnr_T)0, FALSE); | |
7024 } | |
7025 while (i != hisidx[histtype]); | |
7026 } | |
7027 } | |
7028 | |
7029 /* Replace the empty last line with the current command-line and put the | |
7030 * cursor there. */ | |
7031 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7032 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7033 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7034 changed_line_abv_curs(); |
7035 invalidate_botline(); | |
743 | 7036 redraw_later(SOME_VALID); |
7 | 7037 |
7038 /* 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
|
7039 save_cmdline(&save_ccline); |
7 | 7040 |
7041 /* No Ex mode here! */ | |
7042 exmode_active = 0; | |
7043 | |
7044 State = NORMAL; | |
7045 # ifdef FEAT_MOUSE | |
7046 setmouse(); | |
7047 # endif | |
7048 | |
7049 /* 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
|
7050 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7051 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7052 stuffcharReadbuff(K_NOP); | |
7 | 7053 |
7054 i = RedrawingDisabled; | |
7055 RedrawingDisabled = 0; | |
7056 | |
7057 /* | |
7058 * Call the main loop until <CR> or CTRL-C is typed. | |
7059 */ | |
7060 cmdwin_result = 0; | |
168 | 7061 main_loop(TRUE, FALSE); |
7 | 7062 |
7063 RedrawingDisabled = i; | |
7064 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7065 # ifdef FEAT_FOLDING |
6145 | 7066 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7067 # endif |
6145 | 7068 |
7 | 7069 /* 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
|
7070 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7071 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7072 # ifdef FEAT_FOLDING |
6145 | 7073 /* Restore KeyTyped in case it is modified by autocommands */ |
7074 KeyTyped = save_KeyTyped; | |
7 | 7075 # endif |
7076 | |
1214 | 7077 /* 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
|
7078 restore_cmdline(&save_ccline); |
7 | 7079 cmdwin_type = 0; |
7080 | |
7081 exmode_active = save_exmode; | |
7082 | |
1612 | 7083 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7084 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7085 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7086 { |
7087 cmdwin_result = Ctrl_C; | |
7088 EMSG(_("E199: Active window or buffer deleted")); | |
7089 } | |
7090 else | |
7091 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7092 # if defined(FEAT_EVAL) |
7 | 7093 /* autocmds may abort script processing */ |
7094 if (aborting() && cmdwin_result != K_IGNORE) | |
7095 cmdwin_result = Ctrl_C; | |
7096 # endif | |
7097 /* Set the new command line from the cmdline buffer. */ | |
7098 vim_free(ccline.cmdbuff); | |
510 | 7099 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7100 { |
510 | 7101 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7102 | |
7103 if (histtype == HIST_CMD) | |
7104 { | |
7105 /* Execute the command directly. */ | |
7106 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7107 cmdwin_result = CAR; | |
7108 } | |
7109 else | |
7110 { | |
7111 /* First need to cancel what we were doing. */ | |
7112 ccline.cmdbuff = NULL; | |
7113 stuffcharReadbuff(':'); | |
7114 stuffReadbuff((char_u *)p); | |
7115 stuffcharReadbuff(CAR); | |
7116 } | |
7 | 7117 } |
7118 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7119 { | |
7120 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7121 cmdwin_result = CAR; | |
7122 } | |
2839 | 7123 else if (cmdwin_result == Ctrl_C) |
7124 { | |
7125 /* :q or :close, don't execute any command | |
7126 * and don't modify the cmd window. */ | |
7127 ccline.cmdbuff = NULL; | |
7128 } | |
7 | 7129 else |
7130 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7131 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
|
7132 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7133 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
|
7134 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
|
7135 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
|
7136 ccline.cmdpos = 0; |
7 | 7137 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
|
7138 } |
7 | 7139 else |
7140 { | |
7141 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7142 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7143 ccline.cmdpos = curwin->w_cursor.col; | |
7144 if (ccline.cmdpos > ccline.cmdlen) | |
7145 ccline.cmdpos = ccline.cmdlen; | |
7146 if (cmdwin_result == K_IGNORE) | |
7147 { | |
7148 set_cmdspos_cursor(); | |
7149 redrawcmd(); | |
7150 } | |
7151 } | |
7152 | |
7153 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7154 block_autocmds(); |
6876 | 7155 # ifdef FEAT_CONCEAL |
7156 /* Avoid command-line window first character being concealed. */ | |
7157 curwin->w_p_cole = 0; | |
7158 # endif | |
7 | 7159 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7160 set_bufref(&bufref, curbuf); |
7 | 7161 win_goto(old_curwin); |
7162 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7163 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7164 /* 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
|
7165 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7166 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7167 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7168 |
7169 /* Restore window sizes. */ | |
7170 win_size_restore(&winsizes); | |
7171 | |
1410 | 7172 unblock_autocmds(); |
7 | 7173 } |
7174 | |
7175 ga_clear(&winsizes); | |
7176 restart_edit = save_restart_edit; | |
510 | 7177 # ifdef FEAT_RIGHTLEFT |
7178 cmdmsg_rl = save_cmdmsg_rl; | |
7179 # endif | |
7 | 7180 |
7181 State = save_State; | |
7182 # ifdef FEAT_MOUSE | |
7183 setmouse(); | |
7184 # endif | |
7185 | |
7186 return cmdwin_result; | |
7187 } | |
7188 #endif /* FEAT_CMDWIN */ | |
7189 | |
7190 /* | |
7191 * Used for commands that either take a simple command string argument, or: | |
7192 * cmd << endmarker | |
7193 * {script} | |
7194 * endmarker | |
7195 * Returns a pointer to allocated memory with {script} or NULL. | |
7196 */ | |
7197 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7198 script_get(exarg_T *eap, char_u *cmd) |
7 | 7199 { |
7200 char_u *theline; | |
7201 char *end_pattern = NULL; | |
7202 char dot[] = "."; | |
7203 garray_T ga; | |
7204 | |
7205 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7206 return NULL; | |
7207 | |
7208 ga_init2(&ga, 1, 0x400); | |
7209 | |
7210 if (cmd[2] != NUL) | |
7211 end_pattern = (char *)skipwhite(cmd + 2); | |
7212 else | |
7213 end_pattern = dot; | |
7214 | |
7215 for (;;) | |
7216 { | |
7217 theline = eap->getline( | |
7218 #ifdef FEAT_EVAL | |
75 | 7219 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7220 #endif |
7221 NUL, eap->cookie, 0); | |
7222 | |
7223 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7224 { |
7225 vim_free(theline); | |
7 | 7226 break; |
1694 | 7227 } |
7 | 7228 |
7229 ga_concat(&ga, theline); | |
7230 ga_append(&ga, '\n'); | |
7231 vim_free(theline); | |
7232 } | |
21 | 7233 ga_append(&ga, NUL); |
7 | 7234 |
7235 return (char_u *)ga.ga_data; | |
7236 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7237 |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7238 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7239 static void |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7240 set_search_match(pos_T *t) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7241 { |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7242 /* |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7243 * First move cursor to end of match, then to the start. This |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7244 * moves the whole match onto the screen when 'nowrap' is set. |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7245 */ |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7246 t->lnum += search_match_lines; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7247 t->col = search_match_endcol; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7248 if (t->lnum > curbuf->b_ml.ml_line_count) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7249 { |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7250 t->lnum = curbuf->b_ml.ml_line_count; |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7251 coladvance((colnr_T)MAXCOL); |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7252 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7253 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7254 #endif |