Mercurial > vim
annotate src/ex_getln.c @ 14520:20866abc790b v8.1.0273
patch 8.1.0273: invalid memory access when using 'incsearch'
commit https://github.com/vim/vim/commit/ef73a28401cde680dc0d02d4b0fb19ed659ec1d3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 11 19:02:22 2018 +0200
patch 8.1.0273: invalid memory access when using 'incsearch'
Problem: Invalid memory access when using 'incsearch'.
Solution: Reset "patlen" when using previous search pattern.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 11 Aug 2018 19:15:04 +0200 |
parents | 3648e74dd523 |
children | 97641c4f5687 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
55 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
56 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
57 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
119 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
125 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
160 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
172 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
181 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
267 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
270 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
271 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
274 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
275 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 char_u *cmd = skip_range(ccline.cmdbuff, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 char_u *p; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 int delim; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 char_u *end; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
294 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
295 ; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
296 if (*p != NUL) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
297 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
298 delim = *p++; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
299 end = skip_regexp(p, delim, p_magic, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
300 if (end > p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
301 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
302 char_u *dummy; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
303 exarg_T ea; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
304 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
305 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
306 // found a non-empty pattern |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
307 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
308 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
309 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
310 // parse the address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
311 vim_memset(&ea, 0, sizeof(ea)); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 ea.line1 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 ea.line2 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 ea.cmd = ccline.cmdbuff; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
315 ea.addr_type = ADDR_LINES; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
316 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
317 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
318 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
319 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
320 search_first_line = ea.line1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
321 search_last_line = ea.line2; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
322 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
323 else if (*cmd == 's') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
324 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
325 // :s defaults to the current line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
326 search_first_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
327 search_last_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
328 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
329 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
330 curwin->w_cursor = save_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
331 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
332 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
333 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
334 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
335 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
336 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
337 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
338 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
339 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
340 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
341 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
342 * Do 'incsearch' highlighting if desired. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
343 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
344 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
345 may_do_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
346 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
347 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
348 incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
349 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
350 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
351 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
352 pos_T end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
353 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
354 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
355 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
356 #endif |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
357 int c; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
358 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
359 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
360 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
361 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
362 // If there is a character waiting, search and redraw later. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
363 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
364 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
365 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
366 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
367 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
368 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
369 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
370 if (search_first_line == 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
371 // start at the original cursor position |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
372 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
373 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
374 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
375 // start at the first line in the range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
376 curwin->w_cursor.lnum = search_first_line; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
377 curwin->w_cursor.col = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
378 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
379 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
380 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
381 // If there is no command line, don't do anything. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
382 if (patlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
383 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
384 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
385 set_no_hlsearch(TRUE); // turn off previous highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
386 redraw_all_later(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
387 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
388 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
389 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
390 int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
391 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
392 cursor_off(); // so the user knows we're busy |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
393 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
394 ++emsg_off; // so it doesn't beep if bad expr |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
395 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
396 // Set the time limit to half a second. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 profile_setlimit(500L, &tm); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
398 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 search_flags += SEARCH_KEEP; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
401 c = ccline.cmdbuff[skiplen + patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
402 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
403 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
404 ccline.cmdbuff + skiplen, count, search_flags, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
405 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
406 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
407 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
408 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
409 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
410 ); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
411 ccline.cmdbuff[skiplen + patlen] = c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
412 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
414 if (curwin->w_cursor.lnum < search_first_line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
415 || curwin->w_cursor.lnum > search_last_line) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
416 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
417 i = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
418 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 // if interrupted while searching, behave like it failed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
420 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
421 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
422 (void)vpeekc(); // remove <C-C> from input stream |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
423 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
424 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
425 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 else if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
427 // cancelled searching because a char was typed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
428 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
429 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
430 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
431 highlight_match = TRUE; // highlight position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
432 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
433 highlight_match = FALSE; // remove highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
434 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
435 // First restore the old curwin values, so the screen is positioned in the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
436 // same way as the actual search command. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
437 restore_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
438 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
439 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
441 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 pos_T save_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
444 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
445 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
446 set_search_match(&curwin->w_cursor); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
447 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 end_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 is_state->match_end = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 curwin->w_cursor = save_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 end_pos = curwin->w_cursor; // shutup gcc 4 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 // Avoids a flash when typing "foo\|". |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
457 c = ccline.cmdbuff[skiplen + patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
458 ccline.cmdbuff[skiplen + patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 if (empty_pattern(ccline.cmdbuff)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 set_no_hlsearch(TRUE); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
461 ccline.cmdbuff[skiplen + patlen] = c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
463 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
464 // May redraw the status line to show the cursor position. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 if (p_ru && curwin->w_status_height > 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 curwin->w_redr_status = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 update_screen(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
472 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 is_state->did_incsearch = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 * May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 * Returns FAIL when jumping to cmdline_not_changed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 may_adjust_incsearch_highlighting( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
489 int firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
490 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 incsearch_state_T *is_state, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
492 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
493 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
494 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
495 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 int search_flags = SEARCH_NOOF; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 int i; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
499 int save; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
500 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
501 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
503 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
504 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
506 if (firstc == ccline.cmdbuff[skiplen]) |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
507 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 pat = last_search_pattern(); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
509 skiplen = 0; |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
510 patlen = STRLEN(pat); |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
511 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 else |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
513 pat = ccline.cmdbuff + skiplen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 if (c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 t = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 if (LT_POS(is_state->match_start, is_state->match_end)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 // Start searching at the end of the match not at the beginning of |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 t = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 search_flags += SEARCH_KEEP; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
532 save = pat[patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
533 pat[patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 i = searchit(curwin, curbuf, &t, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 c == Ctrl_G ? FORWARD : BACKWARD, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 pat, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 RE_SEARCH, 0, NULL, NULL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
539 pat[patlen] = save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 is_state->search_start = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 is_state->match_end = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 is_state->match_start = t; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
545 if (c == Ctrl_T && firstc != '?') |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 // Move just before the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 else if (c == Ctrl_G && firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
554 // Move just after the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
556 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
558 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
559 if (LT_POS(t, is_state->search_start) && c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
563 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 set_search_match(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 curwin->w_cursor = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
573 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
576 update_screen(NOT_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
577 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 vim_beep(BO_ERROR); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 * When CTRL-L typed: add character from the match to the pattern. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 * May set "*c" to the added character. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
588 * Return OK when jumping to cmdline_not_changed. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
593 int skiplen, patlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
594 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
595 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
596 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 // Add a character from under the cursor for 'incsearch'. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 curwin->w_cursor = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 if (!EQUAL_POS(curwin->w_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 // If 'ignorecase' and 'smartcase' are set and the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 // command line has no uppercase characters, convert |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 // the character to lowercase. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
609 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 *c = MB_TOLOWER(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 if (*c == firstc || vim_strchr((char_u *)( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 // put a backslash before special characters |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
623 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 finish_incsearch_highlighting(int gotesc, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 if (gotesc) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 // put the '" mark at the original position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 setpcmark(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 curwin->w_cursor = is_state->search_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 restore_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 highlight_match = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 validate_cursor(); /* needed for TAB */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 redraw_all_later(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
650 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
651 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
652 /* |
7 | 653 * getcmdline() - accept a command line starting with firstc. |
654 * | |
655 * firstc == ':' get ":" command line. | |
656 * firstc == '/' or '?' get search pattern | |
657 * firstc == '=' get expression | |
658 * firstc == '@' get text for input() function | |
659 * firstc == '>' get text for debug mode | |
660 * firstc == NUL get text for :insert command | |
661 * firstc == -1 like NUL, and break on CTRL-C | |
662 * | |
663 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
664 * command line. | |
665 * | |
666 * Careful: getcmdline() can be called recursively! | |
667 * | |
668 * Return pointer to allocated string if there is a commandline, NULL | |
669 * otherwise. | |
670 */ | |
671 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
672 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
673 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
674 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
|
675 int indent) /* indent for inside conditionals */ |
7 | 676 { |
677 int c; | |
678 int i; | |
679 int j; | |
680 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
681 int do_abbr; /* when TRUE check for abbr. */ | |
682 #ifdef FEAT_CMDHIST | |
683 char_u *lookfor = NULL; /* string to match */ | |
684 int hiscnt; /* current history line in use */ | |
685 int histype; /* history type to be used */ | |
686 #endif | |
687 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 incsearch_state_T is_state; |
7 | 689 #endif |
690 int did_wild_list = FALSE; /* did wild_list() recently */ | |
691 int wim_index = 0; /* index in wim_flags[] */ | |
692 int res; | |
693 int save_msg_scroll = msg_scroll; | |
694 int save_State = State; /* remember State when called */ | |
695 int some_key_typed = FALSE; /* one of the keys was typed */ | |
696 #ifdef FEAT_MOUSE | |
697 /* mouse drag and release events are ignored, unless they are | |
698 * preceded with a mouse down event */ | |
699 int ignore_drag_release = TRUE; | |
700 #endif | |
701 #ifdef FEAT_EVAL | |
702 int break_ctrl_c = FALSE; | |
703 #endif | |
704 expand_T xpc; | |
705 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 707 /* Everything that may work recursively should save and restore the |
708 * current command line in save_ccline. That includes update_screen(), a | |
709 * custom status line may invoke ":normal". */ | |
710 struct cmdline_info save_ccline; | |
711 #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
|
712 int cmdline_type; |
7 | 713 |
714 #ifdef FEAT_EVAL | |
715 if (firstc == -1) | |
716 { | |
717 firstc = NUL; | |
718 break_ctrl_c = TRUE; | |
719 } | |
720 #endif | |
721 #ifdef FEAT_RIGHTLEFT | |
722 /* start without Hebrew mapping for a command line */ | |
723 if (firstc == ':' || firstc == '=' || firstc == '>') | |
724 cmd_hkmap = 0; | |
725 #endif | |
726 | |
727 ccline.overstrike = FALSE; /* always start in insert mode */ | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
728 |
7 | 729 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 init_incsearch_state(&is_state); |
7 | 731 #endif |
732 | |
733 /* | |
734 * set some variables for redrawcmd() | |
735 */ | |
736 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 737 ccline.cmdindent = (firstc > 0 ? indent : 0); |
738 | |
739 /* alloc initial ccline.cmdbuff */ | |
740 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 741 if (ccline.cmdbuff == NULL) |
742 return NULL; /* out of memory */ | |
743 ccline.cmdlen = ccline.cmdpos = 0; | |
744 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
|
745 sb_text_start_cmdline(); |
7 | 746 |
164 | 747 /* autoindent for :insert and :append */ |
748 if (firstc <= 0) | |
749 { | |
6929 | 750 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 751 ccline.cmdbuff[indent] = NUL; |
752 ccline.cmdpos = indent; | |
753 ccline.cmdspos = indent; | |
754 ccline.cmdlen = indent; | |
755 } | |
756 | |
7 | 757 ExpandInit(&xpc); |
1718 | 758 ccline.xpc = &xpc; |
7 | 759 |
760 #ifdef FEAT_RIGHTLEFT | |
761 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
762 && (firstc == '/' || firstc == '?')) | |
763 cmdmsg_rl = TRUE; | |
764 else | |
765 cmdmsg_rl = FALSE; | |
766 #endif | |
767 | |
768 redir_off = TRUE; /* don't redirect the typed command */ | |
769 if (!cmd_silent) | |
770 { | |
771 i = msg_scrolled; | |
772 msg_scrolled = 0; /* avoid wait_return message */ | |
773 gotocmdline(TRUE); | |
774 msg_scrolled += i; | |
775 redrawcmdprompt(); /* draw prompt or indent */ | |
776 set_cmdspos(); | |
777 } | |
778 xpc.xp_context = EXPAND_NOTHING; | |
779 xpc.xp_backslash = XP_BS_NONE; | |
632 | 780 #ifndef BACKSLASH_IN_FILENAME |
781 xpc.xp_shell = FALSE; | |
782 #endif | |
7 | 783 |
531 | 784 #if defined(FEAT_EVAL) |
785 if (ccline.input_fn) | |
786 { | |
787 xpc.xp_context = ccline.xp_context; | |
788 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 789 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 790 xpc.xp_arg = ccline.xp_arg; |
1322 | 791 # endif |
531 | 792 } |
793 #endif | |
794 | |
7 | 795 /* |
796 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
797 * doing ":@0" when register 0 doesn't contain a CR. | |
798 */ | |
799 msg_scroll = FALSE; | |
800 | |
801 State = CMDLINE; | |
802 | |
803 if (firstc == '/' || firstc == '?' || firstc == '@') | |
804 { | |
805 /* Use ":lmap" mappings for search pattern and input(). */ | |
806 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
807 b_im_ptr = &curbuf->b_p_iminsert; | |
808 else | |
809 b_im_ptr = &curbuf->b_p_imsearch; | |
810 if (*b_im_ptr == B_IMODE_LMAP) | |
811 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
812 #ifdef HAVE_INPUT_METHOD |
7 | 813 im_set_active(*b_im_ptr == B_IMODE_IM); |
814 #endif | |
815 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
816 #ifdef HAVE_INPUT_METHOD |
7 | 817 else if (p_imcmdline) |
818 im_set_active(TRUE); | |
819 #endif | |
820 | |
821 #ifdef FEAT_MOUSE | |
822 setmouse(); | |
823 #endif | |
824 #ifdef CURSOR_SHAPE | |
825 ui_cursor_shape(); /* may show different cursor shape */ | |
826 #endif | |
827 | |
571 | 828 /* When inside an autocommand for writing "exiting" may be set and |
829 * terminal mode set to cooked. Need to set raw mode here then. */ | |
830 settmode(TMODE_RAW); | |
831 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
832 /* 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
|
833 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
|
834 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
|
835 |
7 | 836 #ifdef FEAT_CMDHIST |
837 init_history(); | |
838 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
839 histype = hist_char2type(firstc); | |
840 #endif | |
841 | |
842 #ifdef FEAT_DIGRAPHS | |
1868 | 843 do_digraph(-1); /* init digraph typeahead */ |
7 | 844 #endif |
845 | |
5993 | 846 /* If something above caused an error, reset the flags, we do want to type |
847 * and execute commands. Display may be messed up a bit. */ | |
848 if (did_emsg) | |
849 redrawcmd(); | |
850 did_emsg = FALSE; | |
851 got_int = FALSE; | |
852 | |
7 | 853 /* |
854 * Collect the command string, handling editing keys. | |
855 */ | |
856 for (;;) | |
857 { | |
972 | 858 redir_off = TRUE; /* Don't redirect the typed command. |
859 Repeated, because a ":redir" inside | |
860 completion may switch it on. */ | |
7 | 861 #ifdef USE_ON_FLY_SCROLL |
862 dont_scroll = FALSE; /* allow scrolling here */ | |
863 #endif | |
864 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
865 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
866 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
|
867 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
|
868 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
|
869 |
7 | 870 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 871 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
872 /* 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
|
873 * anything, such as stop completion. */ |
1472 | 874 do |
875 { | |
876 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
|
877 } while (c == K_IGNORE || c == K_NOP); |
1472 | 878 |
7 | 879 if (KeyTyped) |
880 { | |
881 some_key_typed = TRUE; | |
882 #ifdef FEAT_RIGHTLEFT | |
883 if (cmd_hkmap) | |
884 c = hkmap(c); | |
885 # ifdef FEAT_FKMAP | |
886 if (cmd_fkmap) | |
887 c = cmdl_fkmap(c); | |
888 # endif | |
889 if (cmdmsg_rl && !KeyStuffed) | |
890 { | |
891 /* Invert horizontal movements and operations. Only when | |
892 * typed by the user directly, not when the result of a | |
893 * mapping. */ | |
894 switch (c) | |
895 { | |
896 case K_RIGHT: c = K_LEFT; break; | |
897 case K_S_RIGHT: c = K_S_LEFT; break; | |
898 case K_C_RIGHT: c = K_C_LEFT; break; | |
899 case K_LEFT: c = K_RIGHT; break; | |
900 case K_S_LEFT: c = K_S_RIGHT; break; | |
901 case K_C_LEFT: c = K_C_RIGHT; break; | |
902 } | |
903 } | |
904 #endif | |
905 } | |
906 | |
907 /* | |
908 * Ignore got_int when CTRL-C was typed here. | |
909 * Don't ignore it in :global, we really need to break then, e.g., for | |
910 * ":g/pat/normal /pat" (without the <CR>). | |
911 * Don't ignore it for the input() function. | |
912 */ | |
913 if ((c == Ctrl_C | |
914 #ifdef UNIX | |
915 || c == intr_char | |
916 #endif | |
917 ) | |
918 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
919 && firstc != '@' | |
920 #endif | |
921 #ifdef FEAT_EVAL | |
922 && !break_ctrl_c | |
923 #endif | |
924 && !global_busy) | |
925 got_int = FALSE; | |
926 | |
927 #ifdef FEAT_CMDHIST | |
928 /* free old command line when finished moving around in the history | |
929 * list */ | |
930 if (lookfor != NULL | |
180 | 931 && c != K_S_DOWN && c != K_S_UP |
230 | 932 && c != K_DOWN && c != K_UP |
7 | 933 && c != K_PAGEDOWN && c != K_PAGEUP |
934 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 935 && c != K_LEFT && c != K_RIGHT |
7 | 936 && (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
|
937 VIM_CLEAR(lookfor); |
7 | 938 #endif |
939 | |
940 /* | |
1718 | 941 * When there are matching completions to select <S-Tab> works like |
942 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 943 */ |
1718 | 944 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 945 c = Ctrl_P; |
946 | |
947 #ifdef FEAT_WILDMENU | |
948 /* Special translations for 'wildmenu' */ | |
949 if (did_wild_list && p_wmnu) | |
950 { | |
230 | 951 if (c == K_LEFT) |
7 | 952 c = Ctrl_P; |
230 | 953 else if (c == K_RIGHT) |
7 | 954 c = Ctrl_N; |
955 } | |
956 /* Hitting CR after "emenu Name.": complete submenu */ | |
957 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
958 && ccline.cmdpos > 1 | |
959 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
960 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
961 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
962 c = K_DOWN; | |
963 #endif | |
964 | |
965 /* free expanded names when finished walking through matches */ | |
966 if (xpc.xp_numfiles != -1 | |
967 && !(c == p_wc && KeyTyped) && c != p_wcm | |
968 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
969 && c != Ctrl_L) | |
970 { | |
971 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
972 did_wild_list = FALSE; | |
973 #ifdef FEAT_WILDMENU | |
230 | 974 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 975 #endif |
976 xpc.xp_context = EXPAND_NOTHING; | |
977 wim_index = 0; | |
978 #ifdef FEAT_WILDMENU | |
979 if (p_wmnu && wild_menu_showing != 0) | |
980 { | |
981 int skt = KeyTyped; | |
532 | 982 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 983 |
984 if (ccline.input_fn) | |
985 RedrawingDisabled = 0; | |
7 | 986 |
987 if (wild_menu_showing == WM_SCROLLED) | |
988 { | |
989 /* Entered command line, move it up */ | |
990 cmdline_row--; | |
991 redrawcmd(); | |
992 } | |
993 else if (save_p_ls != -1) | |
994 { | |
995 /* restore 'laststatus' and 'winminheight' */ | |
996 p_ls = save_p_ls; | |
997 p_wmh = save_p_wmh; | |
998 last_status(FALSE); | |
195 | 999 save_cmdline(&save_ccline); |
7 | 1000 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1001 restore_cmdline(&save_ccline); |
7 | 1002 redrawcmd(); |
1003 save_p_ls = -1; | |
1004 } | |
1005 else | |
1006 { | |
1007 win_redraw_last_status(topframe); | |
1008 redraw_statuslines(); | |
1009 } | |
532 | 1010 KeyTyped = skt; |
1011 wild_menu_showing = 0; | |
531 | 1012 if (ccline.input_fn) |
1013 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1014 } |
1015 #endif | |
1016 } | |
1017 | |
1018 #ifdef FEAT_WILDMENU | |
1019 /* Special translations for 'wildmenu' */ | |
1020 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1021 { | |
1022 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1023 if (c == K_DOWN && ccline.cmdpos > 0 |
1024 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1025 c = p_wc; |
230 | 1026 else if (c == K_UP) |
7 | 1027 { |
1028 /* Hitting <Up>: Remove one submenu name in front of the | |
1029 * cursor */ | |
1030 int found = FALSE; | |
1031 | |
1032 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1033 i = 0; | |
1034 while (--j > 0) | |
1035 { | |
1036 /* check for start of menu name */ | |
1037 if (ccline.cmdbuff[j] == ' ' | |
1038 && ccline.cmdbuff[j - 1] != '\\') | |
1039 { | |
1040 i = j + 1; | |
1041 break; | |
1042 } | |
1043 /* check for start of submenu name */ | |
1044 if (ccline.cmdbuff[j] == '.' | |
1045 && ccline.cmdbuff[j - 1] != '\\') | |
1046 { | |
1047 if (found) | |
1048 { | |
1049 i = j + 1; | |
1050 break; | |
1051 } | |
1052 else | |
1053 found = TRUE; | |
1054 } | |
1055 } | |
1056 if (i > 0) | |
1057 cmdline_del(i); | |
1058 c = p_wc; | |
1059 xpc.xp_context = EXPAND_NOTHING; | |
1060 } | |
1061 } | |
714 | 1062 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1063 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1064 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1065 { |
1066 char_u upseg[5]; | |
1067 | |
1068 upseg[0] = PATHSEP; | |
1069 upseg[1] = '.'; | |
1070 upseg[2] = '.'; | |
1071 upseg[3] = PATHSEP; | |
1072 upseg[4] = NUL; | |
1073 | |
1318 | 1074 if (c == K_DOWN |
1075 && ccline.cmdpos > 0 | |
1076 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1077 && (ccline.cmdpos < 3 | |
1078 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1079 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1080 { | |
1081 /* go down a directory */ | |
1082 c = p_wc; | |
1083 } | |
230 | 1084 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1085 { |
1086 /* If in a direct ancestor, strip off one ../ to go down */ | |
1087 int found = FALSE; | |
1088 | |
1089 j = ccline.cmdpos; | |
1090 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1091 while (--j > i) | |
1092 { | |
39 | 1093 #ifdef FEAT_MBYTE |
1094 if (has_mbyte) | |
1095 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1096 #endif | |
7 | 1097 if (vim_ispathsep(ccline.cmdbuff[j])) |
1098 { | |
1099 found = TRUE; | |
1100 break; | |
1101 } | |
1102 } | |
1103 if (found | |
1104 && ccline.cmdbuff[j - 1] == '.' | |
1105 && ccline.cmdbuff[j - 2] == '.' | |
1106 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1107 { | |
1108 cmdline_del(j - 2); | |
1109 c = p_wc; | |
1110 } | |
1111 } | |
230 | 1112 else if (c == K_UP) |
7 | 1113 { |
1114 /* go up a directory */ | |
1115 int found = FALSE; | |
1116 | |
1117 j = ccline.cmdpos - 1; | |
1118 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1119 while (--j > i) | |
1120 { | |
1121 #ifdef FEAT_MBYTE | |
1122 if (has_mbyte) | |
1123 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1124 #endif | |
1125 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1126 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1127 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1128 ccline.cmdbuff[j + 1]) == NULL |
7 | 1129 #endif |
1130 ) | |
1131 { | |
1132 if (found) | |
1133 { | |
1134 i = j + 1; | |
1135 break; | |
1136 } | |
1137 else | |
1138 found = TRUE; | |
1139 } | |
1140 } | |
1141 | |
1142 if (!found) | |
1143 j = i; | |
1144 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1145 j += 4; | |
1146 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1147 && j == i) | |
1148 j += 3; | |
1149 else | |
1150 j = 0; | |
1151 if (j > 0) | |
1152 { | |
1153 /* TODO this is only for DOS/UNIX systems - need to put in | |
1154 * machine-specific stuff here and in upseg init */ | |
1155 cmdline_del(j); | |
1156 put_on_cmdline(upseg + 1, 3, FALSE); | |
1157 } | |
1158 else if (ccline.cmdpos > i) | |
1159 cmdline_del(i); | |
3204 | 1160 |
1161 /* Now complete in the new directory. Set KeyTyped in case the | |
1162 * Up key came from a mapping. */ | |
7 | 1163 c = p_wc; |
3204 | 1164 KeyTyped = TRUE; |
7 | 1165 } |
1166 } | |
1167 | |
1168 #endif /* FEAT_WILDMENU */ | |
1169 | |
1170 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1171 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1172 if (c == Ctrl_BSL) | |
1173 { | |
1174 ++no_mapping; | |
1175 ++allow_keys; | |
1389 | 1176 c = plain_vgetc(); |
7 | 1177 --no_mapping; |
1178 --allow_keys; | |
3859 | 1179 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1180 * is in a mapping. */ | |
1181 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1182 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1183 { |
1184 vungetc(c); | |
1185 c = Ctrl_BSL; | |
1186 } | |
1187 #ifdef FEAT_EVAL | |
1188 else if (c == 'e') | |
1189 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1190 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1191 int len; |
7 | 1192 |
1193 /* | |
1194 * Replace the command line with the result of an expression. | |
625 | 1195 * Need to save and restore the current command line, to be |
1196 * able to enter a new one... | |
7 | 1197 */ |
1198 if (ccline.cmdpos == ccline.cmdlen) | |
1199 new_cmdpos = 99999; /* keep it at the end */ | |
1200 else | |
1201 new_cmdpos = ccline.cmdpos; | |
95 | 1202 |
1203 save_cmdline(&save_ccline); | |
7 | 1204 c = get_expr_register(); |
95 | 1205 restore_cmdline(&save_ccline); |
7 | 1206 if (c == '=') |
1207 { | |
634 | 1208 /* Need to save and restore ccline. And set "textlock" |
632 | 1209 * to avoid nasty things like going to another buffer when |
1210 * evaluating an expression. */ | |
95 | 1211 save_cmdline(&save_ccline); |
634 | 1212 ++textlock; |
7 | 1213 p = get_expr_line(); |
634 | 1214 --textlock; |
95 | 1215 restore_cmdline(&save_ccline); |
2617 | 1216 |
1217 if (p != NULL) | |
7 | 1218 { |
2617 | 1219 len = (int)STRLEN(p); |
1220 if (realloc_cmdbuff(len + 1) == OK) | |
1221 { | |
1222 ccline.cmdlen = len; | |
1223 STRCPY(ccline.cmdbuff, p); | |
1224 vim_free(p); | |
1225 | |
1226 /* Restore the cursor or use the position set with | |
1227 * set_cmdline_pos(). */ | |
1228 if (new_cmdpos > ccline.cmdlen) | |
1229 ccline.cmdpos = ccline.cmdlen; | |
1230 else | |
1231 ccline.cmdpos = new_cmdpos; | |
1232 | |
1233 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1234 redrawcmd(); | |
1235 goto cmdline_changed; | |
1236 } | |
7 | 1237 } |
1238 } | |
1239 beep_flush(); | |
2636 | 1240 got_int = FALSE; /* don't abandon the command line */ |
1241 did_emsg = FALSE; | |
1242 emsg_on_display = FALSE; | |
1243 redrawcmd(); | |
1244 goto cmdline_not_changed; | |
7 | 1245 } |
1246 #endif | |
1247 else | |
1248 { | |
1249 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1250 restart_edit = 'a'; | |
1251 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1252 in history */ | |
1253 goto returncmd; /* back to Normal mode */ | |
1254 } | |
1255 } | |
1256 | |
1257 #ifdef FEAT_CMDWIN | |
1258 if (c == cedit_key || c == K_CMDWIN) | |
1259 { | |
6211 | 1260 if (ex_normal_busy == 0 && got_int == FALSE) |
1261 { | |
1262 /* | |
1263 * Open a window to edit the command line (and history). | |
1264 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1265 c = open_cmdwin(); |
6211 | 1266 some_key_typed = TRUE; |
1267 } | |
7 | 1268 } |
1269 # ifdef FEAT_DIGRAPHS | |
1270 else | |
1271 # endif | |
1272 #endif | |
1273 #ifdef FEAT_DIGRAPHS | |
1274 c = do_digraph(c); | |
1275 #endif | |
1276 | |
1277 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1278 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1279 { | |
168 | 1280 /* In Ex mode a backslash escapes a newline. */ |
1281 if (exmode_active | |
1282 && c != ESC | |
1318 | 1283 && ccline.cmdpos == ccline.cmdlen |
168 | 1284 && ccline.cmdpos > 0 |
1285 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1286 { | |
1287 if (c == K_KENTER) | |
1288 c = '\n'; | |
1289 } | |
1290 else | |
7 | 1291 { |
168 | 1292 gotesc = FALSE; /* Might have typed ESC previously, don't |
1293 truncate the cmdline now. */ | |
1294 if (ccheck_abbr(c + ABBR_OFF)) | |
1295 goto cmdline_changed; | |
1296 if (!cmd_silent) | |
1297 { | |
1298 windgoto(msg_row, 0); | |
1299 out_flush(); | |
1300 } | |
1301 break; | |
7 | 1302 } |
1303 } | |
1304 | |
1305 /* | |
1306 * Completion for 'wildchar' or 'wildcharm' key. | |
1307 * - hitting <ESC> twice means: abandon command line. | |
1308 * - wildcard expansion is only done when the 'wildchar' key is really | |
1309 * typed, not when it comes from a macro | |
1310 */ | |
1311 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1312 { | |
1313 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1314 { | |
1315 /* if 'wildmode' contains "list" may still need to list */ | |
1316 if (xpc.xp_numfiles > 1 | |
1317 && !did_wild_list | |
1318 && (wim_flags[wim_index] & WIM_LIST)) | |
1319 { | |
1320 (void)showmatches(&xpc, FALSE); | |
1321 redrawcmd(); | |
1322 did_wild_list = TRUE; | |
1323 } | |
1324 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1325 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1326 firstc != '@'); | |
7 | 1327 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1328 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1329 firstc != '@'); | |
7 | 1330 else |
1331 res = OK; /* don't insert 'wildchar' now */ | |
1332 } | |
1333 else /* typed p_wc first time */ | |
1334 { | |
1335 wim_index = 0; | |
1336 j = ccline.cmdpos; | |
1337 /* if 'wildmode' first contains "longest", get longest | |
1338 * common part */ | |
1339 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1340 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1341 firstc != '@'); | |
7 | 1342 else |
3961 | 1343 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1344 firstc != '@'); | |
7 | 1345 |
1346 /* if interrupted while completing, behave like it failed */ | |
1347 if (got_int) | |
1348 { | |
1349 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1350 got_int = FALSE; /* don't abandon the command line */ | |
1351 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1352 #ifdef FEAT_WILDMENU | |
1353 xpc.xp_context = EXPAND_NOTHING; | |
1354 #endif | |
1355 goto cmdline_changed; | |
1356 } | |
1357 | |
1358 /* when more than one match, and 'wildmode' first contains | |
1359 * "list", or no change and 'wildmode' contains "longest,list", | |
1360 * list all matches */ | |
1361 if (res == OK && xpc.xp_numfiles > 1) | |
1362 { | |
1363 /* a "longest" that didn't do anything is skipped (but not | |
1364 * "list:longest") */ | |
1365 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1366 wim_index = 1; | |
1367 if ((wim_flags[wim_index] & WIM_LIST) | |
1368 #ifdef FEAT_WILDMENU | |
1369 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1370 #endif | |
1371 ) | |
1372 { | |
1373 if (!(wim_flags[0] & WIM_LONGEST)) | |
1374 { | |
1375 #ifdef FEAT_WILDMENU | |
1376 int p_wmnu_save = p_wmnu; | |
1377 p_wmnu = 0; | |
1378 #endif | |
3961 | 1379 /* remove match */ |
1380 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1381 #ifdef FEAT_WILDMENU |
1382 p_wmnu = p_wmnu_save; | |
1383 #endif | |
1384 } | |
1385 #ifdef FEAT_WILDMENU | |
1386 (void)showmatches(&xpc, p_wmnu | |
1387 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1388 #else | |
1389 (void)showmatches(&xpc, FALSE); | |
1390 #endif | |
1391 redrawcmd(); | |
1392 did_wild_list = TRUE; | |
1393 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1394 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1395 firstc != '@'); | |
7 | 1396 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1397 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1398 firstc != '@'); | |
7 | 1399 } |
1400 else | |
6949 | 1401 vim_beep(BO_WILD); |
7 | 1402 } |
1403 #ifdef FEAT_WILDMENU | |
1404 else if (xpc.xp_numfiles == -1) | |
1405 xpc.xp_context = EXPAND_NOTHING; | |
1406 #endif | |
1407 } | |
1408 if (wim_index < 3) | |
1409 ++wim_index; | |
1410 if (c == ESC) | |
1411 gotesc = TRUE; | |
1412 if (res == OK) | |
1413 goto cmdline_changed; | |
1414 } | |
1415 | |
1416 gotesc = FALSE; | |
1417 | |
1418 /* <S-Tab> goes to last match, in a clumsy way */ | |
1419 if (c == K_S_TAB && KeyTyped) | |
1420 { | |
3961 | 1421 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1422 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1423 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1424 goto cmdline_changed; |
1425 } | |
1426 | |
1427 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1428 c = NL; | |
1429 | |
1430 do_abbr = TRUE; /* default: check for abbreviation */ | |
1431 | |
1432 /* | |
1433 * Big switch for a typed command line character. | |
1434 */ | |
1435 switch (c) | |
1436 { | |
1437 case K_BS: | |
1438 case Ctrl_H: | |
1439 case K_DEL: | |
1440 case K_KDEL: | |
1441 case Ctrl_W: | |
1442 #ifdef FEAT_FKMAP | |
1443 if (cmd_fkmap && c == K_BS) | |
1444 c = K_DEL; | |
1445 #endif | |
1446 if (c == K_KDEL) | |
1447 c = K_DEL; | |
1448 | |
1449 /* | |
1450 * delete current character is the same as backspace on next | |
1451 * character, except at end of line | |
1452 */ | |
1453 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1454 ++ccline.cmdpos; | |
1455 #ifdef FEAT_MBYTE | |
1456 if (has_mbyte && c == K_DEL) | |
1457 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1458 ccline.cmdbuff + ccline.cmdpos); | |
1459 #endif | |
1460 if (ccline.cmdpos > 0) | |
1461 { | |
1462 char_u *p; | |
1463 | |
1464 j = ccline.cmdpos; | |
1465 p = ccline.cmdbuff + j; | |
1466 #ifdef FEAT_MBYTE | |
1467 if (has_mbyte) | |
1468 { | |
1469 p = mb_prevptr(ccline.cmdbuff, p); | |
1470 if (c == Ctrl_W) | |
1471 { | |
1472 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1473 p = mb_prevptr(ccline.cmdbuff, p); | |
1474 i = mb_get_class(p); | |
1475 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1476 p = mb_prevptr(ccline.cmdbuff, p); | |
1477 if (mb_get_class(p) != i) | |
474 | 1478 p += (*mb_ptr2len)(p); |
7 | 1479 } |
1480 } | |
1481 else | |
1482 #endif | |
1483 if (c == Ctrl_W) | |
1484 { | |
1485 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1486 --p; | |
1487 i = vim_iswordc(p[-1]); | |
1488 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1489 && vim_iswordc(p[-1]) == i) | |
1490 --p; | |
1491 } | |
1492 else | |
1493 --p; | |
1494 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1495 ccline.cmdlen -= j - ccline.cmdpos; | |
1496 i = ccline.cmdpos; | |
1497 while (i < ccline.cmdlen) | |
1498 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1499 | |
1500 /* Truncate at the end, required for multi-byte chars. */ | |
1501 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1502 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1503 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1504 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1505 is_state.search_start = is_state.save_cursor; |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1506 /* 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
|
1507 * won't be restored at the wrong position */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1508 is_state.old_viewstate = is_state.init_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1509 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1510 #endif |
7 | 1511 redrawcmd(); |
1512 } | |
1513 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1514 && ccline.cmdprompt == NULL && indent == 0) | |
1515 { | |
1516 /* In ex and debug mode it doesn't make sense to return. */ | |
1517 if (exmode_active | |
1518 #ifdef FEAT_EVAL | |
1519 || ccline.cmdfirstc == '>' | |
1520 #endif | |
1521 ) | |
1522 goto cmdline_not_changed; | |
1523 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1524 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1525 if (!cmd_silent) |
1526 { | |
1527 #ifdef FEAT_RIGHTLEFT | |
1528 if (cmdmsg_rl) | |
1529 msg_col = Columns; | |
1530 else | |
1531 #endif | |
1532 msg_col = 0; | |
1533 msg_putchar(' '); /* delete ':' */ | |
1534 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1535 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1536 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1537 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1538 #endif |
7 | 1539 redraw_cmdline = TRUE; |
1540 goto returncmd; /* back to cmd mode */ | |
1541 } | |
1542 goto cmdline_changed; | |
1543 | |
1544 case K_INS: | |
1545 case K_KINS: | |
1546 #ifdef FEAT_FKMAP | |
1547 /* if Farsi mode set, we are in reverse insert mode - | |
1548 Do not change the mode */ | |
1549 if (cmd_fkmap) | |
1550 beep_flush(); | |
1551 else | |
1552 #endif | |
1553 ccline.overstrike = !ccline.overstrike; | |
1554 #ifdef CURSOR_SHAPE | |
1555 ui_cursor_shape(); /* may show different cursor shape */ | |
1556 #endif | |
1557 goto cmdline_not_changed; | |
1558 | |
1559 case Ctrl_HAT: | |
782 | 1560 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1561 { |
1562 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1563 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1564 #ifdef HAVE_INPUT_METHOD |
7 | 1565 im_set_active(FALSE); /* Disable input method */ |
1566 #endif | |
1567 if (b_im_ptr != NULL) | |
1568 { | |
1569 if (State & LANGMAP) | |
1570 *b_im_ptr = B_IMODE_LMAP; | |
1571 else | |
1572 *b_im_ptr = B_IMODE_NONE; | |
1573 } | |
1574 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1575 #ifdef HAVE_INPUT_METHOD |
7 | 1576 else |
1577 { | |
1578 /* There are no ":lmap" mappings, toggle IM. When | |
1579 * 'imdisable' is set don't try getting the status, it's | |
1580 * always off. */ | |
1581 if ((p_imdisable && b_im_ptr != NULL) | |
1582 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1583 { | |
1584 im_set_active(FALSE); /* Disable input method */ | |
1585 if (b_im_ptr != NULL) | |
1586 *b_im_ptr = B_IMODE_NONE; | |
1587 } | |
1588 else | |
1589 { | |
1590 im_set_active(TRUE); /* Enable input method */ | |
1591 if (b_im_ptr != NULL) | |
1592 *b_im_ptr = B_IMODE_IM; | |
1593 } | |
1594 } | |
1595 #endif | |
1596 if (b_im_ptr != NULL) | |
1597 { | |
1598 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1599 set_iminsert_global(); | |
1600 else | |
1601 set_imsearch_global(); | |
1602 } | |
1603 #ifdef CURSOR_SHAPE | |
1604 ui_cursor_shape(); /* may show different cursor shape */ | |
1605 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1606 #if defined(FEAT_KEYMAP) |
7 | 1607 /* Show/unshow value of 'keymap' in status lines later. */ |
1608 status_redraw_curbuf(); | |
1609 #endif | |
1610 goto cmdline_not_changed; | |
1611 | |
1612 /* case '@': only in very old vi */ | |
1613 case Ctrl_U: | |
1614 /* delete all characters left of the cursor */ | |
1615 j = ccline.cmdpos; | |
1616 ccline.cmdlen -= j; | |
1617 i = ccline.cmdpos = 0; | |
1618 while (i < ccline.cmdlen) | |
1619 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1620 /* Truncate at the end, required for multi-byte chars. */ | |
1621 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1622 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1623 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1624 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1625 #endif |
7 | 1626 redrawcmd(); |
1627 goto cmdline_changed; | |
1628 | |
1629 #ifdef FEAT_CLIPBOARD | |
1630 case Ctrl_Y: | |
1631 /* Copy the modeless selection, if there is one. */ | |
1632 if (clip_star.state != SELECT_CLEARED) | |
1633 { | |
1634 if (clip_star.state == SELECT_DONE) | |
1635 clip_copy_modeless_selection(TRUE); | |
1636 goto cmdline_not_changed; | |
1637 } | |
1638 break; | |
1639 #endif | |
1640 | |
1641 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1642 case Ctrl_C: | |
571 | 1643 /* In exmode it doesn't make sense to return. Except when |
161 | 1644 * ":normal" runs out of characters. */ |
1645 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1646 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1647 goto cmdline_not_changed; |
1648 | |
1649 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1650 putting it in history */ | |
1651 goto returncmd; /* back to cmd mode */ | |
1652 | |
1653 case Ctrl_R: /* insert register */ | |
1654 #ifdef USE_ON_FLY_SCROLL | |
1655 dont_scroll = TRUE; /* disallow scrolling here */ | |
1656 #endif | |
1657 putcmdline('"', TRUE); | |
1658 ++no_mapping; | |
1389 | 1659 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1660 if (i == Ctrl_O) |
1661 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1662 if (i == Ctrl_R) | |
1389 | 1663 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
|
1664 extra_char = NUL; |
7 | 1665 --no_mapping; |
1666 #ifdef FEAT_EVAL | |
1667 /* | |
1668 * Insert the result of an expression. | |
1669 * Need to save the current command line, to be able to enter | |
1670 * a new one... | |
1671 */ | |
1672 new_cmdpos = -1; | |
1673 if (c == '=') | |
1674 { | |
1675 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1676 { | |
1677 beep_flush(); | |
1678 c = ESC; | |
1679 } | |
1680 else | |
1681 { | |
95 | 1682 save_cmdline(&save_ccline); |
7 | 1683 c = get_expr_register(); |
95 | 1684 restore_cmdline(&save_ccline); |
7 | 1685 } |
1686 } | |
1687 #endif | |
1688 if (c != ESC) /* use ESC to cancel inserting register */ | |
1689 { | |
1015 | 1690 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1691 |
613 | 1692 #ifdef FEAT_EVAL |
606 | 1693 /* When there was a serious error abort getting the |
1694 * command line. */ | |
1695 if (aborting()) | |
1696 { | |
1697 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1698 putting it in history */ | |
1699 goto returncmd; /* back to cmd mode */ | |
1700 } | |
613 | 1701 #endif |
7 | 1702 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1703 #ifdef FEAT_EVAL | |
1704 if (new_cmdpos >= 0) | |
1705 { | |
1706 /* set_cmdline_pos() was used */ | |
1707 if (new_cmdpos > ccline.cmdlen) | |
1708 ccline.cmdpos = ccline.cmdlen; | |
1709 else | |
1710 ccline.cmdpos = new_cmdpos; | |
1711 } | |
1712 #endif | |
1713 } | |
1714 redrawcmd(); | |
1715 goto cmdline_changed; | |
1716 | |
1717 case Ctrl_D: | |
1718 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1719 break; /* Use ^D as normal char instead */ | |
1720 | |
1721 redrawcmd(); | |
1722 continue; /* don't do incremental search now */ | |
1723 | |
1724 case K_RIGHT: | |
1725 case K_S_RIGHT: | |
1726 case K_C_RIGHT: | |
1727 do | |
1728 { | |
1729 if (ccline.cmdpos >= ccline.cmdlen) | |
1730 break; | |
1731 i = cmdline_charsize(ccline.cmdpos); | |
1732 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1733 break; | |
1734 ccline.cmdspos += i; | |
1735 #ifdef FEAT_MBYTE | |
1736 if (has_mbyte) | |
474 | 1737 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1738 + ccline.cmdpos); |
1739 else | |
1740 #endif | |
1741 ++ccline.cmdpos; | |
1742 } | |
180 | 1743 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1744 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1745 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1746 #ifdef FEAT_MBYTE | |
1747 if (has_mbyte) | |
1748 set_cmdspos_cursor(); | |
1749 #endif | |
1750 goto cmdline_not_changed; | |
1751 | |
1752 case K_LEFT: | |
1753 case K_S_LEFT: | |
1754 case K_C_LEFT: | |
1456 | 1755 if (ccline.cmdpos == 0) |
1756 goto cmdline_not_changed; | |
7 | 1757 do |
1758 { | |
1759 --ccline.cmdpos; | |
1760 #ifdef FEAT_MBYTE | |
1761 if (has_mbyte) /* move to first byte of char */ | |
1762 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1763 ccline.cmdbuff + ccline.cmdpos); | |
1764 #endif | |
1765 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1766 } | |
1456 | 1767 while (ccline.cmdpos > 0 |
1768 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1769 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1770 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1771 #ifdef FEAT_MBYTE | |
1772 if (has_mbyte) | |
1773 set_cmdspos_cursor(); | |
1774 #endif | |
1775 goto cmdline_not_changed; | |
1776 | |
1777 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
|
1778 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1779 goto cmdline_not_changed; |
7 | 1780 |
625 | 1781 #ifdef FEAT_GUI_W32 |
1782 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1783 * cancelled. */ | |
1784 case K_F4: | |
1785 if (mod_mask == MOD_MASK_ALT) | |
1786 { | |
1787 redrawcmd(); /* somehow the cmdline is cleared */ | |
1788 goto cmdline_not_changed; | |
1789 } | |
1790 break; | |
1791 #endif | |
1792 | |
7 | 1793 #ifdef FEAT_MOUSE |
1794 case K_MIDDLEDRAG: | |
1795 case K_MIDDLERELEASE: | |
1796 goto cmdline_not_changed; /* Ignore mouse */ | |
1797 | |
1798 case K_MIDDLEMOUSE: | |
1799 # ifdef FEAT_GUI | |
1800 /* When GUI is active, also paste when 'mouse' is empty */ | |
1801 if (!gui.in_use) | |
1802 # endif | |
1803 if (!mouse_has(MOUSE_COMMAND)) | |
1804 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1805 # ifdef FEAT_CLIPBOARD |
7 | 1806 if (clip_star.available) |
1015 | 1807 cmdline_paste('*', TRUE, TRUE); |
7 | 1808 else |
692 | 1809 # endif |
1015 | 1810 cmdline_paste(0, TRUE, TRUE); |
7 | 1811 redrawcmd(); |
1812 goto cmdline_changed; | |
1813 | |
692 | 1814 # ifdef FEAT_DND |
7 | 1815 case K_DROP: |
1015 | 1816 cmdline_paste('~', TRUE, FALSE); |
7 | 1817 redrawcmd(); |
1818 goto cmdline_changed; | |
692 | 1819 # endif |
7 | 1820 |
1821 case K_LEFTDRAG: | |
1822 case K_LEFTRELEASE: | |
1823 case K_RIGHTDRAG: | |
1824 case K_RIGHTRELEASE: | |
1825 /* Ignore drag and release events when the button-down wasn't | |
1826 * seen before. */ | |
1827 if (ignore_drag_release) | |
1828 goto cmdline_not_changed; | |
1829 /* FALLTHROUGH */ | |
1830 case K_LEFTMOUSE: | |
1831 case K_RIGHTMOUSE: | |
1832 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1833 ignore_drag_release = TRUE; | |
1834 else | |
1835 ignore_drag_release = FALSE; | |
1836 # ifdef FEAT_GUI | |
1837 /* When GUI is active, also move when 'mouse' is empty */ | |
1838 if (!gui.in_use) | |
1839 # endif | |
1840 if (!mouse_has(MOUSE_COMMAND)) | |
1841 goto cmdline_not_changed; /* Ignore mouse */ | |
1842 # ifdef FEAT_CLIPBOARD | |
1843 if (mouse_row < cmdline_row && clip_star.available) | |
1844 { | |
1845 int button, is_click, is_drag; | |
1846 | |
1847 /* | |
1848 * Handle modeless selection. | |
1849 */ | |
1850 button = get_mouse_button(KEY2TERMCAP1(c), | |
1851 &is_click, &is_drag); | |
1852 if (mouse_model_popup() && button == MOUSE_LEFT | |
1853 && (mod_mask & MOD_MASK_SHIFT)) | |
1854 { | |
1855 /* Translate shift-left to right button. */ | |
1856 button = MOUSE_RIGHT; | |
1857 mod_mask &= ~MOD_MASK_SHIFT; | |
1858 } | |
1859 clip_modeless(button, is_click, is_drag); | |
1860 goto cmdline_not_changed; | |
1861 } | |
1862 # endif | |
1863 | |
1864 set_cmdspos(); | |
1865 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1866 ++ccline.cmdpos) | |
1867 { | |
1868 i = cmdline_charsize(ccline.cmdpos); | |
1869 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1870 && mouse_col < ccline.cmdspos % Columns + i) | |
1871 break; | |
692 | 1872 # ifdef FEAT_MBYTE |
7 | 1873 if (has_mbyte) |
1874 { | |
1875 /* Count ">" for double-wide char that doesn't fit. */ | |
1876 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1877 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1878 + ccline.cmdpos) - 1; |
1879 } | |
692 | 1880 # endif |
7 | 1881 ccline.cmdspos += i; |
1882 } | |
1883 goto cmdline_not_changed; | |
1884 | |
1885 /* Mouse scroll wheel: ignored here */ | |
1886 case K_MOUSEDOWN: | |
1887 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1888 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1889 case K_MOUSERIGHT: |
7 | 1890 /* Alternate buttons ignored here */ |
1891 case K_X1MOUSE: | |
1892 case K_X1DRAG: | |
1893 case K_X1RELEASE: | |
1894 case K_X2MOUSE: | |
1895 case K_X2DRAG: | |
1896 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1897 case K_MOUSEMOVE: |
7 | 1898 goto cmdline_not_changed; |
1899 | |
1900 #endif /* FEAT_MOUSE */ | |
1901 | |
1902 #ifdef FEAT_GUI | |
1903 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1904 case K_LEFTRELEASE_NM: | |
1905 goto cmdline_not_changed; | |
1906 | |
1907 case K_VER_SCROLLBAR: | |
540 | 1908 if (msg_scrolled == 0) |
7 | 1909 { |
1910 gui_do_scroll(); | |
1911 redrawcmd(); | |
1912 } | |
1913 goto cmdline_not_changed; | |
1914 | |
1915 case K_HOR_SCROLLBAR: | |
540 | 1916 if (msg_scrolled == 0) |
7 | 1917 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1918 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1919 redrawcmd(); |
1920 } | |
1921 goto cmdline_not_changed; | |
1922 #endif | |
692 | 1923 #ifdef FEAT_GUI_TABLINE |
1924 case K_TABLINE: | |
1925 case K_TABMENU: | |
1926 /* Don't want to change any tabs here. Make sure the same tab | |
1927 * is still selected. */ | |
1928 if (gui_use_tabline()) | |
1929 gui_mch_set_curtab(tabpage_index(curtab)); | |
1930 goto cmdline_not_changed; | |
1931 #endif | |
1932 | |
7 | 1933 case K_SELECT: /* end of Select mode mapping - ignore */ |
1934 goto cmdline_not_changed; | |
1935 | |
1936 case Ctrl_B: /* begin of command line */ | |
1937 case K_HOME: | |
1938 case K_KHOME: | |
1939 case K_S_HOME: | |
1940 case K_C_HOME: | |
1941 ccline.cmdpos = 0; | |
1942 set_cmdspos(); | |
1943 goto cmdline_not_changed; | |
1944 | |
1945 case Ctrl_E: /* end of command line */ | |
1946 case K_END: | |
1947 case K_KEND: | |
1948 case K_S_END: | |
1949 case K_C_END: | |
1950 ccline.cmdpos = ccline.cmdlen; | |
1951 set_cmdspos_cursor(); | |
1952 goto cmdline_not_changed; | |
1953 | |
1954 case Ctrl_A: /* all matches */ | |
3961 | 1955 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1956 break; |
1957 goto cmdline_changed; | |
1958 | |
772 | 1959 case Ctrl_L: |
1960 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1961 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 1962 goto cmdline_not_changed; |
1963 #endif | |
1964 | |
1965 /* completion: longest common part */ | |
3961 | 1966 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 1967 break; |
1968 goto cmdline_changed; | |
1969 | |
1970 case Ctrl_N: /* next match */ | |
1971 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
1972 if (xpc.xp_numfiles > 0) |
7 | 1973 { |
3961 | 1974 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
1975 0, firstc != '@') == FAIL) | |
7 | 1976 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1977 goto cmdline_not_changed; |
7 | 1978 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
1979 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1980 /* FALLTHROUGH */ |
7 | 1981 case K_UP: |
1982 case K_DOWN: | |
1983 case K_S_UP: | |
1984 case K_S_DOWN: | |
1985 case K_PAGEUP: | |
1986 case K_KPAGEUP: | |
1987 case K_PAGEDOWN: | |
1988 case K_KPAGEDOWN: | |
1989 if (hislen == 0 || firstc == NUL) /* no history */ | |
1990 goto cmdline_not_changed; | |
1991 | |
1992 i = hiscnt; | |
1993 | |
1994 /* save current command string so it can be restored later */ | |
1995 if (lookfor == NULL) | |
1996 { | |
1997 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
1998 goto cmdline_not_changed; | |
1999 lookfor[ccline.cmdpos] = NUL; | |
2000 } | |
2001 | |
2002 j = (int)STRLEN(lookfor); | |
2003 for (;;) | |
2004 { | |
2005 /* one step backwards */ | |
230 | 2006 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2007 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2008 { |
2009 if (hiscnt == hislen) /* first time */ | |
2010 hiscnt = hisidx[histype]; | |
2011 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2012 hiscnt = hislen - 1; | |
2013 else if (hiscnt != hisidx[histype] + 1) | |
2014 --hiscnt; | |
2015 else /* at top of list */ | |
2016 { | |
2017 hiscnt = i; | |
2018 break; | |
2019 } | |
2020 } | |
2021 else /* one step forwards */ | |
2022 { | |
2023 /* on last entry, clear the line */ | |
2024 if (hiscnt == hisidx[histype]) | |
2025 { | |
2026 hiscnt = hislen; | |
2027 break; | |
2028 } | |
2029 | |
2030 /* not on a history line, nothing to do */ | |
2031 if (hiscnt == hislen) | |
2032 break; | |
2033 if (hiscnt == hislen - 1) /* wrap around */ | |
2034 hiscnt = 0; | |
2035 else | |
2036 ++hiscnt; | |
2037 } | |
2038 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2039 { | |
2040 hiscnt = i; | |
2041 break; | |
2042 } | |
230 | 2043 if ((c != K_UP && c != K_DOWN) |
180 | 2044 || hiscnt == i |
7 | 2045 || STRNCMP(history[histype][hiscnt].hisstr, |
2046 lookfor, (size_t)j) == 0) | |
2047 break; | |
2048 } | |
2049 | |
2050 if (hiscnt != i) /* jumped to other entry */ | |
2051 { | |
2052 char_u *p; | |
2053 int len; | |
2054 int old_firstc; | |
2055 | |
2056 vim_free(ccline.cmdbuff); | |
1718 | 2057 xpc.xp_context = EXPAND_NOTHING; |
7 | 2058 if (hiscnt == hislen) |
2059 p = lookfor; /* back to the old one */ | |
2060 else | |
2061 p = history[histype][hiscnt].hisstr; | |
2062 | |
2063 if (histype == HIST_SEARCH | |
2064 && p != lookfor | |
2065 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2066 { | |
2067 /* Correct for the separator character used when | |
2068 * adding the history entry vs the one used now. | |
2069 * First loop: count length. | |
2070 * Second loop: copy the characters. */ | |
2071 for (i = 0; i <= 1; ++i) | |
2072 { | |
2073 len = 0; | |
2074 for (j = 0; p[j] != NUL; ++j) | |
2075 { | |
2076 /* Replace old sep with new sep, unless it is | |
2077 * escaped. */ | |
2078 if (p[j] == old_firstc | |
2079 && (j == 0 || p[j - 1] != '\\')) | |
2080 { | |
2081 if (i > 0) | |
2082 ccline.cmdbuff[len] = firstc; | |
2083 } | |
2084 else | |
2085 { | |
2086 /* Escape new sep, unless it is already | |
2087 * escaped. */ | |
2088 if (p[j] == firstc | |
2089 && (j == 0 || p[j - 1] != '\\')) | |
2090 { | |
2091 if (i > 0) | |
2092 ccline.cmdbuff[len] = '\\'; | |
2093 ++len; | |
2094 } | |
2095 if (i > 0) | |
2096 ccline.cmdbuff[len] = p[j]; | |
2097 } | |
2098 ++len; | |
2099 } | |
2100 if (i == 0) | |
2101 { | |
2102 alloc_cmdbuff(len); | |
2103 if (ccline.cmdbuff == NULL) | |
2104 goto returncmd; | |
2105 } | |
2106 } | |
2107 ccline.cmdbuff[len] = NUL; | |
2108 } | |
2109 else | |
2110 { | |
2111 alloc_cmdbuff((int)STRLEN(p)); | |
2112 if (ccline.cmdbuff == NULL) | |
2113 goto returncmd; | |
2114 STRCPY(ccline.cmdbuff, p); | |
2115 } | |
2116 | |
2117 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2118 redrawcmd(); | |
2119 goto cmdline_changed; | |
2120 } | |
2121 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2122 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2123 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2124 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2125 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2126 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2127 case Ctrl_T: /* previous match */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2128 if (may_adjust_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2129 firstc, count, &is_state, c) == FAIL) |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2130 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2131 break; |
7 | 2132 #endif |
2133 | |
2134 case Ctrl_V: | |
2135 case Ctrl_Q: | |
2136 #ifdef FEAT_MOUSE | |
2137 ignore_drag_release = TRUE; | |
2138 #endif | |
2139 putcmdline('^', TRUE); | |
2140 c = get_literal(); /* get next (two) character(s) */ | |
2141 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
|
2142 extra_char = NUL; |
7 | 2143 #ifdef FEAT_MBYTE |
2144 /* may need to remove ^ when composing char was typed */ | |
2145 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2146 { | |
2147 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2148 msg_putchar(' '); | |
2149 cursorcmd(); | |
2150 } | |
2151 #endif | |
2152 break; | |
2153 | |
2154 #ifdef FEAT_DIGRAPHS | |
2155 case Ctrl_K: | |
2156 #ifdef FEAT_MOUSE | |
2157 ignore_drag_release = TRUE; | |
2158 #endif | |
2159 putcmdline('?', TRUE); | |
2160 #ifdef USE_ON_FLY_SCROLL | |
2161 dont_scroll = TRUE; /* disallow scrolling here */ | |
2162 #endif | |
2163 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
|
2164 extra_char = NUL; |
7 | 2165 if (c != NUL) |
2166 break; | |
2167 | |
2168 redrawcmd(); | |
2169 goto cmdline_not_changed; | |
2170 #endif /* FEAT_DIGRAPHS */ | |
2171 | |
2172 #ifdef FEAT_RIGHTLEFT | |
2173 case Ctrl__: /* CTRL-_: switch language mode */ | |
2174 if (!p_ari) | |
2175 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2176 # ifdef FEAT_FKMAP |
7 | 2177 if (p_altkeymap) |
2178 { | |
2179 cmd_fkmap = !cmd_fkmap; | |
2180 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2181 ccline.overstrike = FALSE; | |
2182 } | |
2183 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2184 # endif |
7 | 2185 cmd_hkmap = !cmd_hkmap; |
2186 goto cmdline_not_changed; | |
2187 #endif | |
2188 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2189 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
|
2190 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
|
2191 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
|
2192 |
7 | 2193 default: |
2194 #ifdef UNIX | |
2195 if (c == intr_char) | |
2196 { | |
2197 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2198 putting it in history */ | |
2199 goto returncmd; /* back to Normal mode */ | |
2200 } | |
2201 #endif | |
2202 /* | |
2203 * Normal character with no special meaning. Just set mod_mask | |
2204 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2205 * the string <S-Space>. This should only happen after ^V. | |
2206 */ | |
2207 if (!IS_SPECIAL(c)) | |
2208 mod_mask = 0x0; | |
2209 break; | |
2210 } | |
2211 /* | |
2212 * End of switch on command line character. | |
2213 * We come here if we have a normal character. | |
2214 */ | |
2215 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2216 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2217 #ifdef FEAT_MBYTE |
2218 /* Add ABBR_OFF for characters above 0x100, this is | |
2219 * what check_abbr() expects. */ | |
2220 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2221 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2222 c) || c == Ctrl_RSB)) |
7 | 2223 goto cmdline_changed; |
2224 | |
2225 /* | |
2226 * put the character in the command line | |
2227 */ | |
2228 if (IS_SPECIAL(c) || mod_mask != 0) | |
2229 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2230 else | |
2231 { | |
2232 #ifdef FEAT_MBYTE | |
2233 if (has_mbyte) | |
2234 { | |
2235 j = (*mb_char2bytes)(c, IObuff); | |
2236 IObuff[j] = NUL; /* exclude composing chars */ | |
2237 put_on_cmdline(IObuff, j, TRUE); | |
2238 } | |
2239 else | |
2240 #endif | |
2241 { | |
2242 IObuff[0] = c; | |
2243 put_on_cmdline(IObuff, 1, TRUE); | |
2244 } | |
2245 } | |
2246 goto cmdline_changed; | |
2247 | |
2248 /* | |
2249 * This part implements incremental searches for "/" and "?" | |
2250 * Jump to cmdline_not_changed when a character has been read but the command | |
2251 * line did not change. Then we only search and redraw if something changed in | |
2252 * the past. | |
2253 * Jump to cmdline_changed when the command line did change. | |
2254 * (Sorry for the goto's, I know it is ugly). | |
2255 */ | |
2256 cmdline_not_changed: | |
2257 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2258 if (!is_state.incsearch_postponed) |
7 | 2259 continue; |
2260 #endif | |
2261 | |
2262 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
|
2263 /* 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
|
2264 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
|
2265 |
7 | 2266 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2267 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2268 #endif |
2269 | |
2270 #ifdef FEAT_RIGHTLEFT | |
2271 if (cmdmsg_rl | |
2272 # ifdef FEAT_ARABIC | |
534 | 2273 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2274 # endif |
2275 ) | |
2276 /* Always redraw the whole command line to fix shaping and | |
3374 | 2277 * right-left typing. Not efficient, but it works. |
2278 * Do it only when there are no characters left to read | |
2279 * to avoid useless intermediate redraws. */ | |
2280 if (vpeekc() == NUL) | |
2281 redrawcmd(); | |
7 | 2282 #endif |
2283 } | |
2284 | |
2285 returncmd: | |
2286 | |
2287 #ifdef FEAT_RIGHTLEFT | |
2288 cmdmsg_rl = FALSE; | |
2289 #endif | |
2290 | |
2291 #ifdef FEAT_FKMAP | |
2292 cmd_fkmap = 0; | |
2293 #endif | |
2294 | |
2295 ExpandCleanup(&xpc); | |
1718 | 2296 ccline.xpc = NULL; |
7 | 2297 |
2298 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2299 finish_incsearch_highlighting(gotesc, &is_state); |
7 | 2300 #endif |
2301 | |
2302 if (ccline.cmdbuff != NULL) | |
2303 { | |
2304 /* | |
2305 * Put line in history buffer (":" and "=" only when it was typed). | |
2306 */ | |
2307 #ifdef FEAT_CMDHIST | |
2308 if (ccline.cmdlen && firstc != NUL | |
2309 && (some_key_typed || histype == HIST_SEARCH)) | |
2310 { | |
2311 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2312 histype == HIST_SEARCH ? firstc : NUL); | |
2313 if (firstc == ':') | |
2314 { | |
2315 vim_free(new_last_cmdline); | |
2316 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2317 } | |
2318 } | |
2319 #endif | |
2320 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2321 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
|
2322 abandon_cmdline(); |
7 | 2323 } |
2324 | |
2325 /* | |
2326 * If the screen was shifted up, redraw the whole screen (later). | |
2327 * If the line is too long, clear it, so ruler and shown command do | |
2328 * not get printed in the middle of it. | |
2329 */ | |
2330 msg_check(); | |
2331 msg_scroll = save_msg_scroll; | |
2332 redir_off = FALSE; | |
2333 | |
2334 /* When the command line was typed, no need for a wait-return prompt. */ | |
2335 if (some_key_typed) | |
2336 need_wait_return = FALSE; | |
2337 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2338 /* 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
|
2339 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
|
2340 |
7 | 2341 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2342 #ifdef HAVE_INPUT_METHOD |
7 | 2343 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2344 im_save_status(b_im_ptr); | |
2345 im_set_active(FALSE); | |
2346 #endif | |
2347 #ifdef FEAT_MOUSE | |
2348 setmouse(); | |
2349 #endif | |
2350 #ifdef CURSOR_SHAPE | |
2351 ui_cursor_shape(); /* may show different cursor shape */ | |
2352 #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
|
2353 sb_text_end_cmdline(); |
7 | 2354 |
95 | 2355 { |
2356 char_u *p = ccline.cmdbuff; | |
2357 | |
2358 /* Make ccline empty, getcmdline() may try to use it. */ | |
2359 ccline.cmdbuff = NULL; | |
2360 return p; | |
2361 } | |
7 | 2362 } |
2363 | |
2364 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2365 /* | |
2366 * Get a command line with a prompt. | |
2367 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2368 * f_input() when evaluating an expression from CTRL-R =). | |
2369 * Returns the command line in allocated memory, or NULL. | |
2370 */ | |
2371 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2372 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2373 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2374 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2375 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2376 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2377 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2378 { |
2379 char_u *s; | |
2380 struct cmdline_info save_ccline; | |
2381 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
|
2382 int msg_silent_save = msg_silent; |
7 | 2383 |
95 | 2384 save_cmdline(&save_ccline); |
7 | 2385 ccline.cmdprompt = prompt; |
2386 ccline.cmdattr = attr; | |
531 | 2387 # ifdef FEAT_EVAL |
2388 ccline.xp_context = xp_context; | |
2389 ccline.xp_arg = xp_arg; | |
2390 ccline.input_fn = (firstc == '@'); | |
2391 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2392 msg_silent = 0; |
7 | 2393 s = getcmdline(firstc, 1L, 0); |
95 | 2394 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2395 msg_silent = msg_silent_save; |
3020 | 2396 /* Restore msg_col, the prompt from input() may have changed it. |
2397 * But only if called recursively and the commandline is therefore being | |
2398 * restored to an old one; if not, the input() prompt stays on the screen, | |
2399 * so we need its modified msg_col left intact. */ | |
2400 if (ccline.cmdbuff != NULL) | |
2401 msg_col = msg_col_save; | |
7 | 2402 |
2403 return s; | |
2404 } | |
2405 #endif | |
2406 | |
632 | 2407 /* |
634 | 2408 * Return TRUE when the text must not be changed and we can't switch to |
2409 * another window or buffer. Used when editing the command line, evaluating | |
2410 * 'balloonexpr', etc. | |
632 | 2411 */ |
2412 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2413 text_locked(void) |
632 | 2414 { |
2415 #ifdef FEAT_CMDWIN | |
2416 if (cmdwin_type != 0) | |
2417 return TRUE; | |
2418 #endif | |
634 | 2419 return textlock != 0; |
632 | 2420 } |
2421 | |
2422 /* | |
2423 * Give an error message for a command that isn't allowed while the cmdline | |
2424 * window is open or editing the cmdline in another way. | |
2425 */ | |
2426 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2427 text_locked_msg(void) |
632 | 2428 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2429 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2430 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2431 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2432 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2433 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2434 { |
632 | 2435 #ifdef FEAT_CMDWIN |
2436 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2437 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2438 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2439 return e_secure; |
632 | 2440 } |
2441 | |
819 | 2442 /* |
1834 | 2443 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2444 * and give an error message. | |
819 | 2445 */ |
2446 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2447 curbuf_locked(void) |
819 | 2448 { |
2449 if (curbuf_lock > 0) | |
2450 { | |
2451 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2452 return TRUE; | |
2453 } | |
1834 | 2454 return allbuf_locked(); |
2455 } | |
2456 | |
2457 /* | |
2458 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2459 * message. | |
2460 */ | |
2461 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2462 allbuf_locked(void) |
1834 | 2463 { |
2464 if (allbuf_lock > 0) | |
2465 { | |
2466 EMSG(_("E811: Not allowed to change buffer information now")); | |
2467 return TRUE; | |
2468 } | |
819 | 2469 return FALSE; |
2470 } | |
2471 | |
7 | 2472 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2473 cmdline_charsize(int idx) |
7 | 2474 { |
2475 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2476 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2477 return 1; | |
2478 #endif | |
2479 return ptr2cells(ccline.cmdbuff + idx); | |
2480 } | |
2481 | |
2482 /* | |
2483 * Compute the offset of the cursor on the command line for the prompt and | |
2484 * indent. | |
2485 */ | |
2486 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2487 set_cmdspos(void) |
7 | 2488 { |
531 | 2489 if (ccline.cmdfirstc != NUL) |
7 | 2490 ccline.cmdspos = 1 + ccline.cmdindent; |
2491 else | |
2492 ccline.cmdspos = 0 + ccline.cmdindent; | |
2493 } | |
2494 | |
2495 /* | |
2496 * Compute the screen position for the cursor on the command line. | |
2497 */ | |
2498 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2499 set_cmdspos_cursor(void) |
7 | 2500 { |
2501 int i, m, c; | |
2502 | |
2503 set_cmdspos(); | |
2504 if (KeyTyped) | |
534 | 2505 { |
7 | 2506 m = Columns * Rows; |
534 | 2507 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2508 m = MAXCOL; | |
2509 } | |
7 | 2510 else |
2511 m = MAXCOL; | |
2512 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2513 { | |
2514 c = cmdline_charsize(i); | |
2515 #ifdef FEAT_MBYTE | |
2516 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2517 if (has_mbyte) | |
2518 correct_cmdspos(i, c); | |
2519 #endif | |
1612 | 2520 /* If the cmdline doesn't fit, show cursor on last visible char. |
2521 * Don't move the cursor itself, so we can still append. */ | |
7 | 2522 if ((ccline.cmdspos += c) >= m) |
2523 { | |
2524 ccline.cmdspos -= c; | |
2525 break; | |
2526 } | |
2527 #ifdef FEAT_MBYTE | |
2528 if (has_mbyte) | |
474 | 2529 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2530 #endif |
2531 } | |
2532 } | |
2533 | |
2534 #ifdef FEAT_MBYTE | |
2535 /* | |
2536 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2537 * character that doesn't fit, so that a ">" must be displayed. | |
2538 */ | |
2539 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2540 correct_cmdspos(int idx, int cells) |
7 | 2541 { |
474 | 2542 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2543 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2544 && ccline.cmdspos % Columns + cells > Columns) | |
2545 ccline.cmdspos++; | |
2546 } | |
2547 #endif | |
2548 | |
2549 /* | |
2550 * Get an Ex command line for the ":" command. | |
2551 */ | |
2552 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2553 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2554 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2555 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2556 int indent) /* indent for inside conditionals */ |
7 | 2557 { |
2558 /* When executing a register, remove ':' that's in front of each line. */ | |
2559 if (exec_from_reg && vpeekc() == ':') | |
2560 (void)vgetc(); | |
2561 return getcmdline(c, 1L, indent); | |
2562 } | |
2563 | |
2564 /* | |
2565 * Get an Ex command line for Ex mode. | |
2566 * In Ex mode we only use the OS supplied line editing features and no | |
2567 * mappings or abbreviations. | |
168 | 2568 * Returns a string in allocated memory or NULL. |
7 | 2569 */ |
2570 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2571 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2572 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2573 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2574 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2575 int indent) /* indent for inside conditionals */ |
7 | 2576 { |
168 | 2577 garray_T line_ga; |
2578 char_u *pend; | |
2579 int startcol = 0; | |
1329 | 2580 int c1 = 0; |
168 | 2581 int escaped = FALSE; /* CTRL-V typed */ |
2582 int vcol = 0; | |
2583 char_u *p; | |
1329 | 2584 int prev_char; |
5966 | 2585 int len; |
7 | 2586 |
2587 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2588 * confuses the system function that computes tabstops. */ | |
2589 cursor_on(); | |
2590 | |
2591 /* always start in column 0; write a newline if necessary */ | |
2592 compute_cmdrow(); | |
168 | 2593 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2594 msg_putchar('\n'); |
168 | 2595 if (promptc == ':') |
7 | 2596 { |
164 | 2597 /* indent that is only displayed, not in the line itself */ |
168 | 2598 if (p_prompt) |
2599 msg_putchar(':'); | |
7 | 2600 while (indent-- > 0) |
2601 msg_putchar(' '); | |
2602 startcol = msg_col; | |
2603 } | |
2604 | |
2605 ga_init2(&line_ga, 1, 30); | |
2606 | |
164 | 2607 /* autoindent for :insert and :append is in the line itself */ |
168 | 2608 if (promptc <= 0) |
164 | 2609 { |
2610 vcol = indent; | |
2611 while (indent >= 8) | |
2612 { | |
2613 ga_append(&line_ga, TAB); | |
2614 msg_puts((char_u *)" "); | |
2615 indent -= 8; | |
2616 } | |
2617 while (indent-- > 0) | |
2618 { | |
2619 ga_append(&line_ga, ' '); | |
2620 msg_putchar(' '); | |
2621 } | |
2622 } | |
168 | 2623 ++no_mapping; |
2624 ++allow_keys; | |
164 | 2625 |
7 | 2626 /* |
2627 * Get the line, one character at a time. | |
2628 */ | |
2629 got_int = FALSE; | |
168 | 2630 while (!got_int) |
7 | 2631 { |
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
|
2632 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
|
2633 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
|
2634 |
7 | 2635 if (ga_grow(&line_ga, 40) == FAIL) |
2636 break; | |
2637 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2638 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2639 * 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
|
2640 */ |
1329 | 2641 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
|
2642 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2643 /* 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
|
2644 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
|
2645 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
|
2646 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2647 c1 = vgetc(); |
7 | 2648 |
2649 /* | |
168 | 2650 * Handle line editing. |
2651 * Previously this was left to the system, putting the terminal in | |
2652 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2653 */ |
168 | 2654 if (got_int) |
2655 { | |
2656 msg_putchar('\n'); | |
2657 break; | |
2658 } | |
2659 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2660 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
|
2661 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2662 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
|
2663 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
|
2664 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2665 |
168 | 2666 if (!escaped) |
7 | 2667 { |
168 | 2668 /* CR typed means "enter", which is NL */ |
2669 if (c1 == '\r') | |
2670 c1 = '\n'; | |
2671 | |
2672 if (c1 == BS || c1 == K_BS | |
2673 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2674 { |
168 | 2675 if (line_ga.ga_len > 0) |
2676 { | |
5966 | 2677 #ifdef FEAT_MBYTE |
2678 if (has_mbyte) | |
2679 { | |
2680 p = (char_u *)line_ga.ga_data; | |
2681 p[line_ga.ga_len] = NUL; | |
2682 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2683 line_ga.ga_len -= len; | |
2684 } | |
2685 else | |
2686 #endif | |
2687 --line_ga.ga_len; | |
168 | 2688 goto redraw; |
2689 } | |
2690 continue; | |
7 | 2691 } |
2692 | |
168 | 2693 if (c1 == Ctrl_U) |
7 | 2694 { |
168 | 2695 msg_col = startcol; |
2696 msg_clr_eos(); | |
2697 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
|
2698 goto redraw; |
168 | 2699 } |
2700 | |
2701 if (c1 == Ctrl_T) | |
2702 { | |
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
|
2703 sw = get_sw_value(curbuf); |
168 | 2704 p = (char_u *)line_ga.ga_data; |
2705 p[line_ga.ga_len] = NUL; | |
5995 | 2706 indent = get_indent_str(p, 8, FALSE); |
3740 | 2707 indent += sw - indent % sw; |
168 | 2708 add_indent: |
5995 | 2709 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2710 { |
7009 | 2711 (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
|
2712 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
|
2713 s = skipwhite(p); |
168 | 2714 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2715 *s = ' '; | |
2716 ++line_ga.ga_len; | |
7 | 2717 } |
168 | 2718 redraw: |
2719 /* redraw the line */ | |
2720 msg_col = startcol; | |
2721 vcol = 0; | |
5966 | 2722 p = (char_u *)line_ga.ga_data; |
2723 p[line_ga.ga_len] = NUL; | |
2724 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2725 { |
168 | 2726 if (*p == TAB) |
7 | 2727 { |
168 | 2728 do |
7 | 2729 { |
168 | 2730 msg_putchar(' '); |
2731 } while (++vcol % 8); | |
5966 | 2732 ++p; |
7 | 2733 } |
168 | 2734 else |
164 | 2735 { |
5966 | 2736 len = MB_PTR2LEN(p); |
2737 msg_outtrans_len(p, len); | |
2738 vcol += ptr2cells(p); | |
2739 p += len; | |
7 | 2740 } |
2741 } | |
168 | 2742 msg_clr_eos(); |
1329 | 2743 windgoto(msg_row, msg_col); |
168 | 2744 continue; |
2745 } | |
2746 | |
2747 if (c1 == Ctrl_D) | |
2748 { | |
2749 /* Delete one shiftwidth. */ | |
2750 p = (char_u *)line_ga.ga_data; | |
2751 if (prev_char == '0' || prev_char == '^') | |
7 | 2752 { |
168 | 2753 if (prev_char == '^') |
2754 ex_keep_indent = TRUE; | |
2755 indent = 0; | |
2756 p[--line_ga.ga_len] = NUL; | |
7 | 2757 } |
2758 else | |
2759 { | |
168 | 2760 p[line_ga.ga_len] = NUL; |
5995 | 2761 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
|
2762 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
|
2763 { |
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
|
2764 --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
|
2765 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
|
2766 } |
168 | 2767 } |
5995 | 2768 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2769 { |
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
|
2770 s = skipwhite(p); |
168 | 2771 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2772 --line_ga.ga_len; | |
7 | 2773 } |
168 | 2774 goto add_indent; |
2775 } | |
2776 | |
2777 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2778 { | |
2779 escaped = TRUE; | |
2780 continue; | |
7 | 2781 } |
168 | 2782 |
2783 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2784 if (IS_SPECIAL(c1)) | |
2785 continue; | |
7 | 2786 } |
168 | 2787 |
2788 if (IS_SPECIAL(c1)) | |
2789 c1 = '?'; | |
5966 | 2790 #ifdef FEAT_MBYTE |
2791 if (has_mbyte) | |
2792 len = (*mb_char2bytes)(c1, | |
2793 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2794 else | |
2795 #endif | |
2796 { | |
2797 len = 1; | |
2798 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2799 } | |
168 | 2800 if (c1 == '\n') |
2801 msg_putchar('\n'); | |
2802 else if (c1 == TAB) | |
2803 { | |
2804 /* Don't use chartabsize(), 'ts' can be different */ | |
2805 do | |
2806 { | |
2807 msg_putchar(' '); | |
2808 } while (++vcol % 8); | |
2809 } | |
7 | 2810 else |
2811 { | |
168 | 2812 msg_outtrans_len( |
5966 | 2813 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2814 vcol += char2cells(c1); |
7 | 2815 } |
5966 | 2816 line_ga.ga_len += len; |
168 | 2817 escaped = FALSE; |
2818 | |
2819 windgoto(msg_row, msg_col); | |
164 | 2820 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2821 |
2590 | 2822 /* We are done when a NL is entered, but not when it comes after an |
2823 * odd number of backslashes, that results in a NUL. */ | |
2824 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2825 { |
2590 | 2826 int bcount = 0; |
2827 | |
2828 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2829 ++bcount; | |
2830 | |
2831 if (bcount > 0) | |
2832 { | |
2833 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2834 * "\NL", etc. */ | |
2835 line_ga.ga_len -= (bcount + 1) / 2; | |
2836 pend -= (bcount + 1) / 2; | |
2837 pend[-1] = '\n'; | |
2838 } | |
2839 | |
2840 if ((bcount & 1) == 0) | |
2841 { | |
2842 --line_ga.ga_len; | |
2843 --pend; | |
2844 *pend = NUL; | |
2845 break; | |
2846 } | |
7 | 2847 } |
2848 } | |
2849 | |
168 | 2850 --no_mapping; |
2851 --allow_keys; | |
2852 | |
7 | 2853 /* make following messages go to the next line */ |
2854 msg_didout = FALSE; | |
2855 msg_col = 0; | |
2856 if (msg_row < Rows - 1) | |
2857 ++msg_row; | |
2858 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2859 | |
2860 if (got_int) | |
2861 ga_clear(&line_ga); | |
2862 | |
2863 return (char_u *)line_ga.ga_data; | |
2864 } | |
2865 | |
502 | 2866 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2867 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2868 /* |
2869 * Return TRUE if ccline.overstrike is on. | |
2870 */ | |
2871 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2872 cmdline_overstrike(void) |
7 | 2873 { |
2874 return ccline.overstrike; | |
2875 } | |
2876 | |
2877 /* | |
2878 * Return TRUE if the cursor is at the end of the cmdline. | |
2879 */ | |
2880 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2881 cmdline_at_end(void) |
7 | 2882 { |
2883 return (ccline.cmdpos >= ccline.cmdlen); | |
2884 } | |
2885 #endif | |
2886 | |
574 | 2887 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2888 /* |
2889 * Return the virtual column number at the current cursor position. | |
2890 * This is used by the IM code to obtain the start of the preedit string. | |
2891 */ | |
2892 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2893 cmdline_getvcol_cursor(void) |
7 | 2894 { |
2895 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2896 return MAXCOL; | |
2897 | |
2898 # ifdef FEAT_MBYTE | |
2899 if (has_mbyte) | |
2900 { | |
2901 colnr_T col; | |
2902 int i = 0; | |
2903 | |
2904 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2905 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2906 |
2907 return col; | |
2908 } | |
2909 else | |
2910 # endif | |
2911 return ccline.cmdpos; | |
2912 } | |
2913 #endif | |
2914 | |
2915 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2916 /* | |
2917 * If part of the command line is an IM preedit string, redraw it with | |
2918 * IM feedback attributes. The cursor position is restored after drawing. | |
2919 */ | |
2920 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 redrawcmd_preedit(void) |
7 | 2922 { |
2923 if ((State & CMDLINE) | |
2924 && xic != NULL | |
976 | 2925 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2926 && !p_imdisable |
2927 && im_is_preediting()) | |
2928 { | |
2929 int cmdpos = 0; | |
2930 int cmdspos; | |
2931 int old_row; | |
2932 int old_col; | |
2933 colnr_T col; | |
2934 | |
2935 old_row = msg_row; | |
2936 old_col = msg_col; | |
531 | 2937 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2938 |
2939 # ifdef FEAT_MBYTE | |
2940 if (has_mbyte) | |
2941 { | |
2942 for (col = 0; col < preedit_start_col | |
2943 && cmdpos < ccline.cmdlen; ++col) | |
2944 { | |
2945 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2946 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2947 } |
2948 } | |
2949 else | |
2950 # endif | |
2951 { | |
2952 cmdspos += preedit_start_col; | |
2953 cmdpos += preedit_start_col; | |
2954 } | |
2955 | |
2956 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2957 msg_col = cmdspos % (int)Columns; | |
2958 if (msg_row >= Rows) | |
2959 msg_row = Rows - 1; | |
2960 | |
2961 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
2962 { | |
2963 int char_len; | |
2964 int char_attr; | |
2965 | |
2966 char_attr = im_get_feedback_attr(col); | |
2967 if (char_attr < 0) | |
2968 break; /* end of preedit string */ | |
2969 | |
2970 # ifdef FEAT_MBYTE | |
2971 if (has_mbyte) | |
474 | 2972 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2973 else |
2974 # endif | |
2975 char_len = 1; | |
2976 | |
2977 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
2978 cmdpos += char_len; | |
2979 } | |
2980 | |
2981 msg_row = old_row; | |
2982 msg_col = old_col; | |
2983 } | |
2984 } | |
2985 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
2986 | |
2987 /* | |
2988 * Allocate a new command line buffer. | |
2989 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
2990 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
2991 */ | |
2992 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2993 alloc_cmdbuff(int len) |
7 | 2994 { |
2995 /* | |
2996 * give some extra space to avoid having to allocate all the time | |
2997 */ | |
2998 if (len < 80) | |
2999 len = 100; | |
3000 else | |
3001 len += 20; | |
3002 | |
3003 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3004 ccline.cmdbufflen = len; | |
3005 } | |
3006 | |
3007 /* | |
3008 * Re-allocate the command line to length len + something extra. | |
3009 * return FAIL for failure, OK otherwise | |
3010 */ | |
3011 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3012 realloc_cmdbuff(int len) |
7 | 3013 { |
3014 char_u *p; | |
3015 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3016 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3017 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
|
3018 |
7 | 3019 p = ccline.cmdbuff; |
3020 alloc_cmdbuff(len); /* will get some more */ | |
3021 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3022 { | |
3023 ccline.cmdbuff = p; /* keep the old one */ | |
3024 return FAIL; | |
3025 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3026 /* 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
|
3027 * 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
|
3028 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
|
3029 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3030 vim_free(p); |
1718 | 3031 |
3032 if (ccline.xpc != NULL | |
3033 && ccline.xpc->xp_pattern != NULL | |
3034 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3035 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3036 { | |
1754 | 3037 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3038 |
3039 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3040 * to point into the newly allocated memory. */ | |
3041 if (i >= 0 && i <= ccline.cmdlen) | |
3042 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3043 } | |
3044 | |
7 | 3045 return OK; |
3046 } | |
3047 | |
359 | 3048 #if defined(FEAT_ARABIC) || defined(PROTO) |
3049 static char_u *arshape_buf = NULL; | |
3050 | |
3051 # if defined(EXITFREE) || defined(PROTO) | |
3052 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3053 free_cmdline_buf(void) |
359 | 3054 { |
3055 vim_free(arshape_buf); | |
3056 } | |
3057 # endif | |
3058 #endif | |
3059 | |
7 | 3060 /* |
3061 * Draw part of the cmdline at the current cursor position. But draw stars | |
3062 * when cmdline_star is TRUE. | |
3063 */ | |
3064 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3065 draw_cmdline(int start, int len) |
7 | 3066 { |
3067 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3068 int i; | |
3069 | |
3070 if (cmdline_star > 0) | |
3071 for (i = 0; i < len; ++i) | |
3072 { | |
3073 msg_putchar('*'); | |
3074 # ifdef FEAT_MBYTE | |
3075 if (has_mbyte) | |
474 | 3076 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3077 # endif |
3078 } | |
3079 else | |
3080 #endif | |
3081 #ifdef FEAT_ARABIC | |
3082 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3083 { | |
3084 static int buflen = 0; | |
3085 char_u *p; | |
3086 int j; | |
3087 int newlen = 0; | |
3088 int mb_l; | |
719 | 3089 int pc, pc1 = 0; |
7 | 3090 int prev_c = 0; |
3091 int prev_c1 = 0; | |
714 | 3092 int u8c; |
3093 int u8cc[MAX_MCO]; | |
7 | 3094 int nc = 0; |
3095 | |
3096 /* | |
3097 * Do arabic shaping into a temporary buffer. This is very | |
3098 * inefficient! | |
3099 */ | |
507 | 3100 if (len * 2 + 2 > buflen) |
7 | 3101 { |
3102 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3103 * alloc()/free() calls. */ | |
359 | 3104 vim_free(arshape_buf); |
507 | 3105 buflen = len * 2 + 2; |
359 | 3106 arshape_buf = alloc(buflen); |
3107 if (arshape_buf == NULL) | |
7 | 3108 return; /* out of memory */ |
3109 } | |
3110 | |
507 | 3111 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3112 { | |
3113 /* Prepend a space to draw the leading composing char on. */ | |
3114 arshape_buf[0] = ' '; | |
3115 newlen = 1; | |
3116 } | |
3117 | |
7 | 3118 for (j = start; j < start + len; j += mb_l) |
3119 { | |
3120 p = ccline.cmdbuff + j; | |
714 | 3121 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3122 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3123 if (ARABIC_CHAR(u8c)) |
3124 { | |
3125 /* Do Arabic shaping. */ | |
3126 if (cmdmsg_rl) | |
3127 { | |
3128 /* displaying from right to left */ | |
3129 pc = prev_c; | |
3130 pc1 = prev_c1; | |
714 | 3131 prev_c1 = u8cc[0]; |
7 | 3132 if (j + mb_l >= start + len) |
3133 nc = NUL; | |
3134 else | |
3135 nc = utf_ptr2char(p + mb_l); | |
3136 } | |
3137 else | |
3138 { | |
3139 /* displaying from left to right */ | |
3140 if (j + mb_l >= start + len) | |
3141 pc = NUL; | |
3142 else | |
714 | 3143 { |
3144 int pcc[MAX_MCO]; | |
3145 | |
3146 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3147 start + len - j - mb_l); |
714 | 3148 pc1 = pcc[0]; |
3149 } | |
7 | 3150 nc = prev_c; |
3151 } | |
3152 prev_c = u8c; | |
3153 | |
714 | 3154 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3155 |
359 | 3156 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3157 if (u8cc[0] != 0) |
7 | 3158 { |
714 | 3159 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3160 if (u8cc[1] != 0) | |
3161 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3162 arshape_buf + newlen); |
7 | 3163 } |
3164 } | |
3165 else | |
3166 { | |
3167 prev_c = u8c; | |
359 | 3168 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3169 newlen += mb_l; |
3170 } | |
3171 } | |
3172 | |
359 | 3173 msg_outtrans_len(arshape_buf, newlen); |
7 | 3174 } |
3175 else | |
3176 #endif | |
3177 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3178 } | |
3179 | |
3180 /* | |
3181 * Put a character on the command line. Shifts the following text to the | |
3182 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3183 * "c" must be printable (fit in one display cell)! | |
3184 */ | |
3185 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3186 putcmdline(int c, int shift) |
7 | 3187 { |
3188 if (cmd_silent) | |
3189 return; | |
3190 msg_no_more = TRUE; | |
3191 msg_putchar(c); | |
3192 if (shift) | |
3193 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3194 msg_no_more = FALSE; | |
3195 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3196 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3197 extra_char_shift = shift; |
7 | 3198 } |
3199 | |
3200 /* | |
3201 * Undo a putcmdline(c, FALSE). | |
3202 */ | |
3203 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3204 unputcmdline(void) |
7 | 3205 { |
3206 if (cmd_silent) | |
3207 return; | |
3208 msg_no_more = TRUE; | |
3209 if (ccline.cmdlen == ccline.cmdpos) | |
3210 msg_putchar(' '); | |
3558 | 3211 #ifdef FEAT_MBYTE |
3212 else if (has_mbyte) | |
3213 draw_cmdline(ccline.cmdpos, | |
3214 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3215 #endif | |
7 | 3216 else |
3217 draw_cmdline(ccline.cmdpos, 1); | |
3218 msg_no_more = FALSE; | |
3219 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3220 extra_char = NUL; |
7 | 3221 } |
3222 | |
3223 /* | |
3224 * Put the given string, of the given length, onto the command line. | |
3225 * If len is -1, then STRLEN() is used to calculate the length. | |
3226 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3227 * part will be redrawn, otherwise it will not. If this function is called | |
3228 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3229 * called afterwards. | |
3230 */ | |
3231 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3232 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3233 { |
3234 int retval; | |
3235 int i; | |
3236 int m; | |
3237 int c; | |
3238 | |
3239 if (len < 0) | |
3240 len = (int)STRLEN(str); | |
3241 | |
3242 /* Check if ccline.cmdbuff needs to be longer */ | |
3243 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
|
3244 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3245 else |
3246 retval = OK; | |
3247 if (retval == OK) | |
3248 { | |
3249 if (!ccline.overstrike) | |
3250 { | |
3251 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3252 ccline.cmdbuff + ccline.cmdpos, | |
3253 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3254 ccline.cmdlen += len; | |
3255 } | |
3256 else | |
3257 { | |
3258 #ifdef FEAT_MBYTE | |
3259 if (has_mbyte) | |
3260 { | |
3261 /* Count nr of characters in the new string. */ | |
3262 m = 0; | |
474 | 3263 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3264 ++m; |
3265 /* Count nr of bytes in cmdline that are overwritten by these | |
3266 * characters. */ | |
3267 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3268 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3269 --m; |
3270 if (i < ccline.cmdlen) | |
3271 { | |
3272 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3273 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3274 ccline.cmdlen += ccline.cmdpos + len - i; | |
3275 } | |
3276 else | |
3277 ccline.cmdlen = ccline.cmdpos + len; | |
3278 } | |
3279 else | |
3280 #endif | |
3281 if (ccline.cmdpos + len > ccline.cmdlen) | |
3282 ccline.cmdlen = ccline.cmdpos + len; | |
3283 } | |
3284 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3285 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3286 | |
3287 #ifdef FEAT_MBYTE | |
3288 if (enc_utf8) | |
3289 { | |
3290 /* When the inserted text starts with a composing character, | |
3291 * backup to the character before it. There could be two of them. | |
3292 */ | |
3293 i = 0; | |
3294 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3295 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3296 { | |
3297 i = (*mb_head_off)(ccline.cmdbuff, | |
3298 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3299 ccline.cmdpos -= i; | |
3300 len += i; | |
3301 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3302 } | |
3303 # ifdef FEAT_ARABIC | |
3304 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3305 { | |
3306 /* Check the previous character for Arabic combining pair. */ | |
3307 i = (*mb_head_off)(ccline.cmdbuff, | |
3308 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3309 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3310 + ccline.cmdpos - i), c)) | |
3311 { | |
3312 ccline.cmdpos -= i; | |
3313 len += i; | |
3314 } | |
3315 else | |
3316 i = 0; | |
3317 } | |
3318 # endif | |
3319 if (i != 0) | |
3320 { | |
3321 /* Also backup the cursor position. */ | |
3322 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3323 ccline.cmdspos -= i; | |
3324 msg_col -= i; | |
3325 if (msg_col < 0) | |
3326 { | |
3327 msg_col += Columns; | |
3328 --msg_row; | |
3329 } | |
3330 } | |
3331 } | |
3332 #endif | |
3333 | |
3334 if (redraw && !cmd_silent) | |
3335 { | |
3336 msg_no_more = TRUE; | |
3337 i = cmdline_row; | |
3114 | 3338 cursorcmd(); |
7 | 3339 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3340 /* Avoid clearing the rest of the line too often. */ | |
3341 if (cmdline_row != i || ccline.overstrike) | |
3342 msg_clr_eos(); | |
3343 msg_no_more = FALSE; | |
3344 } | |
3345 #ifdef FEAT_FKMAP | |
3346 /* | |
3347 * If we are in Farsi command mode, the character input must be in | |
3348 * Insert mode. So do not advance the cmdpos. | |
3349 */ | |
3350 if (!cmd_fkmap) | |
3351 #endif | |
3352 { | |
3353 if (KeyTyped) | |
534 | 3354 { |
7 | 3355 m = Columns * Rows; |
534 | 3356 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3357 m = MAXCOL; | |
3358 } | |
7 | 3359 else |
3360 m = MAXCOL; | |
3361 for (i = 0; i < len; ++i) | |
3362 { | |
3363 c = cmdline_charsize(ccline.cmdpos); | |
3364 #ifdef FEAT_MBYTE | |
3365 /* count ">" for a double-wide char that doesn't fit. */ | |
3366 if (has_mbyte) | |
3367 correct_cmdspos(ccline.cmdpos, c); | |
3368 #endif | |
1612 | 3369 /* Stop cursor at the end of the screen, but do increment the |
3370 * insert position, so that entering a very long command | |
3371 * works, even though you can't see it. */ | |
3372 if (ccline.cmdspos + c < m) | |
3373 ccline.cmdspos += c; | |
7 | 3374 #ifdef FEAT_MBYTE |
3375 if (has_mbyte) | |
3376 { | |
474 | 3377 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3378 if (c > len - i - 1) |
3379 c = len - i - 1; | |
3380 ccline.cmdpos += c; | |
3381 i += c; | |
3382 } | |
3383 #endif | |
3384 ++ccline.cmdpos; | |
3385 } | |
3386 } | |
3387 } | |
3388 if (redraw) | |
3389 msg_check(); | |
3390 return retval; | |
3391 } | |
3392 | |
95 | 3393 static struct cmdline_info prev_ccline; |
3394 static int prev_ccline_used = FALSE; | |
3395 | |
3396 /* | |
3397 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3398 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3399 * available globally in prev_ccline. | |
3400 */ | |
3401 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3402 save_cmdline(struct cmdline_info *ccp) |
95 | 3403 { |
3404 if (!prev_ccline_used) | |
3405 { | |
3406 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3407 prev_ccline_used = TRUE; | |
3408 } | |
3409 *ccp = prev_ccline; | |
3410 prev_ccline = ccline; | |
3411 ccline.cmdbuff = NULL; | |
3412 ccline.cmdprompt = NULL; | |
1718 | 3413 ccline.xpc = NULL; |
95 | 3414 } |
3415 | |
3416 /* | |
1214 | 3417 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3418 */ |
3419 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3420 restore_cmdline(struct cmdline_info *ccp) |
95 | 3421 { |
3422 ccline = prev_ccline; | |
3423 prev_ccline = *ccp; | |
3424 } | |
3425 | |
849 | 3426 #if defined(FEAT_EVAL) || defined(PROTO) |
3427 /* | |
3428 * Save the command line into allocated memory. Returns a pointer to be | |
3429 * passed to restore_cmdline_alloc() later. | |
3430 * Returns NULL when failed. | |
3431 */ | |
3432 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3433 save_cmdline_alloc(void) |
849 | 3434 { |
3435 struct cmdline_info *p; | |
3436 | |
3437 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3438 if (p != NULL) | |
3439 save_cmdline(p); | |
3440 return (char_u *)p; | |
3441 } | |
3442 | |
3443 /* | |
3444 * Restore the command line from the return value of save_cmdline_alloc(). | |
3445 */ | |
3446 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3447 restore_cmdline_alloc(char_u *p) |
849 | 3448 { |
3449 if (p != NULL) | |
3450 { | |
3451 restore_cmdline((struct cmdline_info *)p); | |
3452 vim_free(p); | |
3453 } | |
3454 } | |
3455 #endif | |
3456 | |
15 | 3457 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3458 * 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
|
3459 * Used by CTRL-R command in command-line mode. |
15 | 3460 * insert_reg() can't be used here, because special characters from the |
3461 * register contents will be interpreted as commands. | |
3462 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3463 * Return FAIL for failure, OK otherwise. |
15 | 3464 */ |
3465 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3466 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3467 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3468 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
|
3469 int remcr) /* remove trailing CR */ |
15 | 3470 { |
3471 long i; | |
3472 char_u *arg; | |
772 | 3473 char_u *p; |
15 | 3474 int allocated; |
3475 struct cmdline_info save_ccline; | |
3476 | |
3477 /* check for valid regname; also accept special characters for CTRL-R in | |
3478 * the command line */ | |
3479 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
|
3480 && 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
|
3481 && !valid_yank_reg(regname, FALSE)) |
15 | 3482 return FAIL; |
3483 | |
3484 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3485 * CTRL-C to break the loop. */ | |
3486 line_breakcheck(); | |
3487 if (got_int) | |
3488 return FAIL; | |
3489 | |
3490 #ifdef FEAT_CLIPBOARD | |
3491 regname = may_get_selection(regname); | |
3492 #endif | |
3493 | |
634 | 3494 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3495 * things like going to another buffer when evaluating an expression. */ |
95 | 3496 save_cmdline(&save_ccline); |
634 | 3497 ++textlock; |
15 | 3498 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3499 --textlock; |
95 | 3500 restore_cmdline(&save_ccline); |
15 | 3501 |
3502 if (i) | |
3503 { | |
3504 /* Got the value of a special register in "arg". */ | |
3505 if (arg == NULL) | |
3506 return FAIL; | |
772 | 3507 |
3508 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3509 * part of the word. */ | |
3510 p = arg; | |
3511 if (p_is && regname == Ctrl_W) | |
3512 { | |
3513 char_u *w; | |
3514 int len; | |
3515 | |
3516 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3517 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3518 { |
3519 #ifdef FEAT_MBYTE | |
3520 if (has_mbyte) | |
3521 { | |
3522 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3523 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3524 break; | |
3525 w -= len; | |
3526 } | |
3527 else | |
3528 #endif | |
3529 { | |
3530 if (!vim_iswordc(w[-1])) | |
3531 break; | |
3532 --w; | |
3533 } | |
3534 } | |
2937 | 3535 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3536 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3537 p += len; | |
3538 } | |
3539 | |
3540 cmdline_paste_str(p, literally); | |
15 | 3541 if (allocated) |
3542 vim_free(arg); | |
3543 return OK; | |
3544 } | |
3545 | |
1015 | 3546 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3547 } |
3548 | |
3549 /* | |
3550 * Put a string on the command line. | |
3551 * When "literally" is TRUE, insert literally. | |
3552 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3553 * line. | |
3554 */ | |
3555 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3556 cmdline_paste_str(char_u *s, int literally) |
15 | 3557 { |
3558 int c, cv; | |
3559 | |
3560 if (literally) | |
3561 put_on_cmdline(s, -1, TRUE); | |
3562 else | |
3563 while (*s != NUL) | |
3564 { | |
3565 cv = *s; | |
3566 if (cv == Ctrl_V && s[1]) | |
3567 ++s; | |
3568 #ifdef FEAT_MBYTE | |
3569 if (has_mbyte) | |
1606 | 3570 c = mb_cptr2char_adv(&s); |
15 | 3571 else |
3572 #endif | |
3573 c = *s++; | |
3628 | 3574 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3575 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3576 #ifdef UNIX |
3577 || c == intr_char | |
3578 #endif | |
3579 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3580 stuffcharReadbuff(Ctrl_V); | |
3581 stuffcharReadbuff(c); | |
3582 } | |
3583 } | |
3584 | |
7 | 3585 #ifdef FEAT_WILDMENU |
3586 /* | |
3587 * Delete characters on the command line, from "from" to the current | |
3588 * position. | |
3589 */ | |
3590 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3591 cmdline_del(int from) |
7 | 3592 { |
3593 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3594 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3595 ccline.cmdlen -= ccline.cmdpos - from; | |
3596 ccline.cmdpos = from; | |
3597 } | |
3598 #endif | |
3599 | |
3600 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3601 * 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
|
3602 * 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
|
3603 * overwritten. |
7 | 3604 */ |
3605 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3606 redrawcmdline(void) |
7 | 3607 { |
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
|
3608 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
|
3609 } |
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
|
3610 |
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
|
3611 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
|
3612 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
|
3613 { |
7 | 3614 if (cmd_silent) |
3615 return; | |
3616 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
|
3617 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
|
3618 compute_cmdrow(); |
7 | 3619 redrawcmd(); |
3620 cursorcmd(); | |
3621 } | |
3622 | |
3623 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3624 redrawcmdprompt(void) |
7 | 3625 { |
3626 int i; | |
3627 | |
3628 if (cmd_silent) | |
3629 return; | |
531 | 3630 if (ccline.cmdfirstc != NUL) |
7 | 3631 msg_putchar(ccline.cmdfirstc); |
3632 if (ccline.cmdprompt != NULL) | |
3633 { | |
3634 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3635 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3636 /* do the reverse of set_cmdspos() */ | |
531 | 3637 if (ccline.cmdfirstc != NUL) |
7 | 3638 --ccline.cmdindent; |
3639 } | |
3640 else | |
3641 for (i = ccline.cmdindent; i > 0; --i) | |
3642 msg_putchar(' '); | |
3643 } | |
3644 | |
3645 /* | |
3646 * Redraw what is currently on the command line. | |
3647 */ | |
3648 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3649 redrawcmd(void) |
7 | 3650 { |
3651 if (cmd_silent) | |
3652 return; | |
3653 | |
683 | 3654 /* when 'incsearch' is set there may be no command line while redrawing */ |
3655 if (ccline.cmdbuff == NULL) | |
3656 { | |
3657 windgoto(cmdline_row, 0); | |
3658 msg_clr_eos(); | |
3659 return; | |
3660 } | |
3661 | |
7 | 3662 msg_start(); |
3663 redrawcmdprompt(); | |
3664 | |
3665 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3666 msg_no_more = TRUE; | |
3667 draw_cmdline(0, ccline.cmdlen); | |
3668 msg_clr_eos(); | |
3669 msg_no_more = FALSE; | |
3670 | |
3671 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
|
3672 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
|
3673 putcmdline(extra_char, extra_char_shift); |
7 | 3674 |
3675 /* | |
3676 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3677 * in cmdline mode we can reset them now. | |
3678 */ | |
3679 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3680 | |
3681 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3682 * in cmdline mode */ | |
3683 skip_redraw = FALSE; | |
3684 } | |
3685 | |
3686 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3687 compute_cmdrow(void) |
7 | 3688 { |
540 | 3689 if (exmode_active || msg_scrolled != 0) |
7 | 3690 cmdline_row = Rows - 1; |
3691 else | |
3692 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
|
3693 + lastwin->w_status_height; |
7 | 3694 } |
3695 | |
3696 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3697 cursorcmd(void) |
7 | 3698 { |
3699 if (cmd_silent) | |
3700 return; | |
3701 | |
3702 #ifdef FEAT_RIGHTLEFT | |
3703 if (cmdmsg_rl) | |
3704 { | |
3705 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3706 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3707 if (msg_row <= 0) | |
3708 msg_row = Rows - 1; | |
3709 } | |
3710 else | |
3711 #endif | |
3712 { | |
3713 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3714 msg_col = ccline.cmdspos % (int)Columns; | |
3715 if (msg_row >= Rows) | |
3716 msg_row = Rows - 1; | |
3717 } | |
3718 | |
3719 windgoto(msg_row, msg_col); | |
3720 #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
|
3721 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
|
3722 redrawcmd_preedit(); |
7 | 3723 #endif |
3724 #ifdef MCH_CURSOR_SHAPE | |
3725 mch_update_cursor(); | |
3726 #endif | |
3727 } | |
3728 | |
3729 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3730 gotocmdline(int clr) |
7 | 3731 { |
3732 msg_start(); | |
3733 #ifdef FEAT_RIGHTLEFT | |
3734 if (cmdmsg_rl) | |
3735 msg_col = Columns - 1; | |
3736 else | |
3737 #endif | |
3738 msg_col = 0; /* always start in column 0 */ | |
3739 if (clr) /* clear the bottom line(s) */ | |
3740 msg_clr_eos(); /* will reset clear_cmdline */ | |
3741 windgoto(cmdline_row, 0); | |
3742 } | |
3743 | |
3744 /* | |
3745 * Check the word in front of the cursor for an abbreviation. | |
3746 * Called when the non-id character "c" has been entered. | |
3747 * When an abbreviation is recognized it is removed from the text with | |
3748 * backspaces and the replacement string is inserted, followed by "c". | |
3749 */ | |
3750 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3751 ccheck_abbr(int c) |
7 | 3752 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3753 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3754 |
7 | 3755 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3756 return FALSE; | |
3757 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3758 /* 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
|
3759 * 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
|
3760 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
|
3761 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3762 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
|
3763 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3764 && 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
|
3765 && 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
|
3766 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3767 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3768 /* 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
|
3769 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3770 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3771 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3772 } |
3773 | |
3164 | 3774 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3775 static int | |
3776 #ifdef __BORLANDC__ | |
3777 _RTLENTRYF | |
3778 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3779 sort_func_compare(const void *s1, const void *s2) |
3164 | 3780 { |
3781 char_u *p1 = *(char_u **)s1; | |
3782 char_u *p2 = *(char_u **)s2; | |
3783 | |
3784 if (*p1 != '<' && *p2 == '<') return -1; | |
3785 if (*p1 == '<' && *p2 != '<') return 1; | |
3786 return STRCMP(p1, p2); | |
3787 } | |
3788 #endif | |
3789 | |
7 | 3790 /* |
3791 * Return FAIL if this is not an appropriate context in which to do | |
3792 * completion of anything, return OK if it is (even if there are no matches). | |
3793 * For the caller, this means that the character is just passed through like a | |
3794 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3795 */ | |
3796 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3797 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3798 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3799 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3800 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3801 int escape) /* if TRUE, escape the returned matches */ |
7 | 3802 { |
3803 int i, j; | |
3804 char_u *p1; | |
3805 char_u *p2; | |
3806 int difflen; | |
3807 int v; | |
3808 | |
3809 if (xp->xp_numfiles == -1) | |
3810 { | |
3811 set_expand_context(xp); | |
3812 cmd_showtail = expand_showtail(xp); | |
3813 } | |
3814 | |
3815 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3816 { | |
3817 beep_flush(); | |
3818 return OK; /* Something illegal on command line */ | |
3819 } | |
3820 if (xp->xp_context == EXPAND_NOTHING) | |
3821 { | |
3822 /* Caller can use the character as a normal char instead */ | |
3823 return FAIL; | |
3824 } | |
3825 | |
3826 MSG_PUTS("..."); /* show that we are busy */ | |
3827 out_flush(); | |
3828 | |
3829 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3830 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3831 |
3832 if (type == WILD_NEXT || type == WILD_PREV) | |
3833 { | |
3834 /* | |
3835 * Get next/previous match for a previous expanded pattern. | |
3836 */ | |
3837 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3838 } | |
3839 else | |
3840 { | |
3841 /* | |
3842 * Translate string into pattern and expand it. | |
3843 */ | |
1965 | 3844 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3845 xp->xp_context)) == NULL) | |
7 | 3846 p2 = NULL; |
3847 else | |
3848 { | |
2652 | 3849 int use_options = options | |
3961 | 3850 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3851 if (escape) | |
3852 use_options |= WILD_ESCAPE; | |
2652 | 3853 |
3854 if (p_wic) | |
3855 use_options += WILD_ICASE; | |
1965 | 3856 p2 = ExpandOne(xp, p1, |
3857 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3858 use_options, type); |
7 | 3859 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3860 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3861 if (p2 != NULL && type == WILD_LONGEST) |
3862 { | |
1965 | 3863 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3864 if (ccline.cmdbuff[i + j] == '*' |
3865 || ccline.cmdbuff[i + j] == '?') | |
3866 break; | |
3867 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
|
3868 VIM_CLEAR(p2); |
7 | 3869 } |
3870 } | |
3871 } | |
3872 | |
3873 if (p2 != NULL && !got_int) | |
3874 { | |
1965 | 3875 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
|
3876 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3877 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3878 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3879 xp->xp_pattern = ccline.cmdbuff + i; |
3880 } | |
3881 else | |
3882 v = OK; | |
3883 if (v == OK) | |
3884 { | |
323 | 3885 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3886 &ccline.cmdbuff[ccline.cmdpos], | |
3887 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3888 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3889 ccline.cmdlen += difflen; |
3890 ccline.cmdpos += difflen; | |
3891 } | |
3892 } | |
3893 vim_free(p2); | |
3894 | |
3895 redrawcmd(); | |
33 | 3896 cursorcmd(); |
7 | 3897 |
3898 /* When expanding a ":map" command and no matches are found, assume that | |
3899 * the key is supposed to be inserted literally */ | |
3900 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3901 return FAIL; | |
3902 | |
3903 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3904 beep_flush(); | |
3905 else if (xp->xp_numfiles == 1) | |
3906 /* free expanded pattern */ | |
3907 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3908 | |
3909 return OK; | |
3910 } | |
3911 | |
3912 /* | |
3913 * Do wildcard expansion on the string 'str'. | |
3914 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3915 * Return a pointer to allocated memory containing the new string. |
7 | 3916 * Return NULL for failure. |
3917 * | |
1412 | 3918 * "orig" is the originally expanded string, copied to allocated memory. It |
3919 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3920 * WILD_PREV "orig" should be NULL. | |
3921 * | |
838 | 3922 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3923 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3924 * |
3925 * mode = WILD_FREE: just free previously expanded matches | |
3926 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3927 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3928 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3929 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3930 * mode = WILD_ALL: return all matches concatenated | |
3931 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3932 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3933 * |
3934 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3935 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3936 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3937 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3938 * options = WILD_ADD_SLASH: add a slash after directory names | |
3939 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3940 * options = WILD_SILENT: don't print warning messages | |
3941 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3942 * options = WILD_ICASE: ignore case for files |
7 | 3943 * |
3944 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3945 */ | |
3946 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3947 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3948 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3949 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3950 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
|
3951 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3952 int mode) |
7 | 3953 { |
3954 char_u *ss = NULL; | |
3955 static int findex; | |
3956 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3957 int orig_saved = FALSE; |
7 | 3958 int i; |
3959 long_u len; | |
3960 int non_suf_match; /* number without matching suffix */ | |
3961 | |
3962 /* | |
3963 * first handle the case of using an old match | |
3964 */ | |
3965 if (mode == WILD_NEXT || mode == WILD_PREV) | |
3966 { | |
3967 if (xp->xp_numfiles > 0) | |
3968 { | |
3969 if (mode == WILD_PREV) | |
3970 { | |
3971 if (findex == -1) | |
3972 findex = xp->xp_numfiles; | |
3973 --findex; | |
3974 } | |
3975 else /* mode == WILD_NEXT */ | |
3976 ++findex; | |
3977 | |
3978 /* | |
3979 * When wrapping around, return the original string, set findex to | |
3980 * -1. | |
3981 */ | |
3982 if (findex < 0) | |
3983 { | |
3984 if (orig_save == NULL) | |
3985 findex = xp->xp_numfiles - 1; | |
3986 else | |
3987 findex = -1; | |
3988 } | |
3989 if (findex >= xp->xp_numfiles) | |
3990 { | |
3991 if (orig_save == NULL) | |
3992 findex = 0; | |
3993 else | |
3994 findex = -1; | |
3995 } | |
3996 #ifdef FEAT_WILDMENU | |
3997 if (p_wmnu) | |
3998 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
3999 findex, cmd_showtail); | |
4000 #endif | |
4001 if (findex == -1) | |
4002 return vim_strsave(orig_save); | |
4003 return vim_strsave(xp->xp_files[findex]); | |
4004 } | |
4005 else | |
4006 return NULL; | |
4007 } | |
4008 | |
1412 | 4009 /* free old names */ |
7 | 4010 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4011 { | |
4012 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4013 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
|
4014 VIM_CLEAR(orig_save); |
7 | 4015 } |
4016 findex = 0; | |
4017 | |
4018 if (mode == WILD_FREE) /* only release file name */ | |
4019 return NULL; | |
4020 | |
4021 if (xp->xp_numfiles == -1) | |
4022 { | |
4023 vim_free(orig_save); | |
4024 orig_save = orig; | |
1432 | 4025 orig_saved = TRUE; |
7 | 4026 |
4027 /* | |
4028 * Do the expansion. | |
4029 */ | |
4030 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4031 options) == FAIL) | |
4032 { | |
4033 #ifdef FNAME_ILLEGAL | |
4034 /* Illegal file name has been silently skipped. But when there | |
4035 * are wildcards, the real problem is that there was no match, | |
4036 * causing the pattern to be added, which has illegal characters. | |
4037 */ | |
4038 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4039 EMSG2(_(e_nomatch2), str); | |
4040 #endif | |
4041 } | |
4042 else if (xp->xp_numfiles == 0) | |
4043 { | |
4044 if (!(options & WILD_SILENT)) | |
4045 EMSG2(_(e_nomatch2), str); | |
4046 } | |
4047 else | |
4048 { | |
4049 /* Escape the matches for use on the command line. */ | |
4050 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4051 | |
4052 /* | |
4053 * Check for matching suffixes in file names. | |
4054 */ | |
3398 | 4055 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4056 && mode != WILD_LONGEST) | |
7 | 4057 { |
4058 if (xp->xp_numfiles) | |
4059 non_suf_match = xp->xp_numfiles; | |
4060 else | |
4061 non_suf_match = 1; | |
4062 if ((xp->xp_context == EXPAND_FILES | |
4063 || xp->xp_context == EXPAND_DIRECTORIES) | |
4064 && xp->xp_numfiles > 1) | |
4065 { | |
4066 /* | |
4067 * More than one match; check suffix. | |
4068 * The files will have been sorted on matching suffix in | |
4069 * expand_wildcards, only need to check the first two. | |
4070 */ | |
4071 non_suf_match = 0; | |
4072 for (i = 0; i < 2; ++i) | |
4073 if (match_suffix(xp->xp_files[i])) | |
4074 ++non_suf_match; | |
4075 } | |
4076 if (non_suf_match != 1) | |
4077 { | |
4078 /* Can we ever get here unless it's while expanding | |
4079 * interactively? If not, we can get rid of this all | |
4080 * together. Don't really want to wait for this message | |
4081 * (and possibly have to hit return to continue!). | |
4082 */ | |
4083 if (!(options & WILD_SILENT)) | |
4084 EMSG(_(e_toomany)); | |
4085 else if (!(options & WILD_NO_BEEP)) | |
4086 beep_flush(); | |
4087 } | |
4088 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4089 ss = vim_strsave(xp->xp_files[0]); | |
4090 } | |
4091 } | |
4092 } | |
4093 | |
4094 /* Find longest common part */ | |
4095 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4096 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4097 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4098 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4099 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4100 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4101 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4102 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4103 if (has_mbyte) |
7 | 4104 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4105 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
|
4106 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
|
4107 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4108 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4109 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4110 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
|
4111 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
|
4112 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4113 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4114 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4115 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
|
4116 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4117 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4118 ci = xp->xp_files[i][len]; |
4242 | 4119 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4120 || xp->xp_context == EXPAND_FILES |
714 | 4121 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4122 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4123 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4124 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4125 break; |
4126 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4127 else if (c0 != ci) |
7 | 4128 break; |
4129 } | |
4130 if (i < xp->xp_numfiles) | |
4131 { | |
4132 if (!(options & WILD_NO_BEEP)) | |
6949 | 4133 vim_beep(BO_WILD); |
7 | 4134 break; |
4135 } | |
4136 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4137 |
7 | 4138 ss = alloc((unsigned)len + 1); |
4139 if (ss) | |
419 | 4140 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4141 findex = -1; /* next p_wc gets first one */ |
4142 } | |
4143 | |
4144 /* Concatenate all matching names */ | |
4145 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4146 { | |
4147 len = 0; | |
4148 for (i = 0; i < xp->xp_numfiles; ++i) | |
4149 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4150 ss = lalloc(len, TRUE); | |
4151 if (ss != NULL) | |
4152 { | |
4153 *ss = NUL; | |
4154 for (i = 0; i < xp->xp_numfiles; ++i) | |
4155 { | |
4156 STRCAT(ss, xp->xp_files[i]); | |
4157 if (i != xp->xp_numfiles - 1) | |
4158 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4159 } | |
4160 } | |
4161 } | |
4162 | |
4163 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4164 ExpandCleanup(xp); | |
4165 | |
1412 | 4166 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4167 if (!orig_saved) |
1412 | 4168 vim_free(orig); |
4169 | |
7 | 4170 return ss; |
4171 } | |
4172 | |
4173 /* | |
4174 * Prepare an expand structure for use. | |
4175 */ | |
4176 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4177 ExpandInit(expand_T *xp) |
7 | 4178 { |
1718 | 4179 xp->xp_pattern = NULL; |
1965 | 4180 xp->xp_pattern_len = 0; |
7 | 4181 xp->xp_backslash = XP_BS_NONE; |
632 | 4182 #ifndef BACKSLASH_IN_FILENAME |
4183 xp->xp_shell = FALSE; | |
4184 #endif | |
7 | 4185 xp->xp_numfiles = -1; |
4186 xp->xp_files = NULL; | |
632 | 4187 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4188 xp->xp_arg = NULL; | |
4189 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4190 xp->xp_line = NULL; |
7 | 4191 } |
4192 | |
4193 /* | |
4194 * Cleanup an expand structure after use. | |
4195 */ | |
4196 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4197 ExpandCleanup(expand_T *xp) |
7 | 4198 { |
4199 if (xp->xp_numfiles >= 0) | |
4200 { | |
4201 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4202 xp->xp_numfiles = -1; | |
4203 } | |
4204 } | |
4205 | |
4206 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4207 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4208 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4209 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4210 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4211 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4212 int options) |
7 | 4213 { |
4214 int i; | |
4215 char_u *p; | |
4216 | |
4217 /* | |
4218 * May change home directory back to "~" | |
4219 */ | |
4220 if (options & WILD_HOME_REPLACE) | |
4221 tilde_replace(str, numfiles, files); | |
4222 | |
4223 if (options & WILD_ESCAPE) | |
4224 { | |
4225 if (xp->xp_context == EXPAND_FILES | |
2778 | 4226 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4227 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4228 || xp->xp_context == EXPAND_BUFFERS |
4229 || xp->xp_context == EXPAND_DIRECTORIES) | |
4230 { | |
4231 /* | |
4232 * Insert a backslash into a file name before a space, \, %, # | |
4233 * and wildmatch characters, except '~'. | |
4234 */ | |
4235 for (i = 0; i < numfiles; ++i) | |
4236 { | |
4237 /* for ":set path=" we need to escape spaces twice */ | |
4238 if (xp->xp_backslash == XP_BS_THREE) | |
4239 { | |
4240 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4241 if (p != NULL) | |
4242 { | |
4243 vim_free(files[i]); | |
4244 files[i] = p; | |
719 | 4245 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4246 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4247 if (p != NULL) | |
4248 { | |
4249 vim_free(files[i]); | |
4250 files[i] = p; | |
4251 } | |
4252 #endif | |
4253 } | |
4254 } | |
1589 | 4255 #ifdef BACKSLASH_IN_FILENAME |
4256 p = vim_strsave_fnameescape(files[i], FALSE); | |
4257 #else | |
1586 | 4258 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4259 #endif |
7 | 4260 if (p != NULL) |
4261 { | |
4262 vim_free(files[i]); | |
4263 files[i] = p; | |
4264 } | |
4265 | |
4266 /* If 'str' starts with "\~", replace "~" at start of | |
4267 * files[i] with "\~". */ | |
4268 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4269 escape_fname(&files[i]); |
7 | 4270 } |
4271 xp->xp_backslash = XP_BS_NONE; | |
435 | 4272 |
4273 /* If the first file starts with a '+' escape it. Otherwise it | |
4274 * could be seen as "+cmd". */ | |
4275 if (*files[0] == '+') | |
4276 escape_fname(&files[0]); | |
7 | 4277 } |
4278 else if (xp->xp_context == EXPAND_TAGS) | |
4279 { | |
4280 /* | |
4281 * Insert a backslash before characters in a tag name that | |
4282 * would terminate the ":tag" command. | |
4283 */ | |
4284 for (i = 0; i < numfiles; ++i) | |
4285 { | |
4286 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4287 if (p != NULL) | |
4288 { | |
4289 vim_free(files[i]); | |
4290 files[i] = p; | |
4291 } | |
4292 } | |
4293 } | |
4294 } | |
4295 } | |
4296 | |
4297 /* | |
1586 | 4298 * Escape special characters in "fname" for when used as a file name argument |
4299 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4300 * Returns the result in allocated memory. | |
4301 */ | |
4302 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4303 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4304 { |
1685 | 4305 char_u *p; |
1586 | 4306 #ifdef BACKSLASH_IN_FILENAME |
4307 char_u buf[20]; | |
4308 int j = 0; | |
4309 | |
5481 | 4310 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4311 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4312 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4313 buf[j++] = *p; |
4314 buf[j] = NUL; | |
1700 | 4315 p = vim_strsave_escaped(fname, buf); |
1586 | 4316 #else |
1685 | 4317 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4318 if (shell && csh_like_shell() && p != NULL) | |
4319 { | |
4320 char_u *s; | |
4321 | |
4322 /* For csh and similar shells need to put two backslashes before '!'. | |
4323 * One is taken by Vim, one by the shell. */ | |
4324 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4325 vim_free(p); | |
4326 p = s; | |
4327 } | |
1700 | 4328 #endif |
4329 | |
4330 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4331 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4332 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4333 escape_fname(&p); |
4334 | |
1685 | 4335 return p; |
1586 | 4336 } |
4337 | |
4338 /* | |
435 | 4339 * Put a backslash before the file name in "pp", which is in allocated memory. |
4340 */ | |
4341 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4342 escape_fname(char_u **pp) |
435 | 4343 { |
4344 char_u *p; | |
4345 | |
4346 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4347 if (p != NULL) | |
4348 { | |
4349 p[0] = '\\'; | |
4350 STRCPY(p + 1, *pp); | |
4351 vim_free(*pp); | |
4352 *pp = p; | |
4353 } | |
4354 } | |
4355 | |
4356 /* | |
7 | 4357 * For each file name in files[num_files]: |
4358 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4359 */ | |
4360 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4361 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4362 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4363 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4364 char_u **files) |
7 | 4365 { |
4366 int i; | |
4367 char_u *p; | |
4368 | |
4369 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4370 { | |
4371 for (i = 0; i < num_files; ++i) | |
4372 { | |
4373 p = home_replace_save(NULL, files[i]); | |
4374 if (p != NULL) | |
4375 { | |
4376 vim_free(files[i]); | |
4377 files[i] = p; | |
4378 } | |
4379 } | |
4380 } | |
4381 } | |
4382 | |
4383 /* | |
4384 * Show all matches for completion on the command line. | |
4385 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4386 * be inserted like a normal character. | |
4387 */ | |
4388 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4389 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4390 { |
4391 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4392 int num_files; | |
4393 char_u **files_found; | |
4394 int i, j, k; | |
4395 int maxlen; | |
4396 int lines; | |
4397 int columns; | |
4398 char_u *p; | |
4399 int lastlen; | |
4400 int attr; | |
4401 int showtail; | |
4402 | |
4403 if (xp->xp_numfiles == -1) | |
4404 { | |
4405 set_expand_context(xp); | |
4406 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4407 &num_files, &files_found); | |
4408 showtail = expand_showtail(xp); | |
4409 if (i != EXPAND_OK) | |
4410 return i; | |
4411 | |
4412 } | |
4413 else | |
4414 { | |
4415 num_files = xp->xp_numfiles; | |
4416 files_found = xp->xp_files; | |
4417 showtail = cmd_showtail; | |
4418 } | |
4419 | |
4420 #ifdef FEAT_WILDMENU | |
4421 if (!wildmenu) | |
4422 { | |
4423 #endif | |
4424 msg_didany = FALSE; /* lines_left will be set */ | |
4425 msg_start(); /* prepare for paging */ | |
4426 msg_putchar('\n'); | |
4427 out_flush(); | |
4428 cmdline_row = msg_row; | |
4429 msg_didany = FALSE; /* lines_left will be set again */ | |
4430 msg_start(); /* prepare for paging */ | |
4431 #ifdef FEAT_WILDMENU | |
4432 } | |
4433 #endif | |
4434 | |
4435 if (got_int) | |
4436 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4437 #ifdef FEAT_WILDMENU | |
4438 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
|
4439 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4440 #endif |
4441 else | |
4442 { | |
4443 /* find the length of the longest file name */ | |
4444 maxlen = 0; | |
4445 for (i = 0; i < num_files; ++i) | |
4446 { | |
4447 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4448 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4449 || xp->xp_context == EXPAND_BUFFERS)) |
4450 { | |
4451 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4452 j = vim_strsize(NameBuff); | |
4453 } | |
4454 else | |
4455 j = vim_strsize(L_SHOWFILE(i)); | |
4456 if (j > maxlen) | |
4457 maxlen = j; | |
4458 } | |
4459 | |
4460 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4461 lines = num_files; | |
4462 else | |
4463 { | |
4464 /* compute the number of columns and lines for the listing */ | |
4465 maxlen += 2; /* two spaces between file names */ | |
4466 columns = ((int)Columns + 2) / maxlen; | |
4467 if (columns < 1) | |
4468 columns = 1; | |
4469 lines = (num_files + columns - 1) / columns; | |
4470 } | |
4471 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4472 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4473 |
4474 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4475 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4476 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4477 msg_clr_eos(); |
4478 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
|
4479 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4480 } |
4481 | |
4482 /* list the files line by line */ | |
4483 for (i = 0; i < lines; ++i) | |
4484 { | |
4485 lastlen = 999; | |
4486 for (k = i; k < num_files; k += lines) | |
4487 { | |
4488 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4489 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4490 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4491 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4492 msg_advance(maxlen + 1); | |
4493 msg_puts(p); | |
4494 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
|
4495 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4496 break; |
4497 } | |
4498 for (j = maxlen - lastlen; --j >= 0; ) | |
4499 msg_putchar(' '); | |
4500 if (xp->xp_context == EXPAND_FILES | |
714 | 4501 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4502 || xp->xp_context == EXPAND_BUFFERS) |
4503 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4504 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4505 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4506 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4507 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4508 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4509 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4510 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4511 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4512 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4513 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
|
4514 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4515 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4516 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4517 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4518 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4519 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4520 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4521 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4522 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4523 j = mch_isdir(files_found[k]); |
7 | 4524 if (showtail) |
4525 p = L_SHOWFILE(k); | |
4526 else | |
4527 { | |
4528 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4529 TRUE); | |
4530 p = NameBuff; | |
4531 } | |
4532 } | |
4533 else | |
4534 { | |
4535 j = FALSE; | |
4536 p = L_SHOWFILE(k); | |
4537 } | |
4538 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4539 } | |
4540 if (msg_col > 0) /* when not wrapped around */ | |
4541 { | |
4542 msg_clr_eos(); | |
4543 msg_putchar('\n'); | |
4544 } | |
4545 out_flush(); /* show one line at a time */ | |
4546 if (got_int) | |
4547 { | |
4548 got_int = FALSE; | |
4549 break; | |
4550 } | |
4551 } | |
4552 | |
4553 /* | |
4554 * we redraw the command below the lines that we have just listed | |
4555 * This is a bit tricky, but it saves a lot of screen updating. | |
4556 */ | |
4557 cmdline_row = msg_row; /* will put it back later */ | |
4558 } | |
4559 | |
4560 if (xp->xp_numfiles == -1) | |
4561 FreeWild(num_files, files_found); | |
4562 | |
4563 return EXPAND_OK; | |
4564 } | |
4565 | |
4566 /* | |
4567 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4568 * Find tail of file name path, but ignore trailing "/". | |
4569 */ | |
4570 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4571 sm_gettail(char_u *s) |
7 | 4572 { |
4573 char_u *p; | |
4574 char_u *t = s; | |
4575 int had_sep = FALSE; | |
4576 | |
4577 for (p = s; *p != NUL; ) | |
4578 { | |
4579 if (vim_ispathsep(*p) | |
4580 #ifdef BACKSLASH_IN_FILENAME | |
4581 && !rem_backslash(p) | |
4582 #endif | |
4583 ) | |
4584 had_sep = TRUE; | |
4585 else if (had_sep) | |
4586 { | |
4587 t = p; | |
4588 had_sep = FALSE; | |
4589 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4590 MB_PTR_ADV(p); |
7 | 4591 } |
4592 return t; | |
4593 } | |
4594 | |
4595 /* | |
4596 * Return TRUE if we only need to show the tail of completion matches. | |
4597 * When not completing file names or there is a wildcard in the path FALSE is | |
4598 * returned. | |
4599 */ | |
4600 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4601 expand_showtail(expand_T *xp) |
7 | 4602 { |
4603 char_u *s; | |
4604 char_u *end; | |
4605 | |
4606 /* When not completing file names a "/" may mean something different. */ | |
714 | 4607 if (xp->xp_context != EXPAND_FILES |
4608 && xp->xp_context != EXPAND_SHELLCMD | |
4609 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4610 return FALSE; |
4611 | |
4612 end = gettail(xp->xp_pattern); | |
4613 if (end == xp->xp_pattern) /* there is no path separator */ | |
4614 return FALSE; | |
4615 | |
4616 for (s = xp->xp_pattern; s < end; s++) | |
4617 { | |
4618 /* Skip escaped wildcards. Only when the backslash is not a path | |
4619 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4620 if (rem_backslash(s)) | |
4621 ++s; | |
4622 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4623 return FALSE; | |
4624 } | |
4625 return TRUE; | |
4626 } | |
4627 | |
4628 /* | |
4629 * Prepare a string for expansion. | |
4630 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4631 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4632 * When expanding other names: The string will be used with regcomp(). Copy |
4633 * the name into allocated memory and prepend "^". | |
4634 */ | |
4635 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4636 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4637 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4638 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4639 int context) /* EXPAND_FILES etc. */ |
7 | 4640 { |
4641 char_u *retval; | |
4642 int i, j; | |
4643 int new_len; | |
4644 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4645 int ends_in_star; |
7 | 4646 |
714 | 4647 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4648 && context != EXPAND_FILES_IN_PATH |
714 | 4649 && context != EXPAND_SHELLCMD |
4650 && context != EXPAND_DIRECTORIES) | |
7 | 4651 { |
4652 /* | |
4653 * Matching will be done internally (on something other than files). | |
4654 * So we convert the file-matching-type wildcards into our kind for | |
4655 * use with vim_regcomp(). First work out how long it will be: | |
4656 */ | |
4657 | |
4658 /* For help tags the translation is done in find_help_tags(). | |
4659 * For a tag pattern starting with "/" no translation is needed. */ | |
4660 if (context == EXPAND_HELP | |
4661 || context == EXPAND_COLORS | |
4662 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4663 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4664 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4665 || 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
|
4666 || ((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
|
4667 || 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
|
4668 && fname[0] == '/')) |
7 | 4669 retval = vim_strnsave(fname, len); |
4670 else | |
4671 { | |
4672 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4673 for (i = 0; i < len; i++) | |
4674 { | |
4675 if (fname[i] == '*' || fname[i] == '~') | |
4676 new_len++; /* '*' needs to be replaced by ".*" | |
4677 '~' needs to be replaced by "\~" */ | |
4678 | |
4679 /* Buffer names are like file names. "." should be literal */ | |
4680 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4681 new_len++; /* "." becomes "\." */ | |
4682 | |
4683 /* Custom expansion takes care of special things, match | |
4684 * backslashes literally (perhaps also for other types?) */ | |
634 | 4685 if ((context == EXPAND_USER_DEFINED |
4686 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4687 new_len++; /* '\' becomes "\\" */ |
4688 } | |
4689 retval = alloc(new_len); | |
4690 if (retval != NULL) | |
4691 { | |
4692 retval[0] = '^'; | |
4693 j = 1; | |
4694 for (i = 0; i < len; i++, j++) | |
4695 { | |
4696 /* Skip backslash. But why? At least keep it for custom | |
4697 * expansion. */ | |
4698 if (context != EXPAND_USER_DEFINED | |
407 | 4699 && context != EXPAND_USER_LIST |
4700 && fname[i] == '\\' | |
4701 && ++i == len) | |
7 | 4702 break; |
4703 | |
4704 switch (fname[i]) | |
4705 { | |
4706 case '*': retval[j++] = '.'; | |
4707 break; | |
4708 case '~': retval[j++] = '\\'; | |
4709 break; | |
4710 case '?': retval[j] = '.'; | |
4711 continue; | |
4712 case '.': if (context == EXPAND_BUFFERS) | |
4713 retval[j++] = '\\'; | |
4714 break; | |
407 | 4715 case '\\': if (context == EXPAND_USER_DEFINED |
4716 || context == EXPAND_USER_LIST) | |
7 | 4717 retval[j++] = '\\'; |
4718 break; | |
4719 } | |
4720 retval[j] = fname[i]; | |
4721 } | |
4722 retval[j] = NUL; | |
4723 } | |
4724 } | |
4725 } | |
4726 else | |
4727 { | |
4728 retval = alloc(len + 4); | |
4729 if (retval != NULL) | |
4730 { | |
419 | 4731 vim_strncpy(retval, fname, len); |
7 | 4732 |
4733 /* | |
831 | 4734 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4735 * * would become **, which walks the whole tree. | |
7 | 4736 * ~ would be at the start of the file name, but not the tail. |
4737 * $ could be anywhere in the tail. | |
4738 * ` could be anywhere in the file name. | |
1484 | 4739 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4740 */ |
4741 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4742 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
|
4743 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4744 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4745 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4746 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4747 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4748 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4749 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4750 #endif |
7 | 4751 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4752 && !ends_in_star |
7 | 4753 && vim_strchr(tail, '$') == NULL |
4754 && vim_strchr(retval, '`') == NULL) | |
4755 retval[len++] = '*'; | |
1484 | 4756 else if (len > 0 && retval[len - 1] == '$') |
4757 --len; | |
7 | 4758 retval[len] = NUL; |
4759 } | |
4760 } | |
4761 return retval; | |
4762 } | |
4763 | |
4764 /* | |
4765 * Must parse the command line so far to work out what context we are in. | |
4766 * Completion can then be done based on that context. | |
4767 * This routine sets the variables: | |
4768 * xp->xp_pattern The start of the pattern to be expanded within | |
4769 * the command line (ends at the cursor). | |
4770 * xp->xp_context The type of thing to expand. Will be one of: | |
4771 * | |
4772 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4773 * the command line, like an unknown command. Caller | |
4774 * should beep. | |
4775 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4776 * a normal char, rather than for completion. eg | |
4777 * :s/^I/ | |
4778 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4779 * it. | |
4780 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4781 * EXPAND_FILES After command with XFILE set, or after setting | |
4782 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4783 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4784 * when we know only directories are of interest. eg | |
4785 * :set dir=^I | |
714 | 4786 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4787 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4788 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4789 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4790 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4791 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4792 * EXPAND_EVENTS Complete event names | |
4793 * EXPAND_SYNTAX Complete :syntax command arguments | |
4794 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4795 * EXPAND_AUGROUP Complete autocommand group names | |
4796 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4797 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4798 * eg :unmap a^I , :cunab x^I | |
4799 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4800 * eg :call sub^I | |
4801 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4802 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4803 * names in expressions, eg :while s^I | |
4804 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4805 * EXPAND_USER Complete user names |
7 | 4806 */ |
4807 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4808 set_expand_context(expand_T *xp) |
7 | 4809 { |
168 | 4810 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4811 if (ccline.cmdfirstc != ':' |
4812 #ifdef FEAT_EVAL | |
168 | 4813 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4814 && !ccline.input_fn |
7 | 4815 #endif |
4816 ) | |
4817 { | |
4818 xp->xp_context = EXPAND_NOTHING; | |
4819 return; | |
4820 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4821 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4822 } |
4823 | |
4824 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4825 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4826 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4827 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
|
4828 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
|
4829 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4830 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4831 { |
4832 int old_char = NUL; | |
4833 char_u *nextcomm; | |
4834 | |
4835 /* | |
4836 * Avoid a UMR warning from Purify, only save the character if it has been | |
4837 * written before. | |
4838 */ | |
4839 if (col < len) | |
4840 old_char = str[col]; | |
4841 str[col] = NUL; | |
4842 nextcomm = str; | |
168 | 4843 |
4844 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4845 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4846 { |
4847 # ifdef FEAT_CMDL_COMPL | |
168 | 4848 /* pass CMD_SIZE because there is no real command */ |
4849 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4850 # endif |
4851 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4852 else if (use_ccline && ccline.input_fn) |
531 | 4853 { |
4854 xp->xp_context = ccline.xp_context; | |
4855 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4856 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4857 xp->xp_arg = ccline.xp_arg; |
1322 | 4858 # endif |
531 | 4859 } |
168 | 4860 else |
4861 #endif | |
4862 while (nextcomm != NULL) | |
4863 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4864 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4865 /* 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
|
4866 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4867 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4868 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4869 |
7 | 4870 str[col] = old_char; |
4871 } | |
4872 | |
4873 /* | |
4874 * Expand the command line "str" from context "xp". | |
4875 * "xp" must have been set by set_cmd_context(). | |
4876 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4877 * starts. | |
4878 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4879 * cursor. | |
4880 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4881 * key that triggered expansion literally. | |
4882 * Returns EXPAND_OK otherwise. | |
4883 */ | |
4884 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4885 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4886 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4887 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
|
4888 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4889 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4890 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4891 { |
4892 char_u *file_str = NULL; | |
2652 | 4893 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4894 |
4895 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4896 { | |
4897 beep_flush(); | |
4898 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4899 } | |
4900 if (xp->xp_context == EXPAND_NOTHING) | |
4901 { | |
4902 /* Caller can use the character as a normal char instead */ | |
4903 return EXPAND_NOTHING; | |
4904 } | |
4905 | |
4906 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4907 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4908 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4909 if (file_str == NULL) |
4910 return EXPAND_UNSUCCESSFUL; | |
4911 | |
2652 | 4912 if (p_wic) |
4913 options += WILD_ICASE; | |
4914 | |
7 | 4915 /* find all files that match the description */ |
2652 | 4916 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4917 { |
4918 *matchcount = 0; | |
4919 *matches = NULL; | |
4920 } | |
4921 vim_free(file_str); | |
4922 | |
4923 return EXPAND_OK; | |
4924 } | |
4925 | |
4926 #ifdef FEAT_MULTI_LANG | |
4927 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4928 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4929 * 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
|
4930 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4931 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4932 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4933 |
4934 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4935 cleanup_help_tags(int num_file, char_u **file) |
7 | 4936 { |
4937 int i, j; | |
4938 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4939 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4940 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4941 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4942 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
|
4943 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4944 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4945 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4946 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4947 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4948 *p = NUL; |
7 | 4949 |
4950 for (i = 0; i < num_file; ++i) | |
4951 { | |
4952 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
|
4953 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4954 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4955 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4956 { |
4957 /* Sorting on priority means the same item in another language may | |
4958 * be anywhere. Search all items for a match up to the "@en". */ | |
4959 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
|
4960 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
|
4961 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 4962 break; |
4963 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4964 /* item only exists with @en, remove it */ |
7 | 4965 file[i][len] = NUL; |
4966 } | |
4967 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4968 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4969 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4970 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
|
4971 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4972 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4973 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4974 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4975 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
|
4976 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4977 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4978 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4979 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4980 } |
7 | 4981 } |
4982 #endif | |
4983 | |
4984 /* | |
4985 * Do the expansion based on xp->xp_context and "pat". | |
4986 */ | |
4987 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4988 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4989 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4990 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4991 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4992 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4993 int options) /* EW_ flags */ |
7 | 4994 { |
4995 #ifdef FEAT_CMDL_COMPL | |
4996 regmatch_T regmatch; | |
4997 #endif | |
4998 int ret; | |
4999 int flags; | |
5000 | |
5001 flags = EW_DIR; /* include directories */ | |
5002 if (options & WILD_LIST_NOTFOUND) | |
5003 flags |= EW_NOTFOUND; | |
5004 if (options & WILD_ADD_SLASH) | |
5005 flags |= EW_ADDSLASH; | |
5006 if (options & WILD_KEEP_ALL) | |
5007 flags |= EW_KEEPALL; | |
5008 if (options & WILD_SILENT) | |
5009 flags |= EW_SILENT; | |
6659 | 5010 if (options & WILD_ALLLINKS) |
5011 flags |= EW_ALLLINKS; | |
7 | 5012 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5013 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5014 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5015 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5016 { |
5017 /* | |
5018 * Expand file or directory names. | |
5019 */ | |
5020 int free_pat = FALSE; | |
5021 int i; | |
5022 | |
5023 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5024 * space */ | |
5025 if (xp->xp_backslash != XP_BS_NONE) | |
5026 { | |
5027 free_pat = TRUE; | |
5028 pat = vim_strsave(pat); | |
5029 for (i = 0; pat[i]; ++i) | |
5030 if (pat[i] == '\\') | |
5031 { | |
5032 if (xp->xp_backslash == XP_BS_THREE | |
5033 && pat[i + 1] == '\\' | |
5034 && pat[i + 2] == '\\' | |
5035 && pat[i + 3] == ' ') | |
1621 | 5036 STRMOVE(pat + i, pat + i + 3); |
7 | 5037 if (xp->xp_backslash == XP_BS_ONE |
5038 && pat[i + 1] == ' ') | |
1621 | 5039 STRMOVE(pat + i, pat + i + 1); |
7 | 5040 } |
5041 } | |
5042 | |
5043 if (xp->xp_context == EXPAND_FILES) | |
5044 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5045 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
|
5046 flags |= (EW_FILE | EW_PATH); |
7 | 5047 else |
5048 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5049 if (options & WILD_ICASE) |
5050 flags |= EW_ICASE; | |
5051 | |
2016 | 5052 /* Expand wildcards, supporting %:h and the like. */ |
5053 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5054 if (free_pat) |
5055 vim_free(pat); | |
5056 return ret; | |
5057 } | |
5058 | |
5059 *file = (char_u **)""; | |
5060 *num_file = 0; | |
5061 if (xp->xp_context == EXPAND_HELP) | |
5062 { | |
1696 | 5063 /* With an empty argument we would get all the help tags, which is |
5064 * very slow. Get matches for "help" instead. */ | |
5065 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5066 num_file, file, FALSE) == OK) | |
7 | 5067 { |
5068 #ifdef FEAT_MULTI_LANG | |
5069 cleanup_help_tags(*num_file, *file); | |
5070 #endif | |
5071 return OK; | |
5072 } | |
5073 return FAIL; | |
5074 } | |
5075 | |
5076 #ifndef FEAT_CMDL_COMPL | |
5077 return FAIL; | |
5078 #else | |
716 | 5079 if (xp->xp_context == EXPAND_SHELLCMD) |
5080 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5081 if (xp->xp_context == EXPAND_OLD_SETTING) |
5082 return ExpandOldSetting(num_file, file); | |
5083 if (xp->xp_context == EXPAND_BUFFERS) | |
5084 return ExpandBufnames(pat, num_file, file, options); | |
5085 if (xp->xp_context == EXPAND_TAGS | |
5086 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5087 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5088 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5089 { |
5090 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5091 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
|
5092 directories); |
2929 | 5093 } |
7 | 5094 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5095 { |
3106 | 5096 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5097 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5098 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5099 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5100 { |
5101 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5102 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5103 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5104 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5105 { |
5106 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
|
5107 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5108 } |
407 | 5109 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5110 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5111 return ExpandUserList(xp, num_file, file); |
407 | 5112 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5113 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5114 return ExpandPackAddDir(pat, num_file, file); |
7 | 5115 |
5116 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5117 if (regmatch.regprog == NULL) | |
5118 return FAIL; | |
5119 | |
5120 /* set ignore-case according to p_ic, p_scs and pat */ | |
5121 regmatch.rm_ic = ignorecase(pat); | |
5122 | |
5123 if (xp->xp_context == EXPAND_SETTINGS | |
5124 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5125 ret = ExpandSettings(xp, ®match, num_file, file); | |
5126 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5127 ret = ExpandMappings(®match, num_file, file); | |
5128 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5129 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5130 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5131 # endif | |
5132 else | |
5133 { | |
5134 static struct expgen | |
5135 { | |
5136 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5137 char_u *((*func)(expand_T *, int)); |
7 | 5138 int ic; |
2849 | 5139 int escaped; |
7 | 5140 } tab[] = |
5141 { | |
2849 | 5142 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5143 {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
|
5144 {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
|
5145 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5146 #ifdef FEAT_CMDHIST |
5147 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5148 #endif | |
7 | 5149 #ifdef FEAT_USR_CMDS |
2849 | 5150 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5151 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5152 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5153 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5154 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5155 #endif |
5156 #ifdef FEAT_EVAL | |
2849 | 5157 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5158 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5159 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5160 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5161 #endif |
5162 #ifdef FEAT_MENU | |
2849 | 5163 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5164 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5165 #endif |
5166 #ifdef FEAT_SYN_HL | |
2849 | 5167 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5168 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5169 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5170 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5171 #endif |
2849 | 5172 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5173 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5174 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5175 #ifdef FEAT_CSCOPE |
2849 | 5176 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5177 #endif |
1868 | 5178 #ifdef FEAT_SIGNS |
2849 | 5179 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5180 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5181 #ifdef FEAT_PROFILE |
2849 | 5182 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5183 #endif |
7 | 5184 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5185 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5186 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5187 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5188 #endif | |
5189 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5190 {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
|
5191 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5192 }; |
5193 int i; | |
5194 | |
5195 /* | |
5196 * Find a context in the table and call the ExpandGeneric() with the | |
5197 * right function to do the expansion. | |
5198 */ | |
5199 ret = FAIL; | |
1880 | 5200 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5201 if (xp->xp_context == tab[i].context) |
5202 { | |
5203 if (tab[i].ic) | |
5204 regmatch.rm_ic = TRUE; | |
2849 | 5205 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5206 tab[i].func, tab[i].escaped); |
7 | 5207 break; |
5208 } | |
5209 } | |
5210 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5211 vim_regfree(regmatch.regprog); |
7 | 5212 |
5213 return ret; | |
5214 #endif /* FEAT_CMDL_COMPL */ | |
5215 } | |
5216 | |
5217 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5218 /* | |
5219 * Expand a list of names. | |
5220 * | |
5221 * Generic function for command line completion. It calls a function to | |
5222 * obtain strings, one by one. The strings are matched against a regexp | |
5223 * program. Matching strings are copied into an array, which is returned. | |
5224 * | |
5225 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5226 */ | |
5227 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5228 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5229 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5230 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5231 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5232 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5233 char_u *((*func)(expand_T *, int)), |
7 | 5234 /* 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
|
5235 int escaped) |
7 | 5236 { |
5237 int i; | |
5238 int count = 0; | |
480 | 5239 int round; |
7 | 5240 char_u *str; |
5241 | |
5242 /* do this loop twice: | |
480 | 5243 * round == 0: count the number of matching names |
5244 * round == 1: copy the matching names into allocated memory | |
7 | 5245 */ |
480 | 5246 for (round = 0; round <= 1; ++round) |
7 | 5247 { |
5248 for (i = 0; ; ++i) | |
5249 { | |
5250 str = (*func)(xp, i); | |
5251 if (str == NULL) /* end of list */ | |
5252 break; | |
5253 if (*str == NUL) /* skip empty strings */ | |
5254 continue; | |
5255 | |
5256 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5257 { | |
480 | 5258 if (round) |
7 | 5259 { |
2849 | 5260 if (escaped) |
5261 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5262 else | |
5263 str = vim_strsave(str); | |
7 | 5264 (*file)[count] = str; |
5265 #ifdef FEAT_MENU | |
5266 if (func == get_menu_names && str != NULL) | |
5267 { | |
5268 /* test for separator added by get_menu_names() */ | |
5269 str += STRLEN(str) - 1; | |
5270 if (*str == '\001') | |
5271 *str = '.'; | |
5272 } | |
5273 #endif | |
5274 } | |
5275 ++count; | |
5276 } | |
5277 } | |
480 | 5278 if (round == 0) |
7 | 5279 { |
5280 if (count == 0) | |
5281 return OK; | |
5282 *num_file = count; | |
5283 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5284 if (*file == NULL) | |
5285 { | |
5286 *file = (char_u **)""; | |
5287 return FAIL; | |
5288 } | |
5289 count = 0; | |
5290 } | |
5291 } | |
480 | 5292 |
828 | 5293 /* Sort the results. Keep menu's in the specified order. */ |
5294 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5295 { |
5296 if (xp->xp_context == EXPAND_EXPRESSION | |
5297 || xp->xp_context == EXPAND_FUNCTIONS | |
5298 || xp->xp_context == EXPAND_USER_FUNC) | |
5299 /* <SNR> functions should be sorted to the end. */ | |
5300 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5301 sort_func_compare); | |
5302 else | |
5303 sort_strings(*file, *num_file); | |
5304 } | |
480 | 5305 |
1322 | 5306 #ifdef FEAT_CMDL_COMPL |
5307 /* Reset the variables used for special highlight names expansion, so that | |
5308 * they don't show up when getting normal highlight names by ID. */ | |
5309 reset_expand_highlight(); | |
5310 #endif | |
5311 | |
7 | 5312 return OK; |
5313 } | |
5314 | |
716 | 5315 /* |
5316 * Complete a shell command. | |
5317 * Returns FAIL or OK; | |
5318 */ | |
5319 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5320 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5321 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
|
5322 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
|
5323 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
|
5324 int flagsarg) /* EW_ flags */ |
716 | 5325 { |
5326 char_u *pat; | |
5327 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5328 char_u *path = NULL; |
716 | 5329 int mustfree = FALSE; |
5330 garray_T ga; | |
5331 char_u *buf = alloc(MAXPATHL); | |
5332 size_t l; | |
5333 char_u *s, *e; | |
5334 int flags = flagsarg; | |
5335 int ret; | |
6695 | 5336 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5337 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5338 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5339 hash_T hash; |
716 | 5340 |
5341 if (buf == NULL) | |
5342 return FAIL; | |
5343 | |
5344 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5345 * space */ | |
5346 pat = vim_strsave(filepat); | |
5347 for (i = 0; pat[i]; ++i) | |
5348 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5349 STRMOVE(pat + i, pat + i + 1); |
716 | 5350 |
6695 | 5351 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5352 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5353 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
|
5354 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5355 path = (char_u *)"."; |
5356 else | |
2630 | 5357 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5358 /* 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
|
5359 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5360 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5361 if (path == NULL) |
5362 path = (char_u *)""; | |
5363 } | |
716 | 5364 |
5365 /* | |
5366 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5367 * collect them in "ga". When "." is not in $PATH also expand for the |
5368 * current directory, to find "subdir/cmd". | |
716 | 5369 */ |
5370 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
|
5371 hash_init(&found_ht); |
6695 | 5372 for (s = path; ; s = e) |
716 | 5373 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5374 #if defined(MSWIN) |
716 | 5375 e = vim_strchr(s, ';'); |
5376 #else | |
5377 e = vim_strchr(s, ':'); | |
5378 #endif | |
5379 if (e == NULL) | |
5380 e = s + STRLEN(s); | |
5381 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5382 if (*s == NUL) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5383 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5384 if (did_curdir) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5385 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5386 // Find directories in the current directory, path is empty. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5387 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5388 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5389 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5390 else if (STRNCMP(s, ".", (int)(e - s)) == 0) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5391 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5392 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5393 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5394 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5395 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5396 // Do not match directories inside a $PATH item. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5397 flags &= ~EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5398 |
716 | 5399 l = e - s; |
5400 if (l > MAXPATHL - 5) | |
5401 break; | |
5402 vim_strncpy(buf, s, l); | |
5403 add_pathsep(buf); | |
5404 l = STRLEN(buf); | |
5405 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5406 | |
5407 /* Expand matches in one directory of $PATH. */ | |
5408 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5409 if (ret == OK) | |
5410 { | |
5411 if (ga_grow(&ga, *num_file) == FAIL) | |
5412 FreeWild(*num_file, *file); | |
5413 else | |
5414 { | |
5415 for (i = 0; i < *num_file; ++i) | |
5416 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5417 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5418 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5419 if (STRLEN(name) > l) |
716 | 5420 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5421 // 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
|
5422 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5423 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
|
5424 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5425 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5426 // 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
|
5427 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5428 ((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
|
5429 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
|
5430 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5431 } |
716 | 5432 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5433 vim_free(name); |
716 | 5434 } |
5435 vim_free(*file); | |
5436 } | |
5437 } | |
5438 if (*e != NUL) | |
5439 ++e; | |
5440 } | |
5441 *file = ga.ga_data; | |
5442 *num_file = ga.ga_len; | |
5443 | |
5444 vim_free(buf); | |
5445 vim_free(pat); | |
5446 if (mustfree) | |
5447 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5448 hash_clear(&found_ht); |
716 | 5449 return OK; |
5450 } | |
5451 | |
5452 | |
7 | 5453 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5454 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5455 * 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
|
5456 * return the result (either a string or a List). |
7 | 5457 */ |
407 | 5458 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5459 call_user_expand_func( |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5460 void *(*user_expand_func)(char_u *, int, typval_T *), |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5461 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5462 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5463 char_u ***file) |
7 | 5464 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5465 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
|
5466 typval_T args[4]; |
7 | 5467 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
|
5468 char_u *pat = NULL; |
407 | 5469 void *ret; |
13 | 5470 struct cmdline_info save_ccline; |
7 | 5471 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5472 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5473 return NULL; |
7 | 5474 *num_file = 0; |
5475 *file = NULL; | |
5476 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5477 if (ccline.cmdbuff != NULL) |
1518 | 5478 { |
5479 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5480 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5481 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5482 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5483 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
|
5484 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5485 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
|
5486 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
|
5487 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
|
5488 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
|
5489 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
|
5490 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
|
5491 args[3].v_type = VAR_UNKNOWN; |
7 | 5492 |
13 | 5493 /* Save the cmdline, we don't know what the function may do. */ |
5494 save_ccline = ccline; | |
5495 ccline.cmdbuff = NULL; | |
5496 ccline.cmdprompt = NULL; | |
7 | 5497 current_SID = xp->xp_scriptID; |
13 | 5498 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5499 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5500 |
5501 ccline = save_ccline; | |
7 | 5502 current_SID = save_current_SID; |
1518 | 5503 if (ccline.cmdbuff != NULL) |
5504 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5505 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5506 vim_free(pat); |
407 | 5507 return ret; |
5508 } | |
5509 | |
5510 /* | |
5511 * Expand names with a function defined by the user. | |
5512 */ | |
5513 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5514 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5515 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5516 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5517 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5518 char_u ***file) |
407 | 5519 { |
5520 char_u *retstr; | |
5521 char_u *s; | |
5522 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
|
5523 int keep; |
407 | 5524 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
|
5525 int skip; |
407 | 5526 |
5527 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5528 if (retstr == NULL) | |
7 | 5529 return FAIL; |
5530 | |
5531 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5532 for (s = retstr; *s != NUL; s = e) |
7 | 5533 { |
5534 e = vim_strchr(s, '\n'); | |
5535 if (e == NULL) | |
5536 e = s + STRLEN(s); | |
5537 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
|
5538 *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
|
5539 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5540 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
|
5541 *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
|
5542 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5543 if (!skip) |
7 | 5544 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5545 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
|
5546 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5547 ((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
|
5548 ++ga.ga_len; |
7 | 5549 } |
5550 | |
5551 if (*e != NUL) | |
5552 ++e; | |
5553 } | |
407 | 5554 vim_free(retstr); |
5555 *file = ga.ga_data; | |
5556 *num_file = ga.ga_len; | |
5557 return OK; | |
5558 } | |
5559 | |
5560 /* | |
5561 * Expand names with a list returned by a function defined by the user. | |
5562 */ | |
5563 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5564 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5565 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5566 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5567 char_u ***file) |
407 | 5568 { |
5569 list_T *retlist; | |
5570 listitem_T *li; | |
5571 garray_T ga; | |
5572 | |
5573 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5574 if (retlist == NULL) | |
5575 return FAIL; | |
5576 | |
5577 ga_init2(&ga, (int)sizeof(char *), 3); | |
5578 /* Loop over the items in the list. */ | |
5579 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5580 { | |
1917 | 5581 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5582 continue; /* Skip non-string items and empty strings */ | |
407 | 5583 |
5584 if (ga_grow(&ga, 1) == FAIL) | |
5585 break; | |
5586 | |
5587 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5588 vim_strsave(li->li_tv.vval.v_string); |
407 | 5589 ++ga.ga_len; |
5590 } | |
5591 list_unref(retlist); | |
5592 | |
7 | 5593 *file = ga.ga_data; |
5594 *num_file = ga.ga_len; | |
5595 return OK; | |
5596 } | |
5597 #endif | |
5598 | |
5599 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5600 * 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
|
5601 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5602 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5603 * 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
|
5604 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5605 * 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
|
5606 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5607 * "dirnames" is an array with one or more directory names. |
7 | 5608 */ |
5609 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5610 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5611 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5612 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5613 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5614 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5615 char *dirnames[]) |
7 | 5616 { |
5617 char_u *s; | |
5618 char_u *e; | |
5873 | 5619 char_u *match; |
7 | 5620 garray_T ga; |
2929 | 5621 int i; |
5622 int pat_len; | |
7 | 5623 |
5624 *num_file = 0; | |
5625 *file = NULL; | |
2931 | 5626 pat_len = (int)STRLEN(pat); |
2929 | 5627 ga_init2(&ga, (int)sizeof(char *), 10); |
5628 | |
5629 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5630 { |
2929 | 5631 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5632 if (s == NULL) | |
5633 { | |
5634 ga_clear_strings(&ga); | |
5635 return FAIL; | |
5636 } | |
5637 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5638 globpath(p_rtp, s, &ga, 0); |
2929 | 5639 vim_free(s); |
5873 | 5640 } |
5641 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5642 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5643 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
|
5644 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5645 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
|
5646 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5647 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5648 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5649 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5650 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5651 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
|
5652 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5653 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5654 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5655 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5656 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5657 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5658 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
|
5659 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5660 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
|
5661 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5662 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5663 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5664 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5665 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5666 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
|
5667 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5668 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5669 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5670 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5671 |
5873 | 5672 for (i = 0; i < ga.ga_len; ++i) |
5673 { | |
5674 match = ((char_u **)ga.ga_data)[i]; | |
5675 s = match; | |
5676 e = s + STRLEN(s); | |
5677 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5678 { |
5873 | 5679 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5680 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5681 if (s < match || vim_ispathsep(*s)) |
5682 break; | |
5683 ++s; | |
5684 *e = NUL; | |
5685 mch_memmove(match, s, e - s + 1); | |
7 | 5686 } |
5687 } | |
5873 | 5688 |
2929 | 5689 if (ga.ga_len == 0) |
3628 | 5690 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5691 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5692 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5693 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5694 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5695 |
7 | 5696 *file = ga.ga_data; |
5697 *num_file = ga.ga_len; | |
5698 return OK; | |
5699 } | |
5700 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5701 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5702 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5703 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5704 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5705 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5706 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5707 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5708 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5709 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5710 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5711 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5712 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5713 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5714 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5715 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5716 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5717 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5718 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5719 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5720 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5721 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
|
5722 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5723 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5724 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5725 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5726 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5727 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5728 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5729 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
|
5730 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5731 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5732 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5733 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
|
5734 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5735 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
|
5736 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5737 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5738 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
|
5739 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5740 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5741 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5742 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5743 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5744 /* 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
|
5745 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5746 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5747 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5748 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5749 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5750 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5751 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5752 |
7 | 5753 #endif |
5754 | |
5755 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5756 /* | |
5757 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5758 * Adds the matches to "ga". Caller must init "ga". |
7 | 5759 */ |
5873 | 5760 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5761 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5762 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5763 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5764 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5765 int expand_options) |
7 | 5766 { |
5767 expand_T xpc; | |
5768 char_u *buf; | |
5769 int i; | |
5770 int num_p; | |
5771 char_u **p; | |
5772 | |
5773 buf = alloc(MAXPATHL); | |
5774 if (buf == NULL) | |
5873 | 5775 return; |
7 | 5776 |
632 | 5777 ExpandInit(&xpc); |
7 | 5778 xpc.xp_context = EXPAND_FILES; |
632 | 5779 |
7 | 5780 /* Loop over all entries in {path}. */ |
5781 while (*path != NUL) | |
5782 { | |
5783 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5784 copy_option_part(&path, buf, MAXPATHL, ","); | |
5785 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5786 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5787 # 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
|
5788 /* 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
|
5789 * 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
|
5790 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
|
5791 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5792 # else |
7 | 5793 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
|
5794 # endif |
7 | 5795 STRCAT(buf, file); |
1754 | 5796 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5797 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5798 { |
1754 | 5799 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5800 |
5801 if (ga_grow(ga, num_p) == OK) | |
7 | 5802 { |
5803 for (i = 0; i < num_p; ++i) | |
5804 { | |
5873 | 5805 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5806 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5807 ++ga->ga_len; |
7 | 5808 } |
5809 } | |
5873 | 5810 |
7 | 5811 FreeWild(num_p, p); |
5812 } | |
5813 } | |
5814 } | |
5815 | |
5816 vim_free(buf); | |
5817 } | |
5818 | |
5819 #endif | |
5820 | |
5821 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5822 | |
5823 /********************************* | |
5824 * Command line history stuff * | |
5825 *********************************/ | |
5826 | |
5827 /* | |
5828 * Translate a history character to the associated type number. | |
5829 */ | |
5830 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5831 hist_char2type(int c) |
7 | 5832 { |
5833 if (c == ':') | |
5834 return HIST_CMD; | |
5835 if (c == '=') | |
5836 return HIST_EXPR; | |
5837 if (c == '@') | |
5838 return HIST_INPUT; | |
5839 if (c == '>') | |
5840 return HIST_DEBUG; | |
5841 return HIST_SEARCH; /* must be '?' or '/' */ | |
5842 } | |
5843 | |
5844 /* | |
5845 * Table of history names. | |
5846 * These names are used in :history and various hist...() functions. | |
5847 * It is sufficient to give the significant prefix of a history name. | |
5848 */ | |
5849 | |
5850 static char *(history_names[]) = | |
5851 { | |
5852 "cmd", | |
5853 "search", | |
5854 "expr", | |
5855 "input", | |
5856 "debug", | |
5857 NULL | |
5858 }; | |
5859 | |
3503 | 5860 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5861 /* | |
5862 * Function given to ExpandGeneric() to obtain the possible first | |
5863 * arguments of the ":history command. | |
5864 */ | |
5865 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5866 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5867 { |
5868 static char_u compl[2] = { NUL, NUL }; | |
5869 char *short_names = ":=@>?/"; | |
3529 | 5870 int short_names_count = (int)STRLEN(short_names); |
3503 | 5871 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5872 | |
5873 if (idx < short_names_count) | |
5874 { | |
5875 compl[0] = (char_u)short_names[idx]; | |
5876 return compl; | |
5877 } | |
5878 if (idx < short_names_count + history_name_count) | |
5879 return (char_u *)history_names[idx - short_names_count]; | |
5880 if (idx == short_names_count + history_name_count) | |
5881 return (char_u *)"all"; | |
5882 return NULL; | |
5883 } | |
5884 #endif | |
5885 | |
7 | 5886 /* |
5887 * init_history() - Initialize the command line history. | |
5888 * Also used to re-allocate the history when the size changes. | |
5889 */ | |
356 | 5890 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5891 init_history(void) |
7 | 5892 { |
5893 int newlen; /* new length of history table */ | |
5894 histentry_T *temp; | |
5895 int i; | |
5896 int j; | |
5897 int type; | |
5898 | |
5899 /* | |
5900 * If size of history table changed, reallocate it | |
5901 */ | |
5902 newlen = (int)p_hi; | |
5903 if (newlen != hislen) /* history length changed */ | |
5904 { | |
5905 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5906 { | |
5907 if (newlen) | |
5908 { | |
5909 temp = (histentry_T *)lalloc( | |
5910 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5911 if (temp == NULL) /* out of memory! */ | |
5912 { | |
5913 if (type == 0) /* first one: just keep the old length */ | |
5914 { | |
5915 newlen = hislen; | |
5916 break; | |
5917 } | |
5918 /* Already changed one table, now we can only have zero | |
5919 * length for all tables. */ | |
5920 newlen = 0; | |
5921 type = -1; | |
5922 continue; | |
5923 } | |
5924 } | |
5925 else | |
5926 temp = NULL; | |
5927 if (newlen == 0 || temp != NULL) | |
5928 { | |
5929 if (hisidx[type] < 0) /* there are no entries yet */ | |
5930 { | |
5931 for (i = 0; i < newlen; ++i) | |
4258 | 5932 clear_hist_entry(&temp[i]); |
7 | 5933 } |
5934 else if (newlen > hislen) /* array becomes bigger */ | |
5935 { | |
5936 for (i = 0; i <= hisidx[type]; ++i) | |
5937 temp[i] = history[type][i]; | |
5938 j = i; | |
5939 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5940 clear_hist_entry(&temp[i]); |
7 | 5941 for ( ; j < hislen; ++i, ++j) |
5942 temp[i] = history[type][j]; | |
5943 } | |
5944 else /* array becomes smaller or 0 */ | |
5945 { | |
5946 j = hisidx[type]; | |
5947 for (i = newlen - 1; ; --i) | |
5948 { | |
5949 if (i >= 0) /* copy newest entries */ | |
5950 temp[i] = history[type][j]; | |
5951 else /* remove older entries */ | |
5952 vim_free(history[type][j].hisstr); | |
5953 if (--j < 0) | |
5954 j = hislen - 1; | |
5955 if (j == hisidx[type]) | |
5956 break; | |
5957 } | |
5958 hisidx[type] = newlen - 1; | |
5959 } | |
5960 vim_free(history[type]); | |
5961 history[type] = temp; | |
5962 } | |
5963 } | |
5964 hislen = newlen; | |
5965 } | |
5966 } | |
5967 | |
4258 | 5968 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5969 clear_hist_entry(histentry_T *hisptr) |
4258 | 5970 { |
5971 hisptr->hisnum = 0; | |
5972 hisptr->viminfo = FALSE; | |
5973 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
5974 hisptr->time_set = 0; |
4258 | 5975 } |
5976 | |
7 | 5977 /* |
5978 * Check if command line 'str' is already in history. | |
5979 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
5980 */ | |
5981 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5982 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5983 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5984 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5985 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
|
5986 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5987 int writing) /* ignore entries read from viminfo */ |
7 | 5988 { |
5989 int i; | |
5990 int last_i = -1; | |
2986 | 5991 char_u *p; |
7 | 5992 |
5993 if (hisidx[type] < 0) | |
5994 return FALSE; | |
5995 i = hisidx[type]; | |
5996 do | |
5997 { | |
5998 if (history[type][i].hisstr == NULL) | |
5999 return FALSE; | |
2986 | 6000 |
6001 /* For search history, check that the separator character matches as | |
6002 * well. */ | |
6003 p = history[type][i].hisstr; | |
6004 if (STRCMP(str, p) == 0 | |
4285 | 6005 && !(writing && history[type][i].viminfo) |
2986 | 6006 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6007 { |
6008 if (!move_to_front) | |
6009 return TRUE; | |
6010 last_i = i; | |
6011 break; | |
6012 } | |
6013 if (--i < 0) | |
6014 i = hislen - 1; | |
6015 } while (i != hisidx[type]); | |
6016 | |
6017 if (last_i >= 0) | |
6018 { | |
6019 str = history[type][i].hisstr; | |
6020 while (i != hisidx[type]) | |
6021 { | |
6022 if (++i >= hislen) | |
6023 i = 0; | |
6024 history[type][last_i] = history[type][i]; | |
6025 last_i = i; | |
6026 } | |
4258 | 6027 history[type][i].hisnum = ++hisnum[type]; |
6028 history[type][i].viminfo = FALSE; | |
7 | 6029 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6030 history[type][i].time_set = vim_time(); |
7 | 6031 return TRUE; |
6032 } | |
6033 return FALSE; | |
6034 } | |
6035 | |
6036 /* | |
6037 * Convert history name (from table above) to its HIST_ equivalent. | |
6038 * When "name" is empty, return "cmd" history. | |
6039 * Returns -1 for unknown history name. | |
6040 */ | |
6041 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6042 get_histtype(char_u *name) |
7 | 6043 { |
6044 int i; | |
6045 int len = (int)STRLEN(name); | |
6046 | |
6047 /* No argument: use current history. */ | |
6048 if (len == 0) | |
6049 return hist_char2type(ccline.cmdfirstc); | |
6050 | |
6051 for (i = 0; history_names[i] != NULL; ++i) | |
6052 if (STRNICMP(name, history_names[i], len) == 0) | |
6053 return i; | |
6054 | |
6055 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6056 return hist_char2type(name[0]); | |
6057 | |
6058 return -1; | |
6059 } | |
6060 | |
6061 static int last_maptick = -1; /* last seen maptick */ | |
6062 | |
6063 /* | |
6064 * Add the given string to the given history. If the string is already in the | |
6065 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6066 * values. | |
6067 */ | |
6068 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6069 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6070 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6071 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6072 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
|
6073 int sep) /* separator character used (search hist) */ |
7 | 6074 { |
6075 histentry_T *hisptr; | |
6076 int len; | |
6077 | |
6078 if (hislen == 0) /* no history */ | |
6079 return; | |
6080 | |
5467 | 6081 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6082 return; | |
6083 | |
7 | 6084 /* |
6085 * Searches inside the same mapping overwrite each other, so that only | |
6086 * the last line is kept. Be careful not to remove a line that was moved | |
6087 * down, only lines that were added. | |
6088 */ | |
6089 if (histype == HIST_SEARCH && in_map) | |
6090 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6091 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6092 { |
6093 /* Current line is from the same mapping, remove it */ | |
6094 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6095 vim_free(hisptr->hisstr); | |
4258 | 6096 clear_hist_entry(hisptr); |
7 | 6097 --hisnum[histype]; |
6098 if (--hisidx[HIST_SEARCH] < 0) | |
6099 hisidx[HIST_SEARCH] = hislen - 1; | |
6100 } | |
6101 last_maptick = -1; | |
6102 } | |
4285 | 6103 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6104 { |
6105 if (++hisidx[histype] == hislen) | |
6106 hisidx[histype] = 0; | |
6107 hisptr = &history[histype][hisidx[histype]]; | |
6108 vim_free(hisptr->hisstr); | |
6109 | |
6110 /* Store the separator after the NUL of the string. */ | |
835 | 6111 len = (int)STRLEN(new_entry); |
7 | 6112 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6113 if (hisptr->hisstr != NULL) | |
6114 hisptr->hisstr[len + 1] = sep; | |
6115 | |
6116 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6117 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6118 hisptr->time_set = vim_time(); |
7 | 6119 if (histype == HIST_SEARCH && in_map) |
6120 last_maptick = maptick; | |
6121 } | |
6122 } | |
6123 | |
6124 #if defined(FEAT_EVAL) || defined(PROTO) | |
6125 | |
6126 /* | |
6127 * Get identifier of newest history entry. | |
6128 * "histype" may be one of the HIST_ values. | |
6129 */ | |
6130 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6131 get_history_idx(int histype) |
7 | 6132 { |
6133 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6134 || hisidx[histype] < 0) | |
6135 return -1; | |
6136 | |
6137 return history[histype][hisidx[histype]].hisnum; | |
6138 } | |
6139 | |
531 | 6140 /* |
7 | 6141 * Calculate history index from a number: |
6142 * num > 0: seen as identifying number of a history entry | |
6143 * num < 0: relative position in history wrt newest entry | |
6144 * "histype" may be one of the HIST_ values. | |
6145 */ | |
6146 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6147 calc_hist_idx(int histype, int num) |
7 | 6148 { |
6149 int i; | |
6150 histentry_T *hist; | |
6151 int wrapped = FALSE; | |
6152 | |
6153 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6154 || (i = hisidx[histype]) < 0 || num == 0) | |
6155 return -1; | |
6156 | |
6157 hist = history[histype]; | |
6158 if (num > 0) | |
6159 { | |
6160 while (hist[i].hisnum > num) | |
6161 if (--i < 0) | |
6162 { | |
6163 if (wrapped) | |
6164 break; | |
6165 i += hislen; | |
6166 wrapped = TRUE; | |
6167 } | |
6168 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6169 return i; | |
6170 } | |
6171 else if (-num <= hislen) | |
6172 { | |
6173 i += num + 1; | |
6174 if (i < 0) | |
6175 i += hislen; | |
6176 if (hist[i].hisstr != NULL) | |
6177 return i; | |
6178 } | |
6179 return -1; | |
6180 } | |
6181 | |
6182 /* | |
6183 * Get a history entry by its index. | |
6184 * "histype" may be one of the HIST_ values. | |
6185 */ | |
6186 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6187 get_history_entry(int histype, int idx) |
7 | 6188 { |
6189 idx = calc_hist_idx(histype, idx); | |
6190 if (idx >= 0) | |
6191 return history[histype][idx].hisstr; | |
6192 else | |
6193 return (char_u *)""; | |
6194 } | |
6195 | |
6196 /* | |
6197 * Clear all entries of a history. | |
6198 * "histype" may be one of the HIST_ values. | |
6199 */ | |
6200 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6201 clr_history(int histype) |
7 | 6202 { |
6203 int i; | |
6204 histentry_T *hisptr; | |
6205 | |
6206 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6207 { | |
6208 hisptr = history[histype]; | |
6209 for (i = hislen; i--;) | |
6210 { | |
6211 vim_free(hisptr->hisstr); | |
4258 | 6212 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6213 hisptr++; |
7 | 6214 } |
6215 hisidx[histype] = -1; /* mark history as cleared */ | |
6216 hisnum[histype] = 0; /* reset identifier counter */ | |
6217 return OK; | |
6218 } | |
6219 return FAIL; | |
6220 } | |
6221 | |
6222 /* | |
6223 * Remove all entries matching {str} from a history. | |
6224 * "histype" may be one of the HIST_ values. | |
6225 */ | |
6226 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6227 del_history_entry(int histype, char_u *str) |
7 | 6228 { |
6229 regmatch_T regmatch; | |
6230 histentry_T *hisptr; | |
6231 int idx; | |
6232 int i; | |
6233 int last; | |
6234 int found = FALSE; | |
6235 | |
6236 regmatch.regprog = NULL; | |
6237 regmatch.rm_ic = FALSE; /* always match case */ | |
6238 if (hislen != 0 | |
6239 && histype >= 0 | |
6240 && histype < HIST_COUNT | |
6241 && *str != NUL | |
6242 && (idx = hisidx[histype]) >= 0 | |
6243 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6244 != NULL) | |
6245 { | |
6246 i = last = idx; | |
6247 do | |
6248 { | |
6249 hisptr = &history[histype][i]; | |
6250 if (hisptr->hisstr == NULL) | |
6251 break; | |
6252 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6253 { | |
6254 found = TRUE; | |
6255 vim_free(hisptr->hisstr); | |
4258 | 6256 clear_hist_entry(hisptr); |
7 | 6257 } |
6258 else | |
6259 { | |
6260 if (i != last) | |
6261 { | |
6262 history[histype][last] = *hisptr; | |
4258 | 6263 clear_hist_entry(hisptr); |
7 | 6264 } |
6265 if (--last < 0) | |
6266 last += hislen; | |
6267 } | |
6268 if (--i < 0) | |
6269 i += hislen; | |
6270 } while (i != idx); | |
6271 if (history[histype][idx].hisstr == NULL) | |
6272 hisidx[histype] = -1; | |
6273 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6274 vim_regfree(regmatch.regprog); |
7 | 6275 return found; |
6276 } | |
6277 | |
6278 /* | |
6279 * Remove an indexed entry from a history. | |
6280 * "histype" may be one of the HIST_ values. | |
6281 */ | |
6282 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6283 del_history_idx(int histype, int idx) |
7 | 6284 { |
6285 int i, j; | |
6286 | |
6287 i = calc_hist_idx(histype, idx); | |
6288 if (i < 0) | |
6289 return FALSE; | |
6290 idx = hisidx[histype]; | |
6291 vim_free(history[histype][i].hisstr); | |
6292 | |
6293 /* When deleting the last added search string in a mapping, reset | |
6294 * last_maptick, so that the last added search string isn't deleted again. | |
6295 */ | |
6296 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6297 last_maptick = -1; | |
6298 | |
6299 while (i != idx) | |
6300 { | |
6301 j = (i + 1) % hislen; | |
6302 history[histype][i] = history[histype][j]; | |
6303 i = j; | |
6304 } | |
4258 | 6305 clear_hist_entry(&history[histype][i]); |
7 | 6306 if (--i < 0) |
6307 i += hislen; | |
6308 hisidx[histype] = i; | |
6309 return TRUE; | |
6310 } | |
6311 | |
6312 #endif /* FEAT_EVAL */ | |
6313 | |
6314 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6315 /* | |
6316 * Very specific function to remove the value in ":set key=val" from the | |
6317 * history. | |
6318 */ | |
6319 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6320 remove_key_from_history(void) |
7 | 6321 { |
6322 char_u *p; | |
6323 int i; | |
6324 | |
6325 i = hisidx[HIST_CMD]; | |
6326 if (i < 0) | |
6327 return; | |
6328 p = history[HIST_CMD][i].hisstr; | |
6329 if (p != NULL) | |
6330 for ( ; *p; ++p) | |
6331 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6332 { | |
6333 p = vim_strchr(p + 3, '='); | |
6334 if (p == NULL) | |
6335 break; | |
6336 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6337 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6338 if (p[i] == '\\' && p[i + 1]) |
6339 ++i; | |
1621 | 6340 STRMOVE(p, p + i); |
7 | 6341 --p; |
6342 } | |
6343 } | |
6344 #endif | |
6345 | |
6346 #endif /* FEAT_CMDHIST */ | |
6347 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6348 #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
|
6349 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6350 * 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
|
6351 * 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
|
6352 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6353 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6354 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6355 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6356 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6357 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6358 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6359 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6360 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
|
6361 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6362 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6363 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6364 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6365 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6366 #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
|
6367 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6368 * 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
|
6369 * 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
|
6370 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6371 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6372 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6373 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6374 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6375 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
|
6376 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6377 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6378 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6379 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
|
6380 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6381 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6382 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6383 * 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
|
6384 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6385 * 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
|
6386 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6387 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6388 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6389 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6390 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6391 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
|
6392 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6393 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6394 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6395 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6397 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6398 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6399 * 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
|
6400 * 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
|
6401 * 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
|
6402 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6403 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6404 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6405 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6406 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6407 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
|
6408 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6409 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6410 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6411 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6412 /* 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
|
6413 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6414 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6415 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6416 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 #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
|
6423 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6424 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 * 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
|
6427 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6429 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6432 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
|
6433 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6434 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6436 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6437 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6438 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6439 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6440 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6441 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 |
7 | 6446 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6447 /* | |
6448 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6449 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6450 * Returns OK if parsed successfully, otherwise FAIL. | |
6451 */ | |
6452 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6453 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6454 { |
6455 int len; | |
6456 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6457 varnumber_T num; |
7 | 6458 |
6459 *str = skipwhite(*str); | |
6460 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6461 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6462 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6463 *str += len; |
6464 *num1 = (int)num; | |
6465 first = TRUE; | |
6466 } | |
6467 *str = skipwhite(*str); | |
6468 if (**str == ',') /* parse "to" part of range */ | |
6469 { | |
6470 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6471 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6472 if (len > 0) |
6473 { | |
6474 *num2 = (int)num; | |
6475 *str = skipwhite(*str + len); | |
6476 } | |
6477 else if (!first) /* no number given at all */ | |
6478 return FAIL; | |
6479 } | |
6480 else if (first) /* only one number given */ | |
6481 *num2 = *num1; | |
6482 return OK; | |
6483 } | |
6484 #endif | |
6485 | |
6486 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6487 /* | |
6488 * :history command - print a history | |
6489 */ | |
6490 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6491 ex_history(exarg_T *eap) |
7 | 6492 { |
6493 histentry_T *hist; | |
6494 int histype1 = HIST_CMD; | |
6495 int histype2 = HIST_CMD; | |
6496 int hisidx1 = 1; | |
6497 int hisidx2 = -1; | |
6498 int idx; | |
6499 int i, j, k; | |
6500 char_u *end; | |
6501 char_u *arg = eap->arg; | |
6502 | |
6503 if (hislen == 0) | |
6504 { | |
6505 MSG(_("'history' option is zero")); | |
6506 return; | |
6507 } | |
6508 | |
6509 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6510 { | |
6511 end = arg; | |
6512 while (ASCII_ISALPHA(*end) | |
6513 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6514 end++; | |
6515 i = *end; | |
6516 *end = NUL; | |
6517 histype1 = get_histtype(arg); | |
6518 if (histype1 == -1) | |
6519 { | |
1853 | 6520 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6521 { |
6522 histype1 = 0; | |
6523 histype2 = HIST_COUNT-1; | |
6524 } | |
6525 else | |
6526 { | |
6527 *end = i; | |
6528 EMSG(_(e_trailing)); | |
6529 return; | |
6530 } | |
6531 } | |
6532 else | |
6533 histype2 = histype1; | |
6534 *end = i; | |
6535 } | |
6536 else | |
6537 end = arg; | |
6538 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6539 { | |
6540 EMSG(_(e_trailing)); | |
6541 return; | |
6542 } | |
6543 | |
6544 for (; !got_int && histype1 <= histype2; ++histype1) | |
6545 { | |
6546 STRCPY(IObuff, "\n # "); | |
6547 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6548 MSG_PUTS_TITLE(IObuff); | |
6549 idx = hisidx[histype1]; | |
6550 hist = history[histype1]; | |
6551 j = hisidx1; | |
6552 k = hisidx2; | |
6553 if (j < 0) | |
6554 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6555 if (k < 0) | |
6556 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6557 if (idx >= 0 && j <= k) | |
6558 for (i = idx + 1; !got_int; ++i) | |
6559 { | |
6560 if (i == hislen) | |
6561 i = 0; | |
6562 if (hist[i].hisstr != NULL | |
6563 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6564 { | |
6565 msg_putchar('\n'); | |
6566 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6567 hist[i].hisnum); | |
6568 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6569 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6570 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6571 else |
6572 STRCAT(IObuff, hist[i].hisstr); | |
6573 msg_outtrans(IObuff); | |
6574 out_flush(); | |
6575 } | |
6576 if (i == idx) | |
6577 break; | |
6578 } | |
6579 } | |
6580 } | |
6581 #endif | |
6582 | |
6583 #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
|
6584 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6585 * 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
|
6586 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6587 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
|
6588 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6589 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
|
6590 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6591 static int viminfo_add_at_front = FALSE; |
6592 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6593 static int hist_type2char(int type, int use_question); |
7 | 6594 |
6595 /* | |
6596 * Translate a history type number to the associated character. | |
6597 */ | |
6598 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6599 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6600 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6601 int use_question) /* use '?' instead of '/' */ |
7 | 6602 { |
6603 if (type == HIST_CMD) | |
6604 return ':'; | |
6605 if (type == HIST_SEARCH) | |
6606 { | |
6607 if (use_question) | |
6608 return '?'; | |
6609 else | |
6610 return '/'; | |
6611 } | |
6612 if (type == HIST_EXPR) | |
6613 return '='; | |
6614 return '@'; | |
6615 } | |
6616 | |
6617 /* | |
6618 * Prepare for reading the history from the viminfo file. | |
6619 * This allocates history arrays to store the read history lines. | |
6620 */ | |
6621 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6622 prepare_viminfo_history(int asklen, int writing) |
7 | 6623 { |
6624 int i; | |
6625 int num; | |
6626 int type; | |
6627 int len; | |
6628 | |
6629 init_history(); | |
4285 | 6630 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6631 if (asklen > hislen) |
6632 asklen = hislen; | |
6633 | |
6634 for (type = 0; type < HIST_COUNT; ++type) | |
6635 { | |
4258 | 6636 /* Count the number of empty spaces in the history list. Entries read |
6637 * from viminfo previously are also considered empty. If there are | |
6638 * more spaces available than we request, then fill them up. */ | |
7 | 6639 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6640 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6641 num++; |
6642 len = asklen; | |
6643 if (num > len) | |
6644 len = num; | |
6645 if (len <= 0) | |
6646 viminfo_history[type] = NULL; | |
6647 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6648 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6649 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6650 if (viminfo_history[type] == NULL) |
6651 len = 0; | |
6652 viminfo_hislen[type] = len; | |
6653 viminfo_hisidx[type] = 0; | |
6654 } | |
6655 } | |
6656 | |
6657 /* | |
6658 * Accept a line from the viminfo, store it in the history array when it's | |
6659 * new. | |
6660 */ | |
6661 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6662 read_viminfo_history(vir_T *virp, int writing) |
7 | 6663 { |
6664 int type; | |
6665 long_u len; | |
6666 char_u *val; | |
6667 char_u *p; | |
6668 | |
6669 type = hist_char2type(virp->vir_line[0]); | |
6670 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6671 { | |
6672 val = viminfo_readstring(virp, 1, TRUE); | |
6673 if (val != NULL && *val != NUL) | |
6674 { | |
3316 | 6675 int sep = (*val == ' ' ? NUL : *val); |
6676 | |
7 | 6677 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6678 viminfo_add_at_front, sep, writing)) |
7 | 6679 { |
6680 /* Need to re-allocate to append the separator byte. */ | |
6681 len = STRLEN(val); | |
6682 p = lalloc(len + 2, TRUE); | |
6683 if (p != NULL) | |
6684 { | |
6685 if (type == HIST_SEARCH) | |
6686 { | |
6687 /* Search entry: Move the separator from the first | |
6688 * column to after the NUL. */ | |
6689 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6690 p[len] = sep; |
7 | 6691 } |
6692 else | |
6693 { | |
6694 /* Not a search entry: No separator in the viminfo | |
6695 * file, add a NUL separator. */ | |
6696 mch_memmove(p, val, (size_t)len + 1); | |
6697 p[len + 1] = NUL; | |
6698 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6699 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
|
6700 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
|
6701 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
|
6702 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
|
6703 viminfo_hisidx[type]++; |
7 | 6704 } |
6705 } | |
6706 } | |
6707 vim_free(val); | |
6708 } | |
6709 return viminfo_readline(virp); | |
6710 } | |
6711 | |
4285 | 6712 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6713 * 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
|
6714 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6715 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6716 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6717 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6718 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6719 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6720 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6721 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6722 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6723 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6724 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6725 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
|
6726 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6727 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6728 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6729 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6730 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6731 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6732 || (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
|
6733 || 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
|
6734 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6735 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6736 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6737 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6738 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6739 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
|
6740 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6741 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6742 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6743 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6744 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
|
6745 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6746 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6747 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6748 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6749 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
|
6750 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6751 /* 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
|
6752 * 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
|
6753 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
|
6754 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6755 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6756 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6757 && (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
|
6758 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6759 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6763 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6764 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6765 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6766 /* 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
|
6767 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6768 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6769 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6770 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6771 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6773 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6774 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
|
6775 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6776 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6777 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
|
6778 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6779 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6780 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
|
6781 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6782 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
|
6783 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6785 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6788 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6789 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6790 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6792 * 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
|
6793 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6794 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6795 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6796 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6797 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6798 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6799 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6800 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6801 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6802 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6803 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6804 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6805 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6806 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6807 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6808 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6809 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6810 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6811 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6812 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6813 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6814 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6815 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6816 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6817 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6818 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6819 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6820 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6821 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6822 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
|
6823 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6824 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6825 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
|
6826 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6827 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
|
6828 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6829 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6830 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6831 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6832 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6833 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
|
6834 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6835 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6836 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6837 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6838 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6839 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6840 #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
|
6841 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6842 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6844 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 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
|
6846 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6847 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6848 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6849 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 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
|
6851 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
|
6852 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6853 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6854 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6856 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 * 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
|
6858 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6866 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6868 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6869 /* 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
|
6870 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 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
|
6872 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
|
6873 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
|
6874 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6875 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6877 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6879 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
|
6880 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
|
6881 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6886 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 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
|
6888 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6902 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
|
6903 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 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
|
6906 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
|
6907 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6911 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 /* |
4285 | 6915 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6916 */ | |
7 | 6917 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 finish_viminfo_history(vir_T *virp) |
7 | 6919 { |
6920 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6922 |
6923 for (type = 0; type < HIST_COUNT; ++type) | |
6924 { | |
6925 if (history[type] == NULL) | |
4283 | 6926 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 merge_history(type); |
7 | 6930 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6933 VIM_CLEAR(viminfo_history[type]); |
4327 | 6934 viminfo_hisidx[type] = 0; |
7 | 6935 } |
6936 } | |
6937 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6938 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6939 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6940 * 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
|
6941 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6942 * 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
|
6943 */ |
7 | 6944 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6945 write_viminfo_history(FILE *fp, int merge) |
7 | 6946 { |
6947 int i; | |
6948 int type; | |
6949 int num_saved; | |
4283 | 6950 int round; |
7 | 6951 |
6952 init_history(); | |
6953 if (hislen == 0) | |
6954 return; | |
6955 for (type = 0; type < HIST_COUNT; ++type) | |
6956 { | |
6957 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6958 if (num_saved == 0) | |
6959 continue; | |
6960 if (num_saved < 0) /* Use default */ | |
6961 num_saved = hislen; | |
6962 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
6963 type == HIST_CMD ? _("Command Line") : | |
6964 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6965 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6966 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6967 _("Debug Line")); |
7 | 6968 if (num_saved > hislen) |
6969 num_saved = hislen; | |
4283 | 6970 |
6971 /* | |
6972 * Merge typed and viminfo history: | |
6973 * round 1: history of typed commands. | |
6974 * round 2: history from recently read viminfo. | |
6975 */ | |
6976 for (round = 1; round <= 2; ++round) | |
6977 { | |
4307 | 6978 if (round == 1) |
6979 /* start at newest entry, somewhere in the list */ | |
6980 i = hisidx[type]; | |
6981 else if (viminfo_hisidx[type] > 0) | |
6982 /* start at newest entry, first in the list */ | |
6983 i = 0; | |
6984 else | |
6985 /* empty list */ | |
6986 i = -1; | |
4283 | 6987 if (i >= 0) |
6988 while (num_saved > 0 | |
6989 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 6990 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6991 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6992 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6993 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6994 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6995 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6996 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6997 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6998 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6999 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7000 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7001 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7002 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7003 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7004 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7005 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7006 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7007 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7008 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7009 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7010 || !history[type][i].viminfo)) |
7 | 7011 { |
4283 | 7012 --num_saved; |
7013 fputc(hist_type2char(type, TRUE), fp); | |
7014 /* For the search history: put the separator in the | |
7015 * second column; use a space if there isn't one. */ | |
7016 if (type == HIST_SEARCH) | |
7017 { | |
7018 c = p[STRLEN(p) + 1]; | |
7019 putc(c == NUL ? ' ' : c, fp); | |
7020 } | |
7021 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7022 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7023 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7024 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7025 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7026 /* 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
|
7027 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7028 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7029 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7030 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7031 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7032 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
|
7033 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7034 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7035 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7036 } |
7 | 7037 } |
4283 | 7038 if (round == 1) |
7039 { | |
7040 /* Decrement index, loop around and stop when back at | |
7041 * the start. */ | |
7042 if (--i < 0) | |
7043 i = hislen - 1; | |
7044 if (i == hisidx[type]) | |
7045 break; | |
7046 } | |
7047 else | |
7048 { | |
7049 /* Increment index. Stop at the end in the while. */ | |
7050 ++i; | |
7051 } | |
7 | 7052 } |
4283 | 7053 } |
4285 | 7054 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7055 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7056 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
|
7057 VIM_CLEAR(viminfo_history[type]); |
4311 | 7058 viminfo_hisidx[type] = 0; |
7 | 7059 } |
7060 } | |
7061 #endif /* FEAT_VIMINFO */ | |
7062 | |
7063 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7064 /* | |
7065 * Write a character at the current cursor+offset position. | |
7066 * It is directly written into the command buffer block. | |
7067 */ | |
7068 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7069 cmd_pchar(int c, int offset) |
7 | 7070 { |
7071 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7072 { | |
7073 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7074 return; | |
7075 } | |
7076 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7077 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7078 } | |
7079 | |
7080 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7081 cmd_gchar(int offset) |
7 | 7082 { |
7083 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7084 { | |
7085 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7086 return NUL; | |
7087 } | |
7088 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7089 } | |
7090 #endif | |
7091 | |
7092 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7093 /* | |
7094 * Open a window on the current command line and history. Allow editing in | |
7095 * the window. Returns when the window is closed. | |
7096 * Returns: | |
7097 * CR if the command is to be executed | |
7098 * Ctrl_C if it is to be abandoned | |
7099 * K_IGNORE if editing continues | |
7100 */ | |
7101 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
|
7102 open_cmdwin(void) |
7 | 7103 { |
7104 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7105 bufref_T old_curbuf; |
7 | 7106 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7107 bufref_T bufref; |
7 | 7108 win_T *wp; |
7109 int i; | |
7110 linenr_T lnum; | |
7111 int histtype; | |
7112 garray_T winsizes; | |
7113 int save_restart_edit = restart_edit; | |
7114 int save_State = State; | |
7115 int save_exmode = exmode_active; | |
510 | 7116 #ifdef FEAT_RIGHTLEFT |
7117 int save_cmdmsg_rl = cmdmsg_rl; | |
7118 #endif | |
6145 | 7119 #ifdef FEAT_FOLDING |
7120 int save_KeyTyped; | |
7121 #endif | |
7 | 7122 |
7123 /* Can't do this recursively. Can't do it when typing a password. */ | |
7124 if (cmdwin_type != 0 | |
7125 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7126 || cmdline_star > 0 | |
7127 # endif | |
7128 ) | |
7129 { | |
7130 beep_flush(); | |
7131 return K_IGNORE; | |
7132 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7133 set_bufref(&old_curbuf, curbuf); |
7 | 7134 |
7135 /* Save current window sizes. */ | |
7136 win_size_save(&winsizes); | |
7137 | |
7138 /* Don't execute autocommands while creating the window. */ | |
1410 | 7139 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7140 |
683 | 7141 /* don't use a new tab page */ |
7142 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
|
7143 cmdmod.noswapfile = 1; |
683 | 7144 |
7 | 7145 /* Create a window for the command-line buffer. */ |
7146 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7147 { | |
7148 beep_flush(); | |
1410 | 7149 unblock_autocmds(); |
7 | 7150 return K_IGNORE; |
7151 } | |
1831 | 7152 cmdwin_type = get_cmdline_type(); |
7 | 7153 |
7154 /* Create the command-line buffer empty. */ | |
1743 | 7155 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7156 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7157 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7158 curbuf->b_p_ma = TRUE; | |
1865 | 7159 #ifdef FEAT_FOLDING |
7160 curwin->w_p_fen = FALSE; | |
7161 #endif | |
7 | 7162 # ifdef FEAT_RIGHTLEFT |
510 | 7163 curwin->w_p_rl = cmdmsg_rl; |
7164 cmdmsg_rl = FALSE; | |
7 | 7165 # endif |
2583 | 7166 RESET_BINDING(curwin); |
7 | 7167 |
7168 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7169 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7170 /* 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
|
7171 ++curbuf_lock; |
7 | 7172 |
510 | 7173 /* Showing the prompt may have set need_wait_return, reset it. */ |
7174 need_wait_return = FALSE; | |
7175 | |
1831 | 7176 histtype = hist_char2type(cmdwin_type); |
7 | 7177 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7178 { | |
7179 if (p_wc == TAB) | |
7180 { | |
7181 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7182 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7183 } | |
7184 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7185 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7186 --curbuf_lock; |
7 | 7187 |
10 | 7188 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7189 * sets 'textwidth' to 78). */ | |
7190 curbuf->b_p_tw = 0; | |
7191 | |
7 | 7192 /* Fill the buffer with the history. */ |
7193 init_history(); | |
7194 if (hislen > 0) | |
7195 { | |
7196 i = hisidx[histtype]; | |
7197 if (i >= 0) | |
7198 { | |
7199 lnum = 0; | |
7200 do | |
7201 { | |
7202 if (++i == hislen) | |
7203 i = 0; | |
7204 if (history[histtype][i].hisstr != NULL) | |
7205 ml_append(lnum++, history[histtype][i].hisstr, | |
7206 (colnr_T)0, FALSE); | |
7207 } | |
7208 while (i != hisidx[histtype]); | |
7209 } | |
7210 } | |
7211 | |
7212 /* Replace the empty last line with the current command-line and put the | |
7213 * cursor there. */ | |
7214 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7215 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7216 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7217 changed_line_abv_curs(); |
7218 invalidate_botline(); | |
743 | 7219 redraw_later(SOME_VALID); |
7 | 7220 |
7221 /* 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
|
7222 save_cmdline(&save_ccline); |
7 | 7223 |
7224 /* No Ex mode here! */ | |
7225 exmode_active = 0; | |
7226 | |
7227 State = NORMAL; | |
7228 # ifdef FEAT_MOUSE | |
7229 setmouse(); | |
7230 # endif | |
7231 | |
7232 /* 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
|
7233 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7234 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7235 stuffcharReadbuff(K_NOP); | |
7 | 7236 |
7237 i = RedrawingDisabled; | |
7238 RedrawingDisabled = 0; | |
7239 | |
7240 /* | |
7241 * Call the main loop until <CR> or CTRL-C is typed. | |
7242 */ | |
7243 cmdwin_result = 0; | |
168 | 7244 main_loop(TRUE, FALSE); |
7 | 7245 |
7246 RedrawingDisabled = i; | |
7247 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7248 # ifdef FEAT_FOLDING |
6145 | 7249 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7250 # endif |
6145 | 7251 |
7 | 7252 /* 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
|
7253 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7254 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7255 # ifdef FEAT_FOLDING |
6145 | 7256 /* Restore KeyTyped in case it is modified by autocommands */ |
7257 KeyTyped = save_KeyTyped; | |
7 | 7258 # endif |
7259 | |
1214 | 7260 /* 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
|
7261 restore_cmdline(&save_ccline); |
7 | 7262 cmdwin_type = 0; |
7263 | |
7264 exmode_active = save_exmode; | |
7265 | |
1612 | 7266 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7267 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7268 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7269 { |
7270 cmdwin_result = Ctrl_C; | |
7271 EMSG(_("E199: Active window or buffer deleted")); | |
7272 } | |
7273 else | |
7274 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7275 # if defined(FEAT_EVAL) |
7 | 7276 /* autocmds may abort script processing */ |
7277 if (aborting() && cmdwin_result != K_IGNORE) | |
7278 cmdwin_result = Ctrl_C; | |
7279 # endif | |
7280 /* Set the new command line from the cmdline buffer. */ | |
7281 vim_free(ccline.cmdbuff); | |
510 | 7282 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7283 { |
510 | 7284 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7285 | |
7286 if (histtype == HIST_CMD) | |
7287 { | |
7288 /* Execute the command directly. */ | |
7289 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7290 cmdwin_result = CAR; | |
7291 } | |
7292 else | |
7293 { | |
7294 /* First need to cancel what we were doing. */ | |
7295 ccline.cmdbuff = NULL; | |
7296 stuffcharReadbuff(':'); | |
7297 stuffReadbuff((char_u *)p); | |
7298 stuffcharReadbuff(CAR); | |
7299 } | |
7 | 7300 } |
7301 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7302 { | |
7303 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7304 cmdwin_result = CAR; | |
7305 } | |
2839 | 7306 else if (cmdwin_result == Ctrl_C) |
7307 { | |
7308 /* :q or :close, don't execute any command | |
7309 * and don't modify the cmd window. */ | |
7310 ccline.cmdbuff = NULL; | |
7311 } | |
7 | 7312 else |
7313 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7314 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
|
7315 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7316 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
|
7317 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
|
7318 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
|
7319 ccline.cmdpos = 0; |
7 | 7320 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
|
7321 } |
7 | 7322 else |
7323 { | |
7324 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7325 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7326 ccline.cmdpos = curwin->w_cursor.col; | |
7327 if (ccline.cmdpos > ccline.cmdlen) | |
7328 ccline.cmdpos = ccline.cmdlen; | |
7329 if (cmdwin_result == K_IGNORE) | |
7330 { | |
7331 set_cmdspos_cursor(); | |
7332 redrawcmd(); | |
7333 } | |
7334 } | |
7335 | |
7336 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7337 block_autocmds(); |
6876 | 7338 # ifdef FEAT_CONCEAL |
7339 /* Avoid command-line window first character being concealed. */ | |
7340 curwin->w_p_cole = 0; | |
7341 # endif | |
7 | 7342 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7343 set_bufref(&bufref, curbuf); |
7 | 7344 win_goto(old_curwin); |
7345 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7346 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7347 /* 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
|
7348 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7349 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7350 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7351 |
7352 /* Restore window sizes. */ | |
7353 win_size_restore(&winsizes); | |
7354 | |
1410 | 7355 unblock_autocmds(); |
7 | 7356 } |
7357 | |
7358 ga_clear(&winsizes); | |
7359 restart_edit = save_restart_edit; | |
510 | 7360 # ifdef FEAT_RIGHTLEFT |
7361 cmdmsg_rl = save_cmdmsg_rl; | |
7362 # endif | |
7 | 7363 |
7364 State = save_State; | |
7365 # ifdef FEAT_MOUSE | |
7366 setmouse(); | |
7367 # endif | |
7368 | |
7369 return cmdwin_result; | |
7370 } | |
7371 #endif /* FEAT_CMDWIN */ | |
7372 | |
7373 /* | |
7374 * Used for commands that either take a simple command string argument, or: | |
7375 * cmd << endmarker | |
7376 * {script} | |
7377 * endmarker | |
7378 * Returns a pointer to allocated memory with {script} or NULL. | |
7379 */ | |
7380 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7381 script_get(exarg_T *eap, char_u *cmd) |
7 | 7382 { |
7383 char_u *theline; | |
7384 char *end_pattern = NULL; | |
7385 char dot[] = "."; | |
7386 garray_T ga; | |
7387 | |
7388 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7389 return NULL; | |
7390 | |
7391 ga_init2(&ga, 1, 0x400); | |
7392 | |
7393 if (cmd[2] != NUL) | |
7394 end_pattern = (char *)skipwhite(cmd + 2); | |
7395 else | |
7396 end_pattern = dot; | |
7397 | |
7398 for (;;) | |
7399 { | |
7400 theline = eap->getline( | |
7401 #ifdef FEAT_EVAL | |
75 | 7402 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7403 #endif |
7404 NUL, eap->cookie, 0); | |
7405 | |
7406 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7407 { |
7408 vim_free(theline); | |
7 | 7409 break; |
1694 | 7410 } |
7 | 7411 |
7412 ga_concat(&ga, theline); | |
7413 ga_append(&ga, '\n'); | |
7414 vim_free(theline); | |
7415 } | |
21 | 7416 ga_append(&ga, NUL); |
7 | 7417 |
7418 return (char_u *)ga.ga_data; | |
7419 } |