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